How do I get the value of a property given an absolute path? | Community
Skip to main content
October 16, 2015
Solved

How do I get the value of a property given an absolute path?

  • October 16, 2015
  • 4 replies
  • 4910 views

Given an absolute path to some text content, how to get I get the actual value of that content? For example, I know the absolute path to my node property is /content/userblog/2015/06/blog_post/jcr:content/par/entry, in my .JSP file, how would I get the text value of that property?

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by brucelef

I hacked up a little example using the excellent AEM Fiddle (part of ACS AEM Tools [0]):

<%@include file="/libs/foundation/global.jsp"%><% %><%@page session="false" contentType="text/html; charset=utf-8" pageEncoding="UTF-8" import="org.apache.sling.api.resource.Resource, org.apache.sling.api.resource.ValueMap"%><%     // Get the text resource Resource textResource = resourceResolver.getResource("/content/userblog/2015/06/blog_post/jcr:content/par/entry");     // Get it's properties ValueMap textResourceProperties = textResource.getValueMap(); %> <%= xssAPI.filterHTML( textResourceProperties.get("text", "no text set") ) %>

[0] http://adobe-consulting-services.github.io/acs-aem-tools/features/aem-fiddle.html

*edit: added XSS protection 

4 replies

smacdonald2008
Level 10
October 16, 2015

As Bruce points out - you can use Sling - which assumes its a resource. That is a great code example. 

The one that i give works at the node level (JCR). 

When working with AEM - you can work at the JCR level (JCR API) or the Sling level (Sling API). 

Also - if you are interested in Sling - look at Sling Models: 

https://helpx.adobe.com/experience-manager/using/sling_models.html

smacdonald2008
Level 10
October 16, 2015

You use the JCR API to get node prop values. See this article to learn how to work with AEM and the JCR API: 

https://helpx.adobe.com/experience-manager/using/programmatically-accessing-cq-content-using.html

joerghoh
Adobe Employee
Adobe Employee
October 16, 2015

For completeness, on JCR you would use something like this:

Item entryItem = session.getItem ("...");
if (!entryItem.isNode()) {
  Property p = Property (entryItem);
}

brucelefAdobe EmployeeAccepted solution
Adobe Employee
October 16, 2015

I hacked up a little example using the excellent AEM Fiddle (part of ACS AEM Tools [0]):

<%@include file="/libs/foundation/global.jsp"%><% %><%@page session="false" contentType="text/html; charset=utf-8" pageEncoding="UTF-8" import="org.apache.sling.api.resource.Resource, org.apache.sling.api.resource.ValueMap"%><%     // Get the text resource Resource textResource = resourceResolver.getResource("/content/userblog/2015/06/blog_post/jcr:content/par/entry");     // Get it's properties ValueMap textResourceProperties = textResource.getValueMap(); %> <%= xssAPI.filterHTML( textResourceProperties.get("text", "no text set") ) %>

[0] http://adobe-consulting-services.github.io/acs-aem-tools/features/aem-fiddle.html

*edit: added XSS protection