Class ResourceResolverControl


  • public class ResourceResolverControl
    extends Object
    This class takes a number of AuthenticatedResourceProvider objects and exposes it as one such object. Provider appropriate for the given operation is chosen basing on its ResourceProviderInfo.getPath() (more specific first) and service ranking. Like a resource resolver itself, this class is not thread safe.
    • Method Detail

      • isAdmin

        public boolean isAdmin()
        Is this an admin resource resolver?
        Returns:
        true if it is an admin resource resolver
      • getAuthenticationInfo

        public Map<String,​Object> getAuthenticationInfo()
        The authentication info
        Returns:
        The map with the auth info
      • isClosed

        public boolean isClosed()
        Is this already closed?
        Returns:
        true if it is closed.
      • refresh

        public void refresh​(@NotNull
                            @NotNull ResourceResolverContext context)
        Refreshes all refreshable providers as well as the resolver used for resource types.
      • isLive

        public boolean isLive​(@NotNull
                              @NotNull ResourceResolverContext context)
        Returns true if all providers are live.
      • getParent

        public org.apache.sling.api.resource.Resource getParent​(@NotNull
                                                                @NotNull ResourceResolverContext context,
                                                                @NotNull
                                                                @NotNull String parentPath,
                                                                @NotNull
                                                                @NotNull org.apache.sling.api.resource.Resource child)
        Returns parent from the most appropriate resource provider accepting the given children. In some cases the SyntheticResource can be returned if no resource provider returns parent for this child. See getResource(ResourceResolverContext, String, Resource, Map, boolean) for more details
      • getResource

        public org.apache.sling.api.resource.Resource getResource​(ResourceResolverContext context,
                                                                  String path,
                                                                  org.apache.sling.api.resource.Resource parent,
                                                                  Map<String,​String> parameters,
                                                                  boolean isResolve)
        Returns resource from the most appropriate resource provider.

        If there's no such provider and the path is a part of some resource provider path, then the SyntheticResource will be returned. For instance, if we have resource provider under /libs/sling/servlet/default/GET.servlet and no resource provider returns a resource for /libs/sling/servlet/default, then the SyntheticResource will be returned to provide a consistent resource tree.

        The same behaviour occurs in getParent(ResourceResolverContext, String, Resource) and listChildren(ResourceResolverContext, Resource).

      • create

        public org.apache.sling.api.resource.Resource create​(ResourceResolverContext context,
                                                             String path,
                                                             Map<String,​Object> properties)
                                                      throws org.apache.sling.api.resource.PersistenceException
        Create a resource.
        Returns:
        The new resource
        Throws:
        UnsupportedOperationException - If creation is not allowed/possible
        org.apache.sling.api.resource.PersistenceException - If creation fails
      • delete

        public void delete​(ResourceResolverContext context,
                           org.apache.sling.api.resource.Resource resource)
                    throws org.apache.sling.api.resource.PersistenceException
        Delete the resource. Iterate over all modifiable ResourceProviders giving each an opportunity to delete the resource if they are able.
        Throws:
        NullPointerException - if resource is null
        UnsupportedOperationException - If deletion is not allowed/possible
        org.apache.sling.api.resource.PersistenceException - If deletion fails
      • revert

        public void revert​(ResourceResolverContext context)
        Revert changes on all modifiable ResourceProviders.
      • commit

        public void commit​(ResourceResolverContext context)
                    throws org.apache.sling.api.resource.PersistenceException
        Commit changes on all modifiable ResourceProviders.
        Throws:
        org.apache.sling.api.resource.PersistenceException
      • hasChanges

        public boolean hasChanges​(ResourceResolverContext context)
        Check if any modifiable ResourceProvider has uncommited changes.
      • getSupportedLanguages

        public String[] getSupportedLanguages​(ResourceResolverContext context)
        Return the union of query languages supported by the providers.
      • adaptTo

        public <AdapterType> AdapterType adaptTo​(ResourceResolverContext context,
                                                 Class<AdapterType> type)
        Returns the first non-null result of the adaptTo() method invoked on the providers.
      • copy

        public org.apache.sling.api.resource.Resource copy​(ResourceResolverContext context,
                                                           String srcAbsPath,
                                                           String destAbsPath)
                                                    throws org.apache.sling.api.resource.PersistenceException
        Tries to find a resource provider accepting both paths and invokes AuthenticatedResourceProvider.copy(String, String) method on it. Returns false if there's no such provider.
        Throws:
        org.apache.sling.api.resource.PersistenceException
      • move

        public org.apache.sling.api.resource.Resource move​(ResourceResolverContext context,
                                                           String srcAbsPath,
                                                           String destAbsPath)
                                                    throws org.apache.sling.api.resource.PersistenceException
        Tries to find a resource provider accepting both paths and invokes AuthenticatedResourceProvider.move(String, String) method on it. Returns false if there's no such provider.
        Throws:
        org.apache.sling.api.resource.PersistenceException
      • close

        public void close()
        Close all dynamic resource providers.
      • getParentResourceType

        public String getParentResourceType​(org.apache.sling.api.resource.ResourceResolverFactory factory,
                                            org.apache.sling.api.resource.ResourceResolver resolver,
                                            String resourceType)
        Get the parent resource type
        See Also:
        ResourceResolver.getParentResourceType(java.lang.String)
      • getProperty

        public static String getProperty​(org.apache.sling.api.resource.Resource res,
                                         String propName)
        Parameters:
        res - The resource to access the property from
        propName - The name of the property to access
        Returns:
        The property as a String or null if the property does not exist or cannot be converted into a String
      • getProperty

        public static <Type> Type getProperty​(org.apache.sling.api.resource.Resource res,
                                              String propName,
                                              Class<Type> type)
        Returns the value of the name property of the resource converted to the requested type.

        If the resource itself does not have the property, the property is looked up in the jcr:content child node. This access is done through the same ValueMap as is used to access the property directly. This generally only works for JCR based ValueMap instances which provide access to relative path property names. This may not work in non JCR ValueMap, however in non JCR envs there is usually no "jcr:content" child node anyway

        Parameters:
        res - The resource to access the property from
        propName - The name of the property to access
        type - The type into which to convert the property
        Returns:
        The property converted to the requested type or null if the property does not exist or cannot be converted into the requested type
      • registerAuthenticatedProvider

        public void registerAuthenticatedProvider​(@NotNull
                                                  @NotNull ResourceProviderHandler handler,
                                                  @Nullable
                                                  @Nullable Object providerState)
      • clearAuthenticatedProviders

        public void clearAuthenticatedProviders()