Class ResourceResolverWrapper

  • All Implemented Interfaces:
    java.io.Closeable, java.lang.AutoCloseable, Adaptable, ResourceResolver

    @ConsumerType
    public class ResourceResolverWrapper
    extends java.lang.Object
    implements ResourceResolver
    The ResourceResolverWrapper is a wrapper for any ResourceResolver, delegating all method calls to the wrapped resource resolver by default. Extensions of this class may overwrite any method to return different values as appropriate.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      <AdapterType>
      AdapterType
      adaptTo​(@NotNull java.lang.Class<AdapterType> type)
      Adapts the adaptable to another type.
      @NotNull ResourceResolver clone​(java.util.Map<java.lang.String,​java.lang.Object> authenticationInfo)
      Wraps and returns the ResourceResolver obtained by calling clone on the wrapped resource resolver.
      void close()
      Close this resource resolver.
      void commit()
      Persist all pending changes.
      Resource copy​(java.lang.String srcAbsPath, java.lang.String destAbsPath)
      Wraps the Resource obtained by calling copy on the wrapped resource resolver.
      @NotNull Resource create​(@NotNull Resource parent, @NotNull java.lang.String name, java.util.Map<java.lang.String,​java.lang.Object> properties)
      Wraps the Resource obtained by calling create on the wrapped resource resolver.
      void delete​(@NotNull Resource resource)
      Delete the resource Deleting a non existing resource leads to no operation nor exception.
      @NotNull java.util.Iterator<Resource> findResources​(@NotNull java.lang.String query, java.lang.String language)
      Wraps and returns the Iterator obtained by calling findResources on the wrapped resource resolver.
      java.lang.Object getAttribute​(@NotNull java.lang.String name)
      Returns the value of the given resource resolver attribute or null if the attribute is not set (or not visible as is the case of the ResourceResolverFactory.PASSWORD or other security sensitive attributes).
      @NotNull java.util.Iterator<java.lang.String> getAttributeNames()
      Returns an iterator of attribute names whose value can be retrieved calling the ResourceResolver.getAttribute(String) method.
      @NotNull java.lang.Iterable<Resource> getChildren​(@NotNull Resource parent)
      Wraps and returns the Iterable obtained by calling getChildren on the wrapped resource resolver.
      Resource getParent​(@NotNull Resource child)
      Wraps and returns the Resource obtained by calling getParent on the wrapped resource resolver.
      java.lang.String getParentResourceType​(java.lang.String resourceType)
      Returns the super type of the given resource type.
      java.lang.String getParentResourceType​(Resource resource)
      Returns the super type of the given resource.
      java.util.Map<java.lang.String,​java.lang.Object> getPropertyMap()
      Returns a map to store temporary objects.
      Resource getResource​(@NotNull java.lang.String path)
      Wraps and returns the Resource obtained by calling getResource on the wrapped resource resolver.
      Resource getResource​(Resource base, @NotNull java.lang.String path)
      Wraps and returns the Resource obtained by calling getResource on the wrapped resource resolver.
      @NotNull java.lang.String[] getSearchPath()
      Returns the search path used by the ResourceResolver.getResource(String) method to search for resources by relative path.
      java.lang.String getUserID()
      Get the user ID, if any, associated with this resource resolver.
      boolean hasChanges()
      Are there any pending changes?
      boolean hasChildren​(@NotNull Resource resource)
      Checks if the specified resource has any direct child resources.
      boolean isLive()
      Returns true if this resource resolver is still usable.
      boolean isResourceType​(Resource resource, java.lang.String resourceType)
      Returns true if the resource type or any of the resource's super type(s) equals the given resource type.
      @NotNull java.util.Iterator<Resource> listChildren​(@NotNull Resource parent)
      Wraps and returns the Iterator obtained by calling listChildren on the wrapped resource resolver.
      @NotNull java.lang.String map​(@NotNull java.lang.String resourcePath)
      Returns a (request) path mapped from the (resource) path applying the reverse mapping used by the ResourceResolver.resolve(String) such that when the path is given to the ResourceResolver.resolve(String) method the same resource is returned.
      java.lang.String map​(@NotNull HttpServletRequest request, @NotNull java.lang.String resourcePath)
      Returns an URL mapped from the (resource) path applying the reverse mapping used by the ResourceResolver.resolve(HttpServletRequest, String) such that when the path is given to the ResourceResolver.resolve(HttpServletRequest, String) method the same resource is returned.
      Resource move​(java.lang.String srcAbsPath, java.lang.String destAbsPath)
      Wraps the Resource obtained by calling move on the wrapped resource resolver.
      boolean orderBefore​(@NotNull Resource parent, @NotNull java.lang.String name, @Nullable java.lang.String followingSiblingName)
      Orders the child resources returned by ResourceResolver.getChildren(Resource) and ResourceResolver.listChildren(Resource) so that a given resource is listed before the given sibling resource.
      @NotNull java.util.Iterator<java.util.Map<java.lang.String,​java.lang.Object>> queryResources​(@NotNull java.lang.String query, java.lang.String language)
      Queries the storage using the given query formulated in the given language.
      void refresh()
      The resolver is updated to reflect the latest state.
      @NotNull Resource resolve​(@NotNull java.lang.String absPath)
      Wraps and returns the Resource obtained by calling resolve on the wrapped resource resolver.
      @NotNull Resource resolve​(@NotNull HttpServletRequest request)
      Wraps and returns the Resource obtained by calling resolve on the wrapped resource resolver.
      @NotNull Resource resolve​(@NotNull HttpServletRequest request, @NotNull java.lang.String absPath)
      Wraps and returns the Resource obtained by calling resolve on the wrapped resource resolver.
      void revert()
      Revert all pending changes.
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • ResourceResolverWrapper

        public ResourceResolverWrapper​(ResourceResolver resolver)
        Creates a new wrapper instance, delegating all calls to the given resolver.
        Parameters:
        resolver - the wrapped resource resolver
    • Method Detail

      • resolve

        @NotNull
        public @NotNull Resource resolve​(@NotNull
                                         @NotNull HttpServletRequest request,
                                         @NotNull
                                         @NotNull java.lang.String absPath)
        Wraps and returns the Resource obtained by calling resolve on the wrapped resource resolver.
        Specified by:
        resolve in interface ResourceResolver
        Parameters:
        request - The http servlet request object providing more hints at how to resolve the absPath. This parameter may be null in which case the implementation should use reasonable defaults.
        absPath - The absolute path to be resolved to a resource. If this parameter is null, it is assumed to address the root of the resource tree. If the path is relative it is assumed relative to the root, that is a slash is prepended to the path before resolving it.
        Returns:
        a wrapped resource obtained through the wrapped resource resolver
        See Also:
        Mappings for Resource Resolution
      • resolve

        @NotNull
        public @NotNull Resource resolve​(@NotNull
                                         @NotNull java.lang.String absPath)
        Wraps and returns the Resource obtained by calling resolve on the wrapped resource resolver.
        Specified by:
        resolve in interface ResourceResolver
        Parameters:
        absPath - The absolute path to be resolved to a resource. If this parameter is null, it is assumed to address the root of the resource tree. If the path is relative it is assumed relative to the root, that is a slash is prepended to the path before resolving it.
        Returns:
        a wrapped resource obtained through the wrapped resource resolver
        See Also:
        Mappings for Resource Resolution
      • resolve

        @NotNull
        public @NotNull Resource resolve​(@NotNull
                                         @NotNull HttpServletRequest request)
        Wraps and returns the Resource obtained by calling resolve on the wrapped resource resolver.
        Specified by:
        resolve in interface ResourceResolver
        Parameters:
        request - The http servlet request object used to resolve the resource for. This must not be null.
        Returns:
        a wrapped resource obtained through the wrapped resource resolver
        See Also:
        Mappings for Resource Resolution
      • getResource

        public Resource getResource​(@NotNull
                                    @NotNull java.lang.String path)
        Wraps and returns the Resource obtained by calling getResource on the wrapped resource resolver.
        Specified by:
        getResource in interface ResourceResolver
        Parameters:
        path - The absolute path to the resource object to be loaded. The path may contain relative path specifiers like . (current location) and .. (parent location), which are resolved by this method. If the path is relative, that is the first character is not a slash, implementations are expected to apply a search path algorithm to resolve the relative path to a resource.
        Returns:
        a wrapped resource obtained through the wrapped resource resolver
      • getResource

        public Resource getResource​(Resource base,
                                    @NotNull
                                    @NotNull java.lang.String path)
        Wraps and returns the Resource obtained by calling getResource on the wrapped resource resolver.
        Specified by:
        getResource in interface ResourceResolver
        Parameters:
        base - The base Resource against which a relative path argument given by path is resolved. This parameter may be null if the path is known to be absolute.
        path - The path to the resource object to be loaded. If the path is relative, i.e. does not start with a slash (/), the resource relative to the given base resource is returned. The path may contain relative path specifiers like . (current location) and .. (parent location), which are resolved by this method.
        Returns:
        a wrapped resource obtained through the wrapped resource resolver
      • getSearchPath

        @NotNull
        public @NotNull java.lang.String[] getSearchPath()
        Description copied from interface: ResourceResolver
        Returns the search path used by the ResourceResolver.getResource(String) method to search for resources by relative path. If no search path is set an empty array is returned.

        The returned array of strings is a copy of the internal value, so modifications to this array have no influence on the operation of the ResourceResolver.

        The search path of a resource resolver never changes during the lifetime of the resource resolver. Therefore clients may call this method once and use the stored value together with this resource resolver.

        Each entry in the array is an absolute path terminated with a slash character. Thus to create an absolute path from a search path entry and a relative path, the search path entry and relative path may just be concatenated.

        Specified by:
        getSearchPath in interface ResourceResolver
        Returns:
        The array of search paths
      • listChildren

        @NotNull
        public @NotNull java.util.Iterator<Resource> listChildren​(@NotNull
                                                                  @NotNull Resource parent)
        Wraps and returns the Iterator obtained by calling listChildren on the wrapped resource resolver.
        Specified by:
        listChildren in interface ResourceResolver
        Parameters:
        parent - The Resource whose children are requested.
        Returns:
        a wrapped iterator obtained through the wrapped resource resolver
      • getParent

        public Resource getParent​(@NotNull
                                  @NotNull Resource child)
        Wraps and returns the Resource obtained by calling getParent on the wrapped resource resolver.
        Specified by:
        getParent in interface ResourceResolver
        Parameters:
        child - The Resource whose parent is requested.
        Returns:
        a wrapped resource obtained through the wrapped resource resolver
      • getChildren

        @NotNull
        public @NotNull java.lang.Iterable<Resource> getChildren​(@NotNull
                                                                 @NotNull Resource parent)
        Wraps and returns the Iterable obtained by calling getChildren on the wrapped resource resolver.
        Specified by:
        getChildren in interface ResourceResolver
        Parameters:
        parent - The Resource whose children are requested.
        Returns:
        a wrapped iterable obtained through the wrapped resource resolver
      • findResources

        @NotNull
        public @NotNull java.util.Iterator<Resource> findResources​(@NotNull
                                                                   @NotNull java.lang.String query,
                                                                   java.lang.String language)
        Wraps and returns the Iterator obtained by calling findResources on the wrapped resource resolver.
        Specified by:
        findResources in interface ResourceResolver
        Parameters:
        query - The query string to use to find the resources.
        language - The language in which the query is formulated. The language should always be specified. However for compatibility with older version, if no language is specified, "xpath" is used.
        Returns:
        a wrapped iterator obtained through the wrapped resource resolver
      • queryResources

        @NotNull
        public @NotNull java.util.Iterator<java.util.Map<java.lang.String,​java.lang.Object>> queryResources​(@NotNull
                                                                                                                  @NotNull java.lang.String query,
                                                                                                                  java.lang.String language)
        Description copied from interface: ResourceResolver
        Queries the storage using the given query formulated in the given language.

        The semantic meaning of the query and language depend on the actual implementation and storage used for the resources. For JCR repository being used as storage, the query and language parameters are used to create a JCR Query through the QueryManager. The result returned is then based on the RowIterator provided by the query result. The map returned for each row is indexed by the column name and the column value is the JCR Value object converted into the respective Java object, such as Boolean for a value of property type Boolean.

        Specified by:
        queryResources in interface ResourceResolver
        Parameters:
        query - The query string to use to find the resources.
        language - The language in which the query is formulated. The language should always be specified. However for compatibility with older version, if no language is specified, "xpath" is used.
        Returns:
        An Iterator of Map instances providing access to the query result.
      • hasChildren

        public boolean hasChildren​(@NotNull
                                   @NotNull Resource resource)
        Description copied from interface: ResourceResolver
        Checks if the specified resource has any direct child resources.
        Specified by:
        hasChildren in interface ResourceResolver
        Parameters:
        resource - the resource to check for direct children
        Returns:
        true if the resource has any child resources
      • clone

        @NotNull
        public @NotNull ResourceResolver clone​(java.util.Map<java.lang.String,​java.lang.Object> authenticationInfo)
                                        throws LoginException
        Wraps and returns the ResourceResolver obtained by calling clone on the wrapped resource resolver.
        Specified by:
        clone in interface ResourceResolver
        Parameters:
        authenticationInfo - The map or credential data to overlay the original credential data with for the creation of a new resource resolver. This may be null in which case the same credential data is used as was used to create this instance.
        Returns:
        a wrapped resource resolver
        Throws:
        LoginException - If an error occurs creating the new ResourceResolver with the provided credential data.
      • isLive

        public boolean isLive()
        Description copied from interface: ResourceResolver
        Returns true if this resource resolver is still usable. This method tests different things like if it has not been closed yet or if any of the used resource providers is not usable anymore.

        Unlike the other methods defined in this interface, this method will never throw an exception even after the resource resolver has been closed.

        Specified by:
        isLive in interface ResourceResolver
        Returns:
        true if the resource resolver is still usable. Once the resource resolver has been closed or a used resource provider has been unregistered, this method returns false.
      • close

        public void close()
        Description copied from interface: ResourceResolver
        Close this resource resolver. This method should be called by clients when the resource resolver is not used anymore. Once this method has been called, the resource resolver is considered unusable and will throw exceptions if still used - with the exception of this method, which can be called several times with no ill effects. A resolver may also be closed implicitly in case when the ResourceResolverFactory which was used to create this resolver is no longer active or any of the used resource providers is no longer active. All objects in the map maintained by ResourceResolver.getPropertyMap() implementing the Closeable interface, will be closed by calling Closeable#close() on each of them. Any exception thrown by this call will be ignored. The order in which the objects are closed is not defined.
        Specified by:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface java.io.Closeable
        Specified by:
        close in interface ResourceResolver
        See Also:
        Resource Resolver (section lifecycle), ResourceResolver.getPropertyMap()
      • getUserID

        public java.lang.String getUserID()
        Description copied from interface: ResourceResolver
        Get the user ID, if any, associated with this resource resolver. The meaning of this identifier is an implementation detail defined by the underlying repository. This method may return null.
        Specified by:
        getUserID in interface ResourceResolver
        Returns:
        the user ID
      • getAttributeNames

        @NotNull
        public @NotNull java.util.Iterator<java.lang.String> getAttributeNames()
        Description copied from interface: ResourceResolver
        Returns an iterator of attribute names whose value can be retrieved calling the ResourceResolver.getAttribute(String) method. This iterator will not include any attributes which are not accessible.
        Specified by:
        getAttributeNames in interface ResourceResolver
        Returns:
        An iterator of attribute names
      • getAttribute

        public java.lang.Object getAttribute​(@NotNull
                                             @NotNull java.lang.String name)
        Description copied from interface: ResourceResolver
        Returns the value of the given resource resolver attribute or null if the attribute is not set (or not visible as is the case of the ResourceResolverFactory.PASSWORD or other security sensitive attributes).
        Specified by:
        getAttribute in interface ResourceResolver
        Parameters:
        name - The name of the attribute to access
        Returns:
        The value of the attribute or null if the attribute is not set or not accessible.
      • create

        @NotNull
        public @NotNull Resource create​(@NotNull
                                        @NotNull Resource parent,
                                        @NotNull
                                        @NotNull java.lang.String name,
                                        java.util.Map<java.lang.String,​java.lang.Object> properties)
                                 throws PersistenceException
        Wraps the Resource obtained by calling create on the wrapped resource resolver.
        Specified by:
        create in interface ResourceResolver
        Parameters:
        parent - The parent resource
        name - The name of the child resource - this is a plain name, not a path!
        properties - Optional properties for the resource
        Returns:
        a wrapped resource obtained through the wrapped resource resolver
        Throws:
        PersistenceException - If the operation fails in the underlying resource provider, e.g. in case a resource of that name does already exist.
      • orderBefore

        public boolean orderBefore​(@NotNull
                                   @NotNull Resource parent,
                                   @NotNull
                                   @NotNull java.lang.String name,
                                   @Nullable
                                   @Nullable java.lang.String followingSiblingName)
                            throws java.lang.UnsupportedOperationException,
                                   PersistenceException,
                                   java.lang.IllegalArgumentException
        Description copied from interface: ResourceResolver
        Orders the child resources returned by ResourceResolver.getChildren(Resource) and ResourceResolver.listChildren(Resource) so that a given resource is listed before the given sibling resource. The changes are transient and require a call to ResourceResolver.commit() for persisting.
        Specified by:
        orderBefore in interface ResourceResolver
        Parameters:
        parent - the parent resource containing the child resources to order.
        name - the name of the child resource in parent to order. Must be an existing child name.
        followingSiblingName - the name of the resource child in parent which should come after the reordered resource. If null is given the resource is ordered as last among all sibling resources.
        Returns:
        true in case the order of the child resources in parent has been changed, false if the given resource were already in the desired order.
        Throws:
        java.lang.UnsupportedOperationException - in case the underlying resource provider does not support ordering or the child resources of parent are provided by different providers.
        PersistenceException - If the operation fails in the underlying resource provider, e.g. in case the parent resource does not support orderable children.
        java.lang.IllegalArgumentException - if either name or followingSiblingName are not existing child resource names of parent.
        See Also:
        ResourceResolver.listChildren(Resource), ResourceResolver.getChildren(Resource)
      • hasChanges

        public boolean hasChanges()
        Description copied from interface: ResourceResolver
        Are there any pending changes?
        Specified by:
        hasChanges in interface ResourceResolver
        Returns:
        true if there are pending changes.
      • getParentResourceType

        public java.lang.String getParentResourceType​(java.lang.String resourceType)
        Description copied from interface: ResourceResolver
        Returns the super type of the given resource type. This method converts the resource type to a resource path and checks the corresponding resource (considering the search path). If the resource exists, the Resource.getResourceSuperType() method is called.
        Specified by:
        getParentResourceType in interface ResourceResolver
        Parameters:
        resourceType - The resource type whose super type is to be returned.
        Returns:
        the super type of the resourceType or null if the resource given by the resource type does not exist or if it returns null for its super type. It also returns null if resourceType is null.
      • isResourceType

        public boolean isResourceType​(Resource resource,
                                      java.lang.String resourceType)
        Description copied from interface: ResourceResolver
        Returns true if the resource type or any of the resource's super type(s) equals the given resource type. In case the type of the given resource or the given resource type starts with one of the resource resolver's search paths it is converted to a relative resource type by stripping off the resource resolver's search path before doing the comparison.
        Specified by:
        isResourceType in interface ResourceResolver
        Parameters:
        resource - The resource to check
        resourceType - The resource type to check this resource against.
        Returns:
        true if the resource type or any of the resource's super type(s) equals the given resource type. false is also returned if resource or resourceType are null.
      • refresh

        public void refresh()
        Description copied from interface: ResourceResolver
        The resolver is updated to reflect the latest state. Resources which have changes pending are not discarded.
        Specified by:
        refresh in interface ResourceResolver
      • copy

        public Resource copy​(java.lang.String srcAbsPath,
                             java.lang.String destAbsPath)
                      throws PersistenceException
        Wraps the Resource obtained by calling copy on the wrapped resource resolver.
        Specified by:
        copy in interface ResourceResolver
        Parameters:
        srcAbsPath - the path of the resource to be copied.
        destAbsPath - the location to which the resource at srcAbsPath is to be copied.
        Returns:
        a wrapped resource obtained through the wrapped resource resolver
        Throws:
        PersistenceException - If an error occurs.
      • move

        public Resource move​(java.lang.String srcAbsPath,
                             java.lang.String destAbsPath)
                      throws PersistenceException
        Wraps the Resource obtained by calling move on the wrapped resource resolver.
        Specified by:
        move in interface ResourceResolver
        Parameters:
        srcAbsPath - the path of the resource to be moved.
        destAbsPath - the location to which the resource at srcAbsPath is to be moved.
        Returns:
        a wrapped resource obtained through the wrapped resource resolver
        Throws:
        PersistenceException - If an error occurs.
      • getPropertyMap

        public java.util.Map<java.lang.String,​java.lang.Object> getPropertyMap()
        Description copied from interface: ResourceResolver
        Returns a map to store temporary objects. This map is suited to store objects which share the same lifecycle as the resource resolver. The resource resolver itself does not use this map. The resource resolver will clear the map during ResourceResolver.close(), so afterwards the map is empty. If a stored value implements the Closeable interface, the ResourceResolver will invoke the close() of the value before clearing the map.
        Specified by:
        getPropertyMap in interface ResourceResolver
        Returns:
        the property map
        See Also:
        ResourceResolver.close()
      • adaptTo

        public <AdapterType> AdapterType adaptTo​(@NotNull
                                                 @NotNull java.lang.Class<AdapterType> type)
        Description copied from interface: Adaptable
        Adapts the adaptable to another type.

        Please note that it is explicitly left as an implementation detail whether each call to this method with the same type yields the same object or a new object on each call.

        Implementations of this method should document their adapted types as well as their behaviour with respect to returning newly created or same instances on each call.

        Specified by:
        adaptTo in interface Adaptable
        Type Parameters:
        AdapterType - The generic type to which this object is adapted to
        Parameters:
        type - The Class object of the target type, such as javax.jcr.Node.class or java.io.File.class
        Returns:
        The adapter target or null if the object cannot adapt to the requested type