Class ResourceType

java.lang.Object
io.wcm.sling.commons.resource.ResourceType

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

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

    Modifier and Type
    Method
    Description
    static boolean
    equals(@NotNull String resourceType, @NotNull String anotherResourceType)
    Deprecated.
    static boolean
    equals(@NotNull String resourceType, @NotNull 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 String resourceType)
    Returns true if the resource type or any of the resource's super type(s) equals the given resource type.
    static @NotNull String
    makeAbsolute(@NotNull String resourceType, @NotNull org.apache.sling.api.resource.ResourceResolver resourceResolver)
    Converts the resource type to an absolute path.
    static @NotNull String
    makeRelative(@NotNull String resourceType)
    Deprecated.
    static @NotNull String
    makeRelative(@NotNull 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 Details

  • Method Details

    • 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(since="1.1.0") @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(since="1.1.0") 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.