However, you can also retrieve content from the JCR using Sling. In fact, a resource is a central part of Sling and it assumes everything in the JCR is a resource. You can use Sling to retrieve a resource from within an OSGi component using the Sling Java API or using a JSP. To use the Sling API from within an OSGi component, you use an org.apache.sling.api.resource.ResourceResolverFactory instance.
The Sling API is used within an OSGi bundle
When using Sling to query the JCR, you have access to helper methods that are not available when using the JCR API. For example, the adaptTo method converts a resource into an appropriate object representing a certain aspect of this resource. For example, to translate a Resource object to the corresponding Node object, you can simply do:
Node node = resource.adaptTo(Node.class);
This development article guides you through how to build an AEM application that uses Sling to retrieve resources from the JCR. An OSGi bundle is created that locates a resource and retrieves a value. To read this development article, click:
http://helpx.adobe.com/experience-manager/using/using-sling-apis.html
Note: When you want to write content to the JCR, it is recommended that you use the JCR API. For information, see Persisting CQ data in the Java Content Repository.
No comments:
Post a Comment
If you have any doubts or questions, please let us know.