【问题标题】:Create custom pathbrowser predicate in AEM 6.2在 AEM 6.2 中创建自定义路径浏览器谓词
【发布时间】:2017-06-11 15:11:36
【问题描述】:

我正在尝试为路径浏览器实现自定义 OSGI 服务谓词。如果有人知道这段代码有什么问题:) 下面有例外。也许它与@Component 或依赖项有关

<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>

谓词实现:

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 构建输出:

[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 

【问题讨论】:

  • 如果你扩展 AbstractNodePredicate 而不是 AbstractResourcePredicate 会发生什么?

标签: java maven osgi aem


【解决方案1】:

当您从使用 SCR 注释(用于生成 OSGi 包描述符)注释的 AEM API 扩展一个类时,可能会发生您看到的错误,同时在您使用的 Uber Jar 中进行了混淆。

您可以在 Adobe's public Maven repository 中找到您正在使用的 AEM 版本的未混淆 Uber Jar。

如果您代表客户或合作伙伴,您还应该能够从帮助站点https://daycare.day.com/home/products/uberjar.html下载一个

如果您的项目使用的存储库已经包含未混淆的 Jar,则应该像更改依赖项一样简单。

例如,在使用带有混淆类的 AEM 6.2 Uber Jar 的项目中

<dependency>
    <groupId>com.adobe.aem</groupId>
    <artifactId>uber-jar</artifactId>
    <version>6.2.0</version>
    <scope>provided</scope>
    <classifier>obfuscated-apis</classifier>
</dependency>

只需更改分类器即可获得未混淆的版本:

<dependency>
    <groupId>com.adobe.aem</groupId>
    <artifactId>uber-jar</artifactId>
    <version>6.2.0</version>
    <scope>provided</scope>
    <classifier>apis</classifier>
</dependency>

查看此Github issue 以更广泛地讨论一个非常相似的问题。

您可能还会觉得这个Adobe Help Forum thread 很有趣, 虽然它属于测试版。

【讨论】:

  • FWIW,未混淆的 uber jar 现在可供所有人使用。见daycare.day.com/home/products/uberjar.html
  • @i.net 很高兴知道。但是,我可以看到您发布的链接受密码保护。看起来像基本的 HTTP 身份验证,但没有说明应该使用什么凭据。这是否使用一个人的 Adob​​e ID?
  • 抱歉,应该澄清一下,现在不能编辑评论(没有足够的代表?)...基本上,如果您是客户,则不需要请求 UberJar,因为该链接允许您下载它(假设您可以访问它)。如果您没有访问权限,Adobe 的公共 repo 上的以下链接将为您提供未混淆的 jar 文件:repo.adobe.com/nexus/content/repositories/releases/com/adobe/… 您还将在同一文件夹中找到经过混淆的版本。此外,这些也可用于其他版本。
  • @i.net 这不是代表的事情。评论只能在有限的时间内编辑(大约几分钟,不记得确切的数字)。更新了我的答案以包含您发布的链接。谢谢。
  • 去掉混淆
【解决方案2】:

尝试实现org.apache.commons.collections.Predicate

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

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", "")
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-07-15
    • 2015-07-18
    • 2020-06-20
    • 2014-04-08
    • 1970-01-01
    • 2017-10-27
    • 1970-01-01
    相关资源
    最近更新 更多