首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >在AEM 6.2中创建自定义路径浏览器谓词

在AEM 6.2中创建自定义路径浏览器谓词
EN

Stack Overflow用户
提问于 2017-01-26 15:21:45
回答 2查看 1.1K关注 0票数 0

我正在尝试为pathbrowser实现自定义的OSGI服务谓词。如果有人知道这段代码出了什么问题:)下面有个例外。可能是@Component或依赖项

代码语言:javascript
运行
复制
<path jcr:primaryType="nt:unstructured"
      sling:resourceType="granite/ui/components/foundation/form/pathbrowser"
      fieldDescription="List item link" 
      fieldLabel="List Item link"
      name="./path"
      predicate="predicate"
      rootPath="/content">
</path>

谓词实现:

代码语言:javascript
运行
复制
import org.apache.commons.collections.Predicate;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Properties;
import org.apache.felix.scr.annotations.Property;
import org.apache.felix.scr.annotations.Service;
import org.apache.sling.api.resource.Resource;

import com.day.cq.commons.predicate.AbstractResourcePredicate;
import com.day.cq.wcm.api.Page;

@Component(label = "Content-page Predicate", description = "This predicate is used to restricted to allow selection of pages that have template content-page")
@Service(value = Predicate.class)
@Properties({
     @Property(label = "Predicate Name", name = "predicate.name", value = "predicate", propertyPrivate = true) })
public class ContentPagePredicate extends AbstractResourcePredicate {

    private static final String CQ_TEMPLATE_CONTENT = "/conf/xxx-lab/settings/wcm/templates/content-page";

    @Override
    public boolean evaluate(Resource resource) {
        if (null != resource) {
            if (!resource.getResourceType().equals("cq:Page")) {
                return false;
            }
            Page page = resource.adaptTo(Page.class);

            return page.getTemplate().getName().equals(CQ_TEMPLATE_CONTENT);

        }
        return false;
    }
}

Maven构建输出:

代码语言:javascript
运行
复制
[ERROR] Failed to execute goal org.apache.felix:maven-scr-plugin:1.20.0:scr (generate-scr-scrdescriptor) on project SomethingDemo.core: Execution generate-scr-scrdescriptor of goal org.apache.felix:maven-scr-plugin:1.20.0:scr failed: An API incompatibility was encountered while executing org.apache.felix:maven-scr-plugin:1.20.0:scr: java.lang.VerifyError: Constructor must call super() or this() before return
[ERROR] Exception Details:
[ERROR] Location:
[ERROR] com/day/cq/commons/predicate/AbstractNodePredicate.<init>()V @1: return
[ERROR] Reason:
[ERROR] Error exists in the bytecode
[ERROR] Bytecode:
[ERROR] 0x0000000: 2ab1 
EN

Stack Overflow用户

发布于 2017-01-26 20:08:37

只要尝试实现org.apache.commons.collections.Predicate即可。

另外:resource.getResourceType().equals("cq:Page")永远不会是true,因为cq:Page是资源的jcr:pimaryTypepage.getTemplate()在发布时不起作用:

代码语言:javascript
运行
复制
public booean evaluate(Resource resource) {
    if (null == resource) return false;
    final ValueMap map = resource.getValueMap();
    return "cq:Page".equals(map.get("jcr:primaryType", "")
            && CQ_TEMPLATE_CONTENT.equals(map.get("cq:template", "")
}
票数 1
EN
查看全部 2 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/41868527

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档