3

我在带有谓词属性的 cq 对话框中使用 aem-commons 的 contextualPathBrowser(类似于 pathfiled 组件)。java 谓词类将评估节点并仅在路径选择器中返回子页面(cq:Page)供用户选择。谓词类如下:

@Component(
        service = Predicate.class,
        property = {
                "predicate.name=pagePathPredicate"
        }
    )
public class PagePathPredicate extends AbstractNodePredicate {


    @Override
    public boolean evaluate(final Node node) throws AccessDeniedException, ItemNotFoundException, RepositoryException {
        try {
            return isInPredicate(node);
        } catch (RepositoryException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return false;
    }

    private boolean isInPredicate(final Node node) throws RepositoryException {
        if (node.getProperty("jcr:primaryType").getString().equals("cq:Page")) {
            return true;
        }
        return false;
    }
}

该代码运行良好,仅列出 jcr:primaryType = cq:Page 的节点。但是,很难仅列出用户当前所在页面的子页面,因为我不确定如何在 Predicate 类中获取当前资源/节点/页面。

4

0 回答 0