简体   繁体   English

Apache Sling资源解析器

[英]Apache Sling Resource Resolver

What exactly is the ResourceResolver? 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. 引用javadocRequestResolver定义了可用于解析Resource对象的服务API。

You typically access it in a SlingServlet by calling request.getResourceResolver() or in a script ( JSP script for instance ) under the resourceResolver variable. 通常,您可以通过在SlingServlet调用request.getResourceResolver()或在resourceResolver变量下的脚本(例如JSP脚本)中对其进行访问。 For more details on variables on scripts see Scripting variables in the Sling wiki . 有关脚本变量的更多详细信息,请参见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 ,然后提取属性

ValueMap properties = resource.adaptTo(ValueMap.class);
String title = properties.get("jcr:title", String.class);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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