如何获得;damFolderPath“;来自AEM中的节点?
我正在使用AEM 6.2并试图从节点的“jcr:content”中获取“damFolderPath”值 我试过这些:如何获得;damFolderPath“;来自AEM中的节点?,aem,jcr,sling,Aem,Jcr,Sling,我正在使用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("j
//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:Property[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获取它呢?您可以读取值,而不必降低到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中看到的是属性
实现的默认字符串
表示(由toString()
返回)
该接口允许您使用多个特定于类型的getter之一获取属性的值
prop.getString()
将为您提供路径/content/dam/projects/newyear-1
另请参见:getValue
、getDouble
、getBoolean
、getDate
等