I'm using AEM 6.2 and trying to get the "damFolderPath" value from a Node's "jcr:content".
i tried these:
//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());
Output 1: false
Output 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}]
I can see it is there, but how do i get it from output2?
You can read the value without going as low as the JCR API level.
From Sling's point of view, jcr:content
is a resolvable Resource.
String resourcePath = "/content/projects/newyear-1/jcr:content"
Resource jcrContentResource = resourceResolver.getResource(resourcePath);
ValueMap valueMap = jcrContentResource.getValueMap();
String damFolderPath = valueMap.get("damFolderPath", String.class);
If, for whatever reason, you insist on using the JCR API, the thing you see in Output 2 is a default String
representation of a Property
implementation (as returned by toString()
).
The Property
interface allows you to obtain the property's value by using one of multiple, type-specific getters.
prop.getString()
will get you the path /content/dam/projects/newyear-1
See also: getValue
, getDouble
, getBoolean
, getDate
, etc.