【问题标题】:How to get "damFolderPath" from a Node in AEM?如何从 AEM 中的节点获取“damFolderPath”?
【发布时间】:2017-01-11 19:53:32
【问题描述】:

我正在使用 AEM 6.2 并尝试从节点的“jcr:content”中获取“damFolderPath”值。

我试过这些:

//resourcePath = "/content/projects/newyear-1"
Resource resource = resourceResolver.getResource(resourcePath);
Node tNode = resource.adaptTo(Node.class);
Property prop = tNode.getProperty("jcr:content/damFolderPath");
log.info("\n...Output 1:"+tNode.hasProperty("damFolderPath"));
log.info("\n...Output 2:"+prop.toString());

输出 1:假

输出 2:PropertyDelegate{parent=/content/projects/newyear-1/kms/jcr:content: { jcr:primaryType = nt:unstructured, detailsHref = /projects/details.html, jcr:title = kms , active = true, cq:template = /apps/swa/projects/templates/default, damFolderPath = /content/dam/projects/newyear-1/kms, coverUrl = /content/dam/projects /newyear-1/kms/cover, sling:resourceType = cq/gui/components/projects/admin/card/projectcontent, 链接 = { ... }, 仪表板 = { ... }}, property=damFolderPath = /content/dam/projects/newyear-1/kms}]

我可以看到它在那里,但我如何从 output2 中获取它?

【问题讨论】:

    标签: aem jcr sling


    【解决方案1】:

    您可以读取该值而无需达到 JCR API 级别。

    从 Sling 的角度来看,jcr:content 是一个可解析的资源。

    String resourcePath = "/content/projects/newyear-1/jcr:content"
    Resource jcrContentResource = resourceResolver.getResource(resourcePath);
    ValueMap valueMap = jcrContentResource.getValueMap();
    String damFolderPath = valueMap.get("damFolderPath", String.class);
    

    如果出于某种原因,您坚持使用 JCR API,那么您在 Output 2 中看到的是默认的 String 表示 Property 实现(由 @987654326 返回@)。

    Property 接口允许您使用多个特定类型的 getter 之一来获取属性的值。

    prop.getString()
    

    将为您提供路径/content/dam/projects/newyear-1

    另请参阅:getValue、getDouble、getBoolean、getDate 等。

    【讨论】:

      猜你喜欢
      • 2016-01-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多