简体   繁体   中英

Apache Sling Resource Resolver

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);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM