The main documentation for viewing is http://sling.apache.org/documentation/the-sling-engine/resources.html , which explains the concept of the Resource and how you work with them.
The API is slightly different from the JCR Node APIs, but uses similar concepts. The only thing that is definitely easier in Resources is access to property values, because you get them in ValueMap, and missing properties do not throw exceptions, for example.
In the above documents, the basic patterns should be explained, in short:
- You get a resource from a Sling request or use the ResourceResolver service
- A resource can be adapted to ValueMap to access its properties.
- Resource can be adapted to Node if you need to switch to JCR API
- Resource.listChildren (...) is similar to Node.getNodes ()
- Resource.getResourceResolver () provides a ResourceResolver that provides access to other resources by searching or by path.
A resource exists to abstract the content store so that you can use other backends than the JCR in Sling, and unify the Sling view with the data and content that it uses internally.
For programming at the application level, in my opinion, the JCR API is very nice, I would not use Resource instead just for it. But there are some cases where the resource API makes things easier.
source share