Class ResourceType


  • public final class ResourceType
    extends java.lang.Object
    Helper methods for resource type path handling.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static java.lang.String APPS_PREFIX
      Deprecated.
      Search paths are confurable and should not be hard-coded.
      static java.lang.String LIBS_PREFIX
      Deprecated.
      Search paths are confurable and should not be hard-coded.
    • Method Summary

      All Methods Static Methods Concrete Methods Deprecated Methods 
      Modifier and Type Method Description
      static boolean equals​(@NotNull java.lang.String resourceType, @NotNull java.lang.String anotherResourceType)
      Deprecated.
      static boolean equals​(@NotNull java.lang.String resourceType, @NotNull java.lang.String anotherResourceType, @NotNull org.apache.sling.api.resource.ResourceResolver resourceResolver)
      Returns true if the given resource type are equal.
      static boolean is​(@Nullable org.apache.sling.api.resource.Resource resource, @Nullable java.lang.String resourceType)
      Returns true if the resource type or any of the resource's super type(s) equals the given resource type.
      static @NotNull java.lang.String makeAbsolute​(@NotNull java.lang.String resourceType, @NotNull org.apache.sling.api.resource.ResourceResolver resourceResolver)
      Converts the resource type to an absolute path.
      static @NotNull java.lang.String makeRelative​(@NotNull java.lang.String resourceType)
      Deprecated.
      static @NotNull java.lang.String makeRelative​(@NotNull java.lang.String resourceType, @NotNull org.apache.sling.api.resource.ResourceResolver resourceResolver)
      Makes the given resource type relative by stripping off any search path prefix.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • APPS_PREFIX

        @Deprecated
        public static final java.lang.String APPS_PREFIX
        Deprecated.
        Search paths are confurable and should not be hard-coded.
        /apps prefix for resource types
        See Also:
        Constant Field Values
      • LIBS_PREFIX

        @Deprecated
        public static final java.lang.String LIBS_PREFIX
        Deprecated.
        Search paths are confurable and should not be hard-coded.
        /libs prefix for resource types
        See Also:
        Constant Field Values
    • Method Detail

      • makeAbsolute

        @NotNull
        public static @NotNull java.lang.String makeAbsolute​(@NotNull
                                                             @NotNull java.lang.String resourceType,
                                                             @NotNull
                                                             @NotNull org.apache.sling.api.resource.ResourceResolver resourceResolver)
        Converts the resource type to an absolute path. If it does not start with "/" the resource is resolved via search paths using resource resolver. If not matching resource is found it is returned unchanged.
        Parameters:
        resourceType - Resource type
        resourceResolver - Resource resolver
        Returns:
        Absolute resource type
      • makeRelative

        @NotNull
        public static @NotNull java.lang.String makeRelative​(@NotNull
                                                             @NotNull java.lang.String resourceType,
                                                             @NotNull
                                                             @NotNull org.apache.sling.api.resource.ResourceResolver resourceResolver)
        Makes the given resource type relative by stripping off any search path prefix. In case the given resource type does not start with any of these prefixes it is returned unmodified.
        Parameters:
        resourceType - The resource type to make relative.
        resourceResolver - Resource resolver
        Returns:
        Relative resource type
      • makeRelative

        @Deprecated
        @NotNull
        public static @NotNull java.lang.String makeRelative​(@NotNull
                                                             @NotNull java.lang.String resourceType)
        Deprecated.
        Makes the given resource type relative by stripping off an /apps/ or /libs/ prefix. In case the given resource type does not start with any of these prefixes it is returned unmodified. This method does not take the real configured search paths into account, but in case of AEM usually only /apps/ and /libs/ are used.
        Parameters:
        resourceType - The resource type to make relative.
        Returns:
        Relative resource type
      • equals

        public static boolean equals​(@NotNull
                                     @NotNull java.lang.String resourceType,
                                     @NotNull
                                     @NotNull java.lang.String anotherResourceType,
                                     @NotNull
                                     @NotNull org.apache.sling.api.resource.ResourceResolver resourceResolver)
        Returns true if the given resource type are equal. In case the value of any of the given resource types starts with /apps/ or /libs/ prefix this is removed before doing the comparison.
        Parameters:
        resourceType - A resource type
        anotherResourceType - Another resource type to compare with
        resourceResolver - Resource resolver
        Returns:
        true if the resource type equals the given resource type.
      • equals

        @Deprecated
        public static boolean equals​(@NotNull
                                     @NotNull java.lang.String resourceType,
                                     @NotNull
                                     @NotNull java.lang.String anotherResourceType)
        Deprecated.
        Returns true if the given resource type are equal. In case the value of any of the given resource types starts with /apps/ or /libs/ prefix this is removed before doing the comparison.
        Parameters:
        resourceType - A resource type
        anotherResourceType - Another resource type to compare with
        Returns:
        true if the resource type equals the given resource type.
      • is

        public static boolean is​(@Nullable
                                 @Nullable org.apache.sling.api.resource.Resource resource,
                                 @Nullable
                                 @Nullable java.lang.String resourceType)
        Returns true if the resource type or any of the resource's super type(s) equals the given resource type. This implementation is equal to ResourceResolver.isResourceType(Resource, String) - but in earlier sling version the comparison check did not take potentieal mixtures of relative and absolute resource types into account. This method respects this.
        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 orresourceType are null.