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?
Solved! Go to Solution.
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
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
For completeness, on JCR you would use something like this:
Item entryItem = session.getItem ("...");
if (!entryItem.isNode()) {
Property p = Property (entryItem);
}
Views
Replies
Total Likes
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
Views
Replies
Total Likes
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
Views
Replies
Total Likes
Views
Likes
Replies
Views
Likes
Replies
Views
Likes
Replies