What exactly is the ResourceResolver? More important, how do you use it? I'm struggling to find a simple example. So, say I have a path and want to use the resource resolver to see if the path resolves to a resource. How would I do that? I know this is wrong but if someone can correct this it would help.
Iterator<String> nodeSample = getResource("title");
return nodeSample
The RequestResolver
, to quote the javadoc, defines the service API which may be used to resolve Resource
objects.
You typically access it in a SlingServlet
by calling request.getResourceResolver()
or in a script ( JSP script for instance ) under the resourceResolver
variable. For more details on variables on scripts see Scripting variables in the Sling wiki.
One you get a hold of it you can use it to access resources in the content tree:
Resource resource = requestResolver.getResource("/content/my/resource");
if ( resource != null ) // bingo!
To display a resource's properties I usually adapt it to a ValueMap
and then extract the properties
ValueMap properties = resource.adaptTo(ValueMap.class);
String title = properties.get("jcr:title", String.class);