Package io.wcm.sling.commons.resource
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 StringAPPS_PREFIXDeprecated.Search paths are confurable and should not be hard-coded.static StringLIBS_PREFIXDeprecated.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 booleanequals(@NotNull String resourceType, @NotNull String anotherResourceType)Deprecated.Please useequals(String, String, ResourceResolver)instead.static booleanequals(@NotNull String resourceType, @NotNull String anotherResourceType, @NotNull org.apache.sling.api.resource.ResourceResolver resourceResolver)Returnstrueif the given resource type are equal.static booleanis(@Nullable org.apache.sling.api.resource.Resource resource, @Nullable String resourceType)Returnstrueif the resource type or any of the resource's super type(s) equals the given resource type.static @NotNull StringmakeAbsolute(@NotNull String resourceType, @NotNull org.apache.sling.api.resource.ResourceResolver resourceResolver)Converts the resource type to an absolute path.static @NotNull StringmakeRelative(@NotNull String resourceType)Deprecated.Please usemakeRelative(String, ResourceResolver)instead.static @NotNull StringmakeRelative(@NotNull String resourceType, @NotNull org.apache.sling.api.resource.ResourceResolver resourceResolver)Makes the given resource type relative by stripping off any search path prefix.
-
-
-
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 typeresourceResolver- 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.Please usemakeRelative(String, ResourceResolver)instead.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)Returnstrueif 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 typeanotherResourceType- Another resource type to compare withresourceResolver- Resource resolver- Returns:
trueif the resource type equals the given resource type.
-
equals
@Deprecated public static boolean equals(@NotNull @NotNull String resourceType, @NotNull @NotNull String anotherResourceType)
Deprecated.Please useequals(String, String, ResourceResolver)instead.Returnstrueif 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 typeanotherResourceType- Another resource type to compare with- Returns:
trueif 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)Returnstrueif the resource type or any of the resource's super type(s) equals the given resource type. This implementation is equal toResourceResolver.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 checkresourceType- The resource type to check this resource against.- Returns:
trueif the resource type or any of the resource's super type(s) equals the given resource type.falseis also returned ifresourceorresourceTypearenull.
-
-