Class ResourceType


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

      • APPS_PREFIX

        @Deprecated
        public static final 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 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 String makeAbsolute​(@NotNull
                                                   @NotNull 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 String makeRelative​(@NotNull
                                                   @NotNull 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 String makeRelative​(@NotNull
                                                   @NotNull 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 String resourceType,
                                     @NotNull
                                     @NotNull 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 String resourceType,
                                     @NotNull
                                     @NotNull 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 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.