如何从AEM中的节点获取“damFolderPath”?

时间:2017-01-11 19:53:32

标签: aem jcr sling

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

Screenshot

我试过这些:

//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,links = {...},dashboard = {...}}, property = damFolderPath = / content / dam / projects / newyear-1 / kms }]

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

1 个答案:

答案 0 :(得分:3)

您可以在不低于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,那么您在输出2 中看到的内容是String实现的默认Property表示形式(如由toString())返回。

Property界面允许您使用多个特定类型的getter中的一个来获取属性的值。

prop.getString()

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

另请参阅:getValuegetDoublegetBooleangetDate等。