2017-01-11 26 views
1

我正在使用AEM 6.2並試圖從節點的「jcr:content」中獲取「damFolderPath」值。如何從AEM中的節點獲取「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 {父= /內容/項目/ NEWYEAR-1 /公里/ JCR: content:{jcr:primaryType = nt:unstructured,detailsHref = /projects/details.html,jcr:title = kms,a​​ctive = true,cq:template =/apps/swa/projects/templates/default,damFolderPath =/content/dam/projects/newyear-1/kms, c overUrl =/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中獲取它?

回答

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看到的東西是一個Property實現(通過toString()返回)的默認String表示。

Property接口允許您通過使用多個特定於類型的獲得者之一獲取該屬性的值。

prop.getString() 

將讓你的路徑/content/dam/projects/newyear-1

參見:getValuegetDoublegetBooleangetDate

相關問題