You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@sling.apache.org by Mike Müller <mi...@mysign.ch> on 2010/09/03 17:01:26 UTC

The easiest way to access a resource without a request

Hi

To resolve SLING-1708 [1] I would like to implement a
Velocity ResourceManager which does not only get a template
from the JCR but searches in the whole resource tree instead.
So I wondered which is the easiest way to get a resource
without a request.
I guess I should get a ResourceResolver an call getResource(String)
on it, but how do I get the correct ResourceResolver without a
request?
Can someone give me a pointer?


[1] https://issues.apache.org/jira/browse/SLING-1708

best regards
mike

Re: The easiest way to access a resource without a request

Posted by Justin Edelson <ju...@gmail.com>.
To get a ResourceResolver without credentials (which is really what you
need), you have to use
ResourceResolverFactory.getAdministrativeResourceResolver().

Ideally, you would have support for a "resourceUser" which could be used
to grant access only to certain resources. Look at how the scriptUser
configuration parameter is implemented in SlingServletResolver. However,
without any context (i.e. the request), I'm not sure how you can
implement the "resolve the script resource from the request workspace"
logic in SlingServletResolver.

The other option (which I know some people won't like) is to store the
ResourceResolver in a ThreadLocal in the script engine.

Justin


On 9/3/10 11:01 AM, Mike Müller wrote:
> Hi
> 
> To resolve SLING-1708 [1] I would like to implement a
> Velocity ResourceManager which does not only get a template
> from the JCR but searches in the whole resource tree instead.
> So I wondered which is the easiest way to get a resource
> without a request.
> I guess I should get a ResourceResolver an call getResource(String)
> on it, but how do I get the correct ResourceResolver without a
> request?
> Can someone give me a pointer?
> 
> 
> [1] https://issues.apache.org/jira/browse/SLING-1708
> 
> best regards
> mike