Class ResourceUtil

  • All Implemented Interfaces:
    CoreConstants, org.apache.jackrabbit.JcrConstants

    public class ResourceUtil
    extends org.apache.sling.api.resource.ResourceUtil
    implements CoreConstants
    A collection of loads of utilities dealing with Resources.
    • Nested Class Summary

      • Nested classes/interfaces inherited from class org.apache.sling.api.resource.ResourceUtil

        org.apache.sling.api.resource.ResourceUtil.BatchResourceRemover
    • Constructor Summary

      Constructors 
      Constructor Description
      ResourceUtil()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static boolean containsPath​(List<org.apache.sling.api.resource.Resource> collection, String path)  
      static boolean containsPath​(List<org.apache.sling.api.resource.Resource> collection, org.apache.sling.api.resource.Resource resource)  
      static javax.jcr.Binary getBinaryData​(org.apache.sling.api.resource.Resource resource)  
      static @Nullable org.apache.sling.api.resource.Resource getByUuid​(@NotNull org.apache.sling.api.resource.ResourceResolver resolver, @Nullable String uuid)
      Finds a mix:referenceable by its jcr:uuid.
      static List<org.apache.sling.api.resource.Resource> getChildrenByResourceType​(org.apache.sling.api.resource.Resource resource, String resourceType)
      retrieves all children of a sling:resourceType
      static List<org.apache.sling.api.resource.Resource> getChildrenByType​(org.apache.sling.api.resource.Resource resource, String type)
      retrieves all children of a type (node type or resource type)
      static List<org.apache.sling.api.resource.Resource> getChildrenByType​(org.apache.sling.api.resource.Resource resource, List<String> typeSet)
      retrieves all children of one of a type from a type set (node type or resource type)
      static org.apache.sling.api.resource.Resource getDataResource​(org.apache.sling.api.resource.Resource resource)  
      static int getIndexOfSameType​(org.apache.sling.api.resource.Resource resource)  
      static String getNameExtension​(org.apache.sling.api.resource.Resource resource)  
      static org.apache.sling.api.resource.Resource getNextOfSameType​(org.apache.sling.api.resource.Resource resource, boolean wrapAround)  
      static org.apache.sling.api.resource.Resource getOrCreateChild​(org.apache.sling.api.resource.Resource resource, String relPath, String primaryTypes)
      Retrieves the resources child resource, creates this child if not existing.
      static org.apache.sling.api.resource.Resource getOrCreateResource​(org.apache.sling.api.resource.ResourceResolver resolver, String path)  
      static org.apache.sling.api.resource.Resource getOrCreateResource​(org.apache.sling.api.resource.ResourceResolver resolver, String path, String primaryTypes)  
      static String getPrimaryType​(org.apache.sling.api.resource.Resource resource)
      retrieves the primary type of the resources node
      static @Nullable org.apache.sling.api.resource.Resource getReferredResource​(@Nullable org.apache.sling.api.resource.Resource propertyResource)
      Finds the referenced node from a property of type REFERENCE, WEAKREFERENCE or PATH or convertable to that.
      static org.apache.sling.api.resource.Resource getResourceType​(org.apache.sling.api.resource.Resource resource)  
      static org.apache.sling.api.resource.Resource getResourceType​(org.apache.sling.api.resource.ResourceResolver resolver, String resourceTypeName)  
      static <T> T getTypeProperty​(org.apache.sling.api.resource.ResourceResolver resolver, String resourceTypeName, String name, Class<T> type)  
      static <T> T getTypeProperty​(org.apache.sling.api.resource.Resource resource, String name, Class<T> type)  
      static <T> T getTypeProperty​(org.apache.sling.api.resource.Resource resource, String name, T defaultValue)  
      static boolean isFile​(org.apache.sling.api.resource.Resource resource)
      Returns 'true' is this resource represents a 'file'.
      static boolean isNodeType​(String wanted, String probe)  
      static boolean isNodeType​(org.apache.sling.api.resource.Resource resource, String primaryType)
      Returns true if this node is of the specified primary node type or mixin type, or a subtype thereof.
      static boolean isPrimaryType​(org.apache.sling.api.resource.Resource resource, String primaryType)
      True if the getPrimaryType(Resource) of the resource is exactly primaryType.
      static boolean isRenderableFile​(org.apache.sling.api.resource.Resource resource)
      Returns 'true' is this resource represents a 'file' witch can be displayed (a HTML file).
      static boolean isResourceType​(@Nullable org.apache.sling.api.resource.Resource resource, String resourceType)
      Checks whether any of the resource's primary type, super types, sling resource type and supertypes is {resourceType}.
      static boolean isResourceType​(org.apache.sling.api.resource.ResourceResolver resolver, String resourceTypeName, Pattern pattern)  
      static boolean isResourceType​(org.apache.sling.api.resource.Resource resource, Pattern pattern)  
      static boolean isWriteEnabled​(org.apache.sling.api.resource.Resource resource, String relPath)
      Checks the access control policies for enabled changes (node creation and property change).
      static @NotNull String[] splitPathAndName​(@NotNull String path)
      Returns an array of two elements for a nontrivial path (containing /): the parent path and the name.
      • Methods inherited from class org.apache.sling.api.resource.ResourceUtil

        adaptTo, createUniqueChildName, findResourceSuperType, getBatchResourceRemover, getName, getName, getOrCreateResource, getOrCreateResource, getParent, getParent, getParent, getResourceSuperType, getValueMap, isA, isNonExistingResource, isStarResource, isSyntheticResource, listChildren, normalize, resourceTypeToPath, unwrap
    • Constructor Detail

      • ResourceUtil

        public ResourceUtil()
    • Method Detail

      • getChildrenByType

        public static List<org.apache.sling.api.resource.Resource> getChildrenByType​(org.apache.sling.api.resource.Resource resource,
                                                                                     List<String> typeSet)
        retrieves all children of one of a type from a type set (node type or resource type)
      • getChildrenByType

        public static List<org.apache.sling.api.resource.Resource> getChildrenByType​(org.apache.sling.api.resource.Resource resource,
                                                                                     String type)
        retrieves all children of a type (node type or resource type)
      • getChildrenByResourceType

        public static List<org.apache.sling.api.resource.Resource> getChildrenByResourceType​(org.apache.sling.api.resource.Resource resource,
                                                                                             String resourceType)
        retrieves all children of a sling:resourceType
      • getIndexOfSameType

        public static int getIndexOfSameType​(org.apache.sling.api.resource.Resource resource)
      • getNextOfSameType

        public static org.apache.sling.api.resource.Resource getNextOfSameType​(org.apache.sling.api.resource.Resource resource,
                                                                               boolean wrapAround)
      • getNameExtension

        public static String getNameExtension​(org.apache.sling.api.resource.Resource resource)
      • getPrimaryType

        public static String getPrimaryType​(org.apache.sling.api.resource.Resource resource)
        retrieves the primary type of the resources node
      • isResourceType

        public static boolean isResourceType​(@Nullable
                                             @Nullable org.apache.sling.api.resource.Resource resource,
                                             String resourceType)
        Checks whether any of the resource's primary type, super types, sling resource type and supertypes is {resourceType}.
      • isPrimaryType

        public static boolean isPrimaryType​(org.apache.sling.api.resource.Resource resource,
                                            String primaryType)
        True if the getPrimaryType(Resource) of the resource is exactly primaryType.
      • isNodeType

        public static boolean isNodeType​(org.apache.sling.api.resource.Resource resource,
                                         String primaryType)
        Returns true if this node is of the specified primary node type or mixin type, or a subtype thereof. Returns false otherwise.
      • isNodeType

        public static boolean isNodeType​(String wanted,
                                         String probe)
      • getResourceType

        public static org.apache.sling.api.resource.Resource getResourceType​(org.apache.sling.api.resource.Resource resource)
      • getResourceType

        public static org.apache.sling.api.resource.Resource getResourceType​(org.apache.sling.api.resource.ResourceResolver resolver,
                                                                             String resourceTypeName)
      • isResourceType

        public static boolean isResourceType​(org.apache.sling.api.resource.Resource resource,
                                             Pattern pattern)
      • isResourceType

        public static boolean isResourceType​(org.apache.sling.api.resource.ResourceResolver resolver,
                                             String resourceTypeName,
                                             Pattern pattern)
      • getTypeProperty

        public static <T> T getTypeProperty​(org.apache.sling.api.resource.Resource resource,
                                            String name,
                                            T defaultValue)
      • getTypeProperty

        public static <T> T getTypeProperty​(org.apache.sling.api.resource.Resource resource,
                                            String name,
                                            Class<T> type)
      • getTypeProperty

        public static <T> T getTypeProperty​(org.apache.sling.api.resource.ResourceResolver resolver,
                                            String resourceTypeName,
                                            String name,
                                            Class<T> type)
      • getOrCreateResource

        public static org.apache.sling.api.resource.Resource getOrCreateResource​(org.apache.sling.api.resource.ResourceResolver resolver,
                                                                                 String path)
                                                                          throws javax.jcr.RepositoryException
        Throws:
        javax.jcr.RepositoryException
      • getOrCreateResource

        public static org.apache.sling.api.resource.Resource getOrCreateResource​(org.apache.sling.api.resource.ResourceResolver resolver,
                                                                                 String path,
                                                                                 String primaryTypes)
                                                                          throws javax.jcr.RepositoryException
        Throws:
        javax.jcr.RepositoryException
      • containsPath

        public static boolean containsPath​(List<org.apache.sling.api.resource.Resource> collection,
                                           org.apache.sling.api.resource.Resource resource)
      • containsPath

        public static boolean containsPath​(List<org.apache.sling.api.resource.Resource> collection,
                                           String path)
      • splitPathAndName

        @NotNull
        public static @NotNull String[] splitPathAndName​(@NotNull
                                                         @NotNull String path)
        Returns an array of two elements for a nontrivial path (containing /): the parent path and the name. The parent of a toplevel node like "/var" is returned as "/". If it doesn't contain a / , the result has null in the first place.
      • getOrCreateChild

        public static org.apache.sling.api.resource.Resource getOrCreateChild​(org.apache.sling.api.resource.Resource resource,
                                                                              String relPath,
                                                                              String primaryTypes)
                                                                       throws javax.jcr.RepositoryException
        Retrieves the resources child resource, creates this child if not existing.
        Parameters:
        resource - the resource to extend
        relPath - the path to the requested child resource
        primaryTypes - the 'path' of primary types for the new nodes (optional, can be 'null')
        Returns:
        the requested child
        Throws:
        javax.jcr.RepositoryException
      • isWriteEnabled

        public static boolean isWriteEnabled​(org.apache.sling.api.resource.Resource resource,
                                             String relPath)
                                      throws javax.jcr.RepositoryException
        Checks the access control policies for enabled changes (node creation and property change).
        Throws:
        javax.jcr.RepositoryException
      • isRenderableFile

        public static boolean isRenderableFile​(org.apache.sling.api.resource.Resource resource)
        Returns 'true' is this resource represents a 'file' witch can be displayed (a HTML file).
      • isFile

        public static boolean isFile​(org.apache.sling.api.resource.Resource resource)
        Returns 'true' is this resource represents a 'file'.
      • getDataResource

        public static org.apache.sling.api.resource.Resource getDataResource​(org.apache.sling.api.resource.Resource resource)
      • getBinaryData

        public static javax.jcr.Binary getBinaryData​(org.apache.sling.api.resource.Resource resource)
      • getByUuid

        @Nullable
        public static @Nullable org.apache.sling.api.resource.Resource getByUuid​(@NotNull
                                                                                 @NotNull org.apache.sling.api.resource.ResourceResolver resolver,
                                                                                 @Nullable
                                                                                 @Nullable String uuid)
                                                                          throws javax.jcr.RepositoryException
        Finds a mix:referenceable by its jcr:uuid. This works only for JCR resources.
        Throws:
        javax.jcr.RepositoryException
      • getReferredResource

        @Nullable
        public static @Nullable org.apache.sling.api.resource.Resource getReferredResource​(@Nullable
                                                                                           @Nullable org.apache.sling.api.resource.Resource propertyResource)
                                                                                    throws javax.jcr.RepositoryException
        Finds the referenced node from a property of type REFERENCE, WEAKREFERENCE or PATH or convertable to that.
        Throws:
        javax.jcr.RepositoryException