Interface ResourceResolverHelper
-
@ProviderType public interface ResourceResolverHelper
TheResourceResolverHelper
service provides access to aResourceResolver
previously provided for the current thread.The implementation provides two contexts:
- While handling a Servlet API request the default
ResourceResolver
provided is the one provided by the Sling Engine through theSlingHttpServletRequest
- In a callstack opened by a call to the
callWith(ResourceResolver, Callable)
method
- While handling a Servlet API request the default
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description <Type> Type
callWith(ResourceResolver resolver, Callable<Type> callable)
Calls the givencallable
under the providesResourceResolver
.ResourceResolver
getResourceResolver()
Returns the currentResourceResolver
for the current thread ornull
if this method is called on a thread which is not handling a request or which is not in a call stack started with a call to thecallWith(ResourceResolver, Callable)
method.<Type> Type
getResourceResolverAs(Class<Type> type)
Returns the currentResourceResolver
adapted to the selected type.
-
-
-
Method Detail
-
getResourceResolver
ResourceResolver getResourceResolver()
Returns the currentResourceResolver
for the current thread ornull
if this method is called on a thread which is not handling a request or which is not in a call stack started with a call to thecallWith(ResourceResolver, Callable)
method.ResourceResolver
instances must not be shared accross threads because they are not thread safe.
-
getResourceResolverAs
<Type> Type getResourceResolverAs(Class<Type> type)
Returns the currentResourceResolver
adapted to the selected type. If there is no currenResourceResolver
or if theResourceResolver
does not adapt to the desired typenull
is returned.This method is equivalent to calling
getResourceResolver().adaptTo(type)
.- Parameters:
type
- The type to which the currentResourceResolver
should be adapted.- Returns:
- The
ResourceResolver
adapted to the desiredtype
ornull
-
callWith
<Type> Type callWith(ResourceResolver resolver, Callable<Type> callable) throws Exception
Calls the givencallable
under the providesResourceResolver
. Before calling thecallable
theresolver
is set as the currentResourceResolver
such that thegetResourceResolver()
method returns the givenResourceResolver
.- Parameters:
resolver
- TheResourceResolver
to set as the currentResourceResolver
before calling thecallable
.callable
- The code to execute under theresolver
.- Returns:
- The result from calling the
callable
- Throws:
NullPointerException
- ifcallable
isnull
.Exception
- The exception thrown by thecallable
is returned.
-
-