繁体   English   中英

如何在Sling模型中访问AEM Core模型

[英]How to access AEM Core models in a Sling model

具体来说,我正在尝试使.SVG文件可由核心映像组件使用。

现在,我正在制作一个吊索模型,理想情况下,我想在位于此处的核心AEM Component接口中访问getSrc()和getFileReference()类的返回值。

我对AEM开发和Sling模型非常陌生。 我是否缺少一些让我做到这一点的重要功能?

这是我的代码,在这一点上可能根本没有帮助。

package com.site.core.models;

import com.adobe.cq.wcm.core.components.models.Image;
import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ResourceResolver;
import org.apache.sling.api.resource.ValueMap;
import org.apache.sling.models.annotations.*;
import org.apache.sling.models.annotations.injectorspecific.*;

import org.apache.sling.settings.SlingSettingsService;
import javax.jcr.Node;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import javax.inject.Inject;

@Model(adaptables = SlingHttpServletRequest.class)
public class ImageModel {

    private String src = Image.getSrc(); 

    return src;

}

正如我在评论中提到的那样,您所指的链接是一个接口,该接口的实现在此处

为了使用自己的实现,您有两个选择:

  1. 在图像组件html中,更改data-sly-use以引用您的impl: com.site.core.models.ImageModel

  2. 创建一个单独的模型来实现Image接口,并为其提供较高的排名,以取代现有的impl。

免责声明:我没有测试过#2,但是文档表明这是可能的。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM