Package com.composum.sling.core.util
Class ResourceUtil
- java.lang.Object
-
- org.apache.sling.api.resource.ResourceUtil
-
- com.composum.sling.core.util.ResourceUtil
-
- All Implemented Interfaces:
CoreConstants
,org.apache.jackrabbit.JcrConstants
public class ResourceUtil extends org.apache.sling.api.resource.ResourceUtil implements CoreConstants
A collection of loads of utilities dealing withResource
s.
-
-
Field Summary
Fields Modifier and Type Field Description static Map<String,List<String>>
NODE_TYPE_MAP
-
Fields inherited from interface com.composum.sling.core.util.CoreConstants
CONTENT_NODE, DEFAULT_OVERLAY_ROOT, DEFAULT_OVERRIDE_ROOT, JCR_CREATED_BY, JCR_DESCRIPTION, JCR_LASTMODIFIED_BY, JCR_TITLE, MIX_CREATED, MIX_LAST_MODIFIED, MIX_TITLE, PROP_BASE_VERSION, PROP_CREATED, PROP_DATA, PROP_DESCRIPTION, PROP_ENCODING, PROP_FILE_REFERENCE, PROP_JCR_CONTENT, PROP_LAST_MODIFIED, PROP_MIME_TYPE, PROP_MIXINTYPES, PROP_PREDECESSORS, PROP_PRIMARY_TYPE, PROP_RESOURCE_SUPER_TYPE, PROP_RESOURCE_TYPE, PROP_ROOT_VERSION, PROP_SUCCESSORS, PROP_TITLE, PROP_UUID, PROP_VERSION_HISTORY, PROPO_FROZEN_UUID, TYPE_CREATED, TYPE_FILE, TYPE_FOLDER, TYPE_LAST_MODIFIED, TYPE_LINKED_FILE, TYPE_LOCKABLE, TYPE_OAKINDEX, TYPE_REFERENCEABLE, TYPE_RESOURCE, TYPE_SLING_FOLDER, TYPE_SLING_ORDERED_FOLDER, TYPE_SLING_RESOURCE, TYPE_TITLE, TYPE_UNSTRUCTURED, TYPE_VERSIONABLE
-
Fields inherited from interface org.apache.jackrabbit.JcrConstants
JCR_AUTOCREATED, JCR_BASEVERSION, JCR_CHILD, JCR_CHILDNODEDEFINITION, JCR_CONTENT, JCR_CREATED, JCR_DATA, JCR_DEFAULTPRIMARYTYPE, JCR_DEFAULTVALUES, JCR_ENCODING, JCR_FROZENMIXINTYPES, JCR_FROZENNODE, JCR_FROZENPRIMARYTYPE, JCR_FROZENUUID, JCR_HASORDERABLECHILDNODES, JCR_ISCHECKEDOUT, JCR_ISMIXIN, JCR_LANGUAGE, JCR_LASTMODIFIED, JCR_LOCKISDEEP, JCR_LOCKOWNER, JCR_MANDATORY, JCR_MERGEFAILED, JCR_MIMETYPE, JCR_MIXINTYPES, JCR_MULTIPLE, JCR_NAME, JCR_NODETYPENAME, JCR_ONPARENTVERSION, JCR_PATH, JCR_PREDECESSORS, JCR_PRIMARYITEMNAME, JCR_PRIMARYTYPE, JCR_PROPERTYDEFINITION, JCR_PROTECTED, JCR_REQUIREDPRIMARYTYPES, JCR_REQUIREDTYPE, JCR_ROOTVERSION, JCR_SAMENAMESIBLINGS, JCR_SCORE, JCR_STATEMENT, JCR_SUCCESSORS, JCR_SUPERTYPES, JCR_SYSTEM, JCR_UUID, JCR_VALUECONSTRAINTS, JCR_VERSIONABLEUUID, JCR_VERSIONHISTORY, JCR_VERSIONLABELS, JCR_VERSIONSTORAGE, MIX_LOCKABLE, MIX_REFERENCEABLE, MIX_SHAREABLE, MIX_VERSIONABLE, NT_BASE, NT_CHILDNODEDEFINITION, NT_FILE, NT_FOLDER, NT_FROZENNODE, NT_HIERARCHYNODE, NT_LINKEDFILE, NT_NODETYPE, NT_PROPERTYDEFINITION, NT_QUERY, NT_RESOURCE, NT_UNSTRUCTURED, NT_VERSION, NT_VERSIONEDCHILD, NT_VERSIONHISTORY, NT_VERSIONLABELS
-
-
Constructor Summary
Constructors Constructor Description ResourceUtil()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static boolean
containsPath(List<org.apache.sling.api.resource.Resource> collection, String path)
static boolean
containsPath(List<org.apache.sling.api.resource.Resource> collection, org.apache.sling.api.resource.Resource resource)
static javax.jcr.Binary
getBinaryData(org.apache.sling.api.resource.Resource resource)
static @Nullable org.apache.sling.api.resource.Resource
getByUuid(@NotNull org.apache.sling.api.resource.ResourceResolver resolver, @Nullable String uuid)
Finds a mix:referenceable by its jcr:uuid.static List<org.apache.sling.api.resource.Resource>
getChildrenByResourceType(org.apache.sling.api.resource.Resource resource, String resourceType)
retrieves all children of a sling:resourceTypestatic List<org.apache.sling.api.resource.Resource>
getChildrenByType(org.apache.sling.api.resource.Resource resource, String type)
retrieves all children of a type (node type or resource type)static List<org.apache.sling.api.resource.Resource>
getChildrenByType(org.apache.sling.api.resource.Resource resource, List<String> typeSet)
retrieves all children of one of a type from a type set (node type or resource type)static org.apache.sling.api.resource.Resource
getDataResource(org.apache.sling.api.resource.Resource resource)
static int
getIndexOfSameType(org.apache.sling.api.resource.Resource resource)
static String
getNameExtension(org.apache.sling.api.resource.Resource resource)
static org.apache.sling.api.resource.Resource
getNextOfSameType(org.apache.sling.api.resource.Resource resource, boolean wrapAround)
static org.apache.sling.api.resource.Resource
getOrCreateChild(org.apache.sling.api.resource.Resource resource, String relPath, String primaryTypes)
Retrieves the resources child resource, creates this child if not existing.static org.apache.sling.api.resource.Resource
getOrCreateResource(org.apache.sling.api.resource.ResourceResolver resolver, String path)
static org.apache.sling.api.resource.Resource
getOrCreateResource(org.apache.sling.api.resource.ResourceResolver resolver, String path, String primaryTypes)
static String
getPrimaryType(org.apache.sling.api.resource.Resource resource)
retrieves the primary type of the resources nodestatic @Nullable org.apache.sling.api.resource.Resource
getReferredResource(@Nullable org.apache.sling.api.resource.Resource propertyResource)
Finds the referenced node from a property of type REFERENCE, WEAKREFERENCE or PATH or convertable to that.static org.apache.sling.api.resource.Resource
getResourceType(org.apache.sling.api.resource.Resource resource)
static org.apache.sling.api.resource.Resource
getResourceType(org.apache.sling.api.resource.ResourceResolver resolver, String resourceTypeName)
static <T> T
getTypeProperty(org.apache.sling.api.resource.ResourceResolver resolver, String resourceTypeName, String name, Class<T> type)
static <T> T
getTypeProperty(org.apache.sling.api.resource.Resource resource, String name, Class<T> type)
static <T> T
getTypeProperty(org.apache.sling.api.resource.Resource resource, String name, T defaultValue)
static boolean
isFile(org.apache.sling.api.resource.Resource resource)
Returns 'true' is this resource represents a 'file'.static boolean
isNodeType(String wanted, String probe)
static boolean
isNodeType(org.apache.sling.api.resource.Resource resource, String primaryType)
Returns true if this node is of the specified primary node type or mixin type, or a subtype thereof.static boolean
isPrimaryType(org.apache.sling.api.resource.Resource resource, String primaryType)
True if thegetPrimaryType(Resource)
of the resource is exactly primaryType.static boolean
isRenderableFile(org.apache.sling.api.resource.Resource resource)
Returns 'true' is this resource represents a 'file' witch can be displayed (a HTML file).static boolean
isResourceType(@Nullable org.apache.sling.api.resource.Resource resource, String resourceType)
Checks whether any of the resource's primary type, super types, sling resource type and supertypes is {resourceType}.static boolean
isResourceType(org.apache.sling.api.resource.ResourceResolver resolver, String resourceTypeName, Pattern pattern)
static boolean
isResourceType(org.apache.sling.api.resource.Resource resource, Pattern pattern)
static boolean
isWriteEnabled(org.apache.sling.api.resource.Resource resource, String relPath)
Checks the access control policies for enabled changes (node creation and property change).static @NotNull String[]
splitPathAndName(@NotNull String path)
Returns an array of two elements for a nontrivial path (containing /): the parent path and the name.-
Methods inherited from class org.apache.sling.api.resource.ResourceUtil
adaptTo, createUniqueChildName, findResourceSuperType, getBatchResourceRemover, getName, getName, getOrCreateResource, getOrCreateResource, getParent, getParent, getParent, getResourceSuperType, getValueMap, isA, isNonExistingResource, isStarResource, isSyntheticResource, listChildren, normalize, resourceTypeToPath, unwrap
-
-
-
-
Method Detail
-
getChildrenByType
public static List<org.apache.sling.api.resource.Resource> getChildrenByType(org.apache.sling.api.resource.Resource resource, List<String> typeSet)
retrieves all children of one of a type from a type set (node type or resource type)
-
getChildrenByType
public static List<org.apache.sling.api.resource.Resource> getChildrenByType(org.apache.sling.api.resource.Resource resource, String type)
retrieves all children of a type (node type or resource type)
-
getChildrenByResourceType
public static List<org.apache.sling.api.resource.Resource> getChildrenByResourceType(org.apache.sling.api.resource.Resource resource, String resourceType)
retrieves all children of a sling:resourceType
-
getIndexOfSameType
public static int getIndexOfSameType(org.apache.sling.api.resource.Resource resource)
-
getNextOfSameType
public static org.apache.sling.api.resource.Resource getNextOfSameType(org.apache.sling.api.resource.Resource resource, boolean wrapAround)
-
getNameExtension
public static String getNameExtension(org.apache.sling.api.resource.Resource resource)
-
getPrimaryType
public static String getPrimaryType(org.apache.sling.api.resource.Resource resource)
retrieves the primary type of the resources node
-
isResourceType
public static boolean isResourceType(@Nullable @Nullable org.apache.sling.api.resource.Resource resource, String resourceType)
Checks whether any of the resource's primary type, super types, sling resource type and supertypes is {resourceType}.
-
isPrimaryType
public static boolean isPrimaryType(org.apache.sling.api.resource.Resource resource, String primaryType)
True if thegetPrimaryType(Resource)
of the resource is exactly primaryType.
-
isNodeType
public static boolean isNodeType(org.apache.sling.api.resource.Resource resource, String primaryType)
Returns true if this node is of the specified primary node type or mixin type, or a subtype thereof. Returns false otherwise.
-
getResourceType
public static org.apache.sling.api.resource.Resource getResourceType(org.apache.sling.api.resource.Resource resource)
-
getResourceType
public static org.apache.sling.api.resource.Resource getResourceType(org.apache.sling.api.resource.ResourceResolver resolver, String resourceTypeName)
-
isResourceType
public static boolean isResourceType(org.apache.sling.api.resource.Resource resource, Pattern pattern)
-
isResourceType
public static boolean isResourceType(org.apache.sling.api.resource.ResourceResolver resolver, String resourceTypeName, Pattern pattern)
-
getTypeProperty
public static <T> T getTypeProperty(org.apache.sling.api.resource.Resource resource, String name, T defaultValue)
-
getTypeProperty
public static <T> T getTypeProperty(org.apache.sling.api.resource.Resource resource, String name, Class<T> type)
-
getTypeProperty
public static <T> T getTypeProperty(org.apache.sling.api.resource.ResourceResolver resolver, String resourceTypeName, String name, Class<T> type)
-
getOrCreateResource
public static org.apache.sling.api.resource.Resource getOrCreateResource(org.apache.sling.api.resource.ResourceResolver resolver, String path) throws javax.jcr.RepositoryException
- Throws:
javax.jcr.RepositoryException
-
getOrCreateResource
public static org.apache.sling.api.resource.Resource getOrCreateResource(org.apache.sling.api.resource.ResourceResolver resolver, String path, String primaryTypes) throws javax.jcr.RepositoryException
- Throws:
javax.jcr.RepositoryException
-
containsPath
public static boolean containsPath(List<org.apache.sling.api.resource.Resource> collection, org.apache.sling.api.resource.Resource resource)
-
containsPath
public static boolean containsPath(List<org.apache.sling.api.resource.Resource> collection, String path)
-
splitPathAndName
@NotNull public static @NotNull String[] splitPathAndName(@NotNull @NotNull String path)
Returns an array of two elements for a nontrivial path (containing /): the parent path and the name. The parent of a toplevel node like "/var" is returned as "/". If it doesn't contain a / , the result has null in the first place.
-
getOrCreateChild
public static org.apache.sling.api.resource.Resource getOrCreateChild(org.apache.sling.api.resource.Resource resource, String relPath, String primaryTypes) throws javax.jcr.RepositoryException
Retrieves the resources child resource, creates this child if not existing.- Parameters:
resource
- the resource to extendrelPath
- the path to the requested child resourceprimaryTypes
- the 'path' of primary types for the new nodes (optional, can be 'null')- Returns:
- the requested child
- Throws:
javax.jcr.RepositoryException
-
isWriteEnabled
public static boolean isWriteEnabled(org.apache.sling.api.resource.Resource resource, String relPath) throws javax.jcr.RepositoryException
Checks the access control policies for enabled changes (node creation and property change).- Throws:
javax.jcr.RepositoryException
-
isRenderableFile
public static boolean isRenderableFile(org.apache.sling.api.resource.Resource resource)
Returns 'true' is this resource represents a 'file' witch can be displayed (a HTML file).
-
isFile
public static boolean isFile(org.apache.sling.api.resource.Resource resource)
Returns 'true' is this resource represents a 'file'.
-
getDataResource
public static org.apache.sling.api.resource.Resource getDataResource(org.apache.sling.api.resource.Resource resource)
-
getBinaryData
public static javax.jcr.Binary getBinaryData(org.apache.sling.api.resource.Resource resource)
-
getByUuid
@Nullable public static @Nullable org.apache.sling.api.resource.Resource getByUuid(@NotNull @NotNull org.apache.sling.api.resource.ResourceResolver resolver, @Nullable @Nullable String uuid) throws javax.jcr.RepositoryException
Finds a mix:referenceable by its jcr:uuid. This works only for JCR resources.- Throws:
javax.jcr.RepositoryException
-
getReferredResource
@Nullable public static @Nullable org.apache.sling.api.resource.Resource getReferredResource(@Nullable @Nullable org.apache.sling.api.resource.Resource propertyResource) throws javax.jcr.RepositoryException
Finds the referenced node from a property of type REFERENCE, WEAKREFERENCE or PATH or convertable to that.- Throws:
javax.jcr.RepositoryException
-
-