Class CMSUtils


  • public class CMSUtils
    extends Object
    Shared utility functions
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static <T> @NotNull List<T> adaptResources​(Collection<org.apache.sling.api.resource.Resource> resources, Class<T> type)
      Adapts the collection of resources ensuring that if any cannot be adapted it is excluded from the returned list.
      static <T> @NotNull List<T> adaptResources​(org.apache.sling.api.resource.Resource[] resources, Class<T> type)
      Adapts the array of resources ensuring that if any cannot be adapted it is excluded from the returned list.
      static @Nullable org.apache.sling.api.resource.Resource findParentResourceofType​(org.apache.sling.api.resource.Resource resource, String type)
      Looks up the resource tree to find the parent resource with the specified jcr:primaryType.
      static @Nullable org.apache.sling.api.resource.Resource findPublishableParent​(org.apache.sling.api.resource.Resource resource)
      Look up the resource tree to find a parent of a publishable type.
      static boolean isPublished​(org.apache.sling.api.resource.Resource resource)
      Return true of the resource (or it's publishable parent) is published or false otherwise.
    • Method Detail

      • adaptResources

        @NotNull
        public static final <T> @NotNull List<T> adaptResources​(Collection<org.apache.sling.api.resource.Resource> resources,
                                                                Class<T> type)
        Adapts the collection of resources ensuring that if any cannot be adapted it is excluded from the returned list.
        Type Parameters:
        T - the type to which the resources are adapted
        Parameters:
        resources - the collection of resources to adapt
        type - the type to which to adapt the resources
        Returns:
        the list of adapted classes
      • adaptResources

        @NotNull
        public static final <T> @NotNull List<T> adaptResources​(org.apache.sling.api.resource.Resource[] resources,
                                                                Class<T> type)
        Adapts the array of resources ensuring that if any cannot be adapted it is excluded from the returned list.
        Type Parameters:
        T - the type to which the resources are adapted
        Parameters:
        resources - the array of resources to adapt
        type - the type to which to adapt the resources
        Returns:
        the list of adapted classes
      • findParentResourceofType

        @Nullable
        public static final @Nullable org.apache.sling.api.resource.Resource findParentResourceofType​(org.apache.sling.api.resource.Resource resource,
                                                                                                      String type)
        Looks up the resource tree to find the parent resource with the specified jcr:primaryType.
        Parameters:
        resource - the resource to search from
        type - the primary type to find
        Returns:
        the parent of the type or null
      • findPublishableParent

        @Nullable
        public static final @Nullable org.apache.sling.api.resource.Resource findPublishableParent​(org.apache.sling.api.resource.Resource resource)
        Look up the resource tree to find a parent of a publishable type.
        Parameters:
        resource - the resource to search from
        Returns:
        the parent publishable type
      • isPublished

        public static final boolean isPublished​(org.apache.sling.api.resource.Resource resource)
        Return true of the resource (or it's publishable parent) is published or false otherwise. If the resource is not contained within a publishable parent it is considered published.
        Parameters:
        resource - the resource to check
        Returns:
        whether or not the resource is published