Interface ResourceResolverHelper

  • @Deprecated
    public interface ResourceResolverHelper
    The ResourceResolverHelper service provides access to a ResourceResolver 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 the SlingHttpServletRequest
    • In a callstack opened by a call to the callWith(ResourceResolver, Callable) method
    • Method Detail

      • getResourceResolver

        ResourceResolver getResourceResolver()
        Returns the current ResourceResolver for the current thread or null 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 the callWith(ResourceResolver, Callable) method.

        ResourceResolver instances must not be shared accross threads because they are not thread safe.

      • getResourceResolverAs

        <Type> Type getResourceResolverAs​(java.lang.Class<Type> type)
        Returns the current ResourceResolver adapted to the selected type. If there is no curren ResourceResolver or if the ResourceResolver does not adapt to the desired type null is returned.

        This method is equivalent to calling getResourceResolver().adaptTo(type).

        type - The type to which the current ResourceResolver should be adapted.
        The ResourceResolver adapted to the desired type or null
      • callWith

        <Type> Type callWith​(ResourceResolver resolver,
                             java.util.concurrent.Callable<Type> callable)
                      throws java.lang.Exception
        Calls the given callable under the provides ResourceResolver. Before calling the callable the resolver is set as the current ResourceResolver such that the getResourceResolver() method returns the given ResourceResolver.
        resolver - The ResourceResolver to set as the current ResourceResolver before calling the callable.
        callable - The code to execute under the resolver.
        The result from calling the callable
        java.lang.NullPointerException - if callable is null.
        java.lang.Exception - The exception thrown by the callable is returned.