Class ResourceResolverWrapper
- All Implemented Interfaces:
Closeable,AutoCloseable,Adaptable,ResourceResolver
ResourceResolverWrapper is a wrapper for any ResourceResolver, delegating all method calls to the wrapped resource
resolver by default. Extensions of this class may overwrite any method to return different values as appropriate.-
Field Summary
Fields inherited from interface org.apache.sling.api.resource.ResourceResolver
PROPERTY_RESOURCE_TYPE, REQUEST_ATTR_WORKSPACE_INFO, USER_IMPERSONATOR -
Constructor Summary
ConstructorsConstructorDescriptionResourceResolverWrapper(ResourceResolver resolver) Creates a new wrapper instance, delegating all calls to the givenresolver. -
Method Summary
Modifier and TypeMethodDescription<AdapterType>
AdapterTypeAdapts the adaptable to another type.@NotNull ResourceResolverWraps and returns theResourceResolverobtained by callingcloneon the wrapped resource resolver.voidclose()Close this resource resolver.voidcommit()Persist all pending changes.Wraps theResourceobtained by callingcopyon the wrapped resource resolver.@NotNull ResourceWraps theResourceobtained by callingcreateon the wrapped resource resolver.voidDelete the resource Deleting a non existing resource leads to no operation nor exception.findResources(@NotNull String query, String language) Wraps and returns theIteratorobtained by callingfindResourceson the wrapped resource resolver.getAttribute(@NotNull String name) Returns the value of the given resource resolver attribute ornullif the attribute is not set (or not visible as is the case of theResourceResolverFactory.PASSWORDor other security sensitive attributes).Returns an iterator of attribute names whose value can be retrieved calling theResourceResolver.getAttribute(String)method.getChildren(@NotNull Resource parent) Wraps and returns theIterableobtained by callinggetChildrenon the wrapped resource resolver.Wraps and returns theResourceobtained by callinggetParenton the wrapped resource resolver.getParentResourceType(String resourceType) Returns the super type of the given resource type.getParentResourceType(Resource resource) Returns the super type of the given resource.Returns a mutable map to store temporary objects.getResource(@NotNull String path) Wraps and returns theResourceobtained by callinggetResourceon the wrapped resource resolver.getResource(Resource base, @NotNull String path) Wraps and returns theResourceobtained by callinggetResourceon the wrapped resource resolver.@NotNull String[]Returns the search path used by theResourceResolver.getResource(String)method to search for resources by relative path.Get the user ID, if any, associated with this resource resolver.booleanAre there any pending changes?booleanhasChildren(@NotNull Resource resource) Checks if the specified resource has any direct child resources.booleanisLive()Returnstrueif this resource resolver is still usable.booleanisResourceType(Resource resource, String resourceType) Returnstrueif the resource type or any of the resource's super type(s) equals the given resource type.listChildren(@NotNull Resource parent) Wraps and returns theIteratorobtained by callinglistChildrenon the wrapped resource resolver.@NotNull StringReturns a (request) path mapped from the (resource) path applying the reverse mapping used by theResourceResolver.resolve(String)such that when the path is given to theResourceResolver.resolve(String)method the same resource is returned.Returns an URL mapped from the (resource) path applying the reverse mapping used by theResourceResolver.resolve(HttpServletRequest, String)such that when the path is given to theResourceResolver.resolve(HttpServletRequest, String)method the same resource is returned.Wraps theResourceobtained by callingmoveon the wrapped resource resolver.booleanorderBefore(@NotNull Resource parent, @NotNull String name, @Nullable String followingSiblingName) Orders the child resources returned byResourceResolver.getChildren(Resource)andResourceResolver.listChildren(Resource)so that a given resource is listed before the given sibling resource.queryResources(@NotNull String query, String language) Queries the storage using the given query formulated in the given language.voidrefresh()The resolver is updated to reflect the latest state.@NotNull ResourceWraps and returns theResourceobtained by callingresolveon the wrapped resource resolver.@NotNull Resourceresolve(@NotNull javax.servlet.http.HttpServletRequest request) Wraps and returns theResourceobtained by callingresolveon the wrapped resource resolver.@NotNull ResourceWraps and returns theResourceobtained by callingresolveon the wrapped resource resolver.voidrevert()Revert all pending changes.
-
Constructor Details
-
ResourceResolverWrapper
Creates a new wrapper instance, delegating all calls to the givenresolver.- Parameters:
resolver- the wrapped resource resolver
-
-
Method Details
-
resolve
@NotNull public @NotNull Resource resolve(@NotNull @NotNull javax.servlet.http.HttpServletRequest request, @NotNull @NotNull String absPath) Wraps and returns theResourceobtained by callingresolveon the wrapped resource resolver.- Specified by:
resolvein interfaceResourceResolver- Parameters:
request- The http servlet request object providing more hints at how to resolve theabsPath. This parameter may benullin which case the implementation should use reasonable defaults.absPath- The absolute path to be resolved to a resource. If this parameter isnull, it is assumed to address the root of the resource tree. If the path is relative it is assumed relative to the root, that is a slash is prepended to the path before resolving it.- Returns:
- a wrapped resource obtained through the wrapped resource resolver
- See Also:
-
resolve
Wraps and returns theResourceobtained by callingresolveon the wrapped resource resolver.- Specified by:
resolvein interfaceResourceResolver- Parameters:
absPath- The absolute path to be resolved to a resource. If this parameter isnull, it is assumed to address the root of the resource tree. If the path is relative it is assumed relative to the root, that is a slash is prepended to the path before resolving it.- Returns:
- a wrapped resource obtained through the wrapped resource resolver
- See Also:
-
resolve
@NotNull public @NotNull Resource resolve(@NotNull @NotNull javax.servlet.http.HttpServletRequest request) Wraps and returns theResourceobtained by callingresolveon the wrapped resource resolver.- Specified by:
resolvein interfaceResourceResolver- Parameters:
request- The http servlet request object used to resolve the resource for. This must not benull.- Returns:
- a wrapped resource obtained through the wrapped resource resolver
- See Also:
-
map
Description copied from interface:ResourceResolverReturns a (request) path mapped from the (resource) path applying the reverse mapping used by theResourceResolver.resolve(String)such that when the path is given to theResourceResolver.resolve(String)method the same resource is returned.Note, that technically the
resourcePathneed not refer to an existing resource. This method just applies the mappings and returns the resulting string. If theresourcePathdoes not address an existing resource roundtripping may of course not work and callingResourceResolver.resolve(String)with the path returned may returnnull.This method is intended as the reverse operation of the
ResourceResolver.resolve(String)method.This method also does percent-encoding before returning the (request) path (with charset UTF-8). Due to this calling this method multiple times in a nested fashion might lead to an invalid (request) path which can subsequently not be resolved via
ResourceResolver.resolve(String).- Specified by:
mapin interfaceResourceResolver- Parameters:
resourcePath- The path for which to return a mapped path.- Returns:
- The mapped path or
resourcePathin case no mapping is found. - See Also:
-
map
public String map(@NotNull @NotNull javax.servlet.http.HttpServletRequest request, @NotNull @NotNull String resourcePath) Description copied from interface:ResourceResolverReturns an URL mapped from the (resource) path applying the reverse mapping used by theResourceResolver.resolve(HttpServletRequest, String)such that when the path is given to theResourceResolver.resolve(HttpServletRequest, String)method the same resource is returned.Note, that technically the
resourcePathneed not refer to an existing resource. This method just applies the mappings and returns the resulting string. If theresourcePathdoes not address an existing resource roundtripping may of course not work and callingResourceResolver.resolve(HttpServletRequest, String)with the path returned may returnnull.This method is intended as the reverse operation of the
ResourceResolver.resolve(HttpServletRequest, String)method. As such the URL returned is expected to be an absolute URL including scheme, host, any servlet context path and the actual path used to resolve the resource.This method also does percent-encoding before returning the URL (with charset UTF-8). Due to this calling this method multiple times in a nested fashion might lead to an invalid URL which can subsequently not be resolved via
ResourceResolver.resolve(String).- Specified by:
mapin interfaceResourceResolver- Parameters:
request- The http servlet request object which may be used to apply more mapping functionality.resourcePath- The path for which to return a mapped path.- Returns:
- The mapped URL or
resourcePathin case no mapping is found. - See Also:
-
getResource
Wraps and returns theResourceobtained by callinggetResourceon the wrapped resource resolver.- Specified by:
getResourcein interfaceResourceResolver- Parameters:
path- The absolute path to the resource object to be loaded. The path may contain relative path specifiers like.(current location) and..(parent location), which are resolved by this method. If the path is relative, that is the first character is not a slash, implementations are expected to apply a search path algorithm to resolve the relative path to a resource.- Returns:
- a wrapped resource obtained through the wrapped resource resolver
-
getResource
Wraps and returns theResourceobtained by callinggetResourceon the wrapped resource resolver.- Specified by:
getResourcein interfaceResourceResolver- Parameters:
base- The baseResourceagainst which a relative path argument given bypathis resolved. This parameter may benullif thepathis known to be absolute.path- The path to the resource object to be loaded. If the path is relative, i.e. does not start with a slash (/), the resource relative to the givenbaseresource is returned. The path may contain relative path specifiers like.(current location) and..(parent location), which are resolved by this method.- Returns:
- a wrapped resource obtained through the wrapped resource resolver
-
getSearchPath
Description copied from interface:ResourceResolverReturns the search path used by theResourceResolver.getResource(String)method to search for resources by relative path. If no search path is set an array with the single value "/" is returned.The returned array of strings is a copy of the internal value, so modifications to this array have no influence on the operation of the ResourceResolver.
The search path of a resource resolver never changes during the lifetime of the resource resolver. Therefore clients may call this method once and use the stored value together with this resource resolver.
Each entry in the array is an absolute path terminated with a slash character. Thus to create an absolute path from a search path entry and a relative path, the search path entry and relative path may just be concatenated.
- Specified by:
getSearchPathin interfaceResourceResolver- Returns:
- The array of search paths
-
listChildren
Wraps and returns theIteratorobtained by callinglistChildrenon the wrapped resource resolver.- Specified by:
listChildrenin interfaceResourceResolver- Parameters:
parent- TheResourcewhose children are requested.- Returns:
- a wrapped iterator obtained through the wrapped resource resolver
-
getParent
Wraps and returns theResourceobtained by callinggetParenton the wrapped resource resolver.- Specified by:
getParentin interfaceResourceResolver- Parameters:
child- TheResourcewhose parent is requested.- Returns:
- a wrapped resource obtained through the wrapped resource resolver
-
getChildren
Wraps and returns theIterableobtained by callinggetChildrenon the wrapped resource resolver.- Specified by:
getChildrenin interfaceResourceResolver- Parameters:
parent- TheResourcewhose children are requested.- Returns:
- a wrapped iterable obtained through the wrapped resource resolver
-
findResources
@NotNull public @NotNull Iterator<Resource> findResources(@NotNull @NotNull String query, String language) Wraps and returns theIteratorobtained by callingfindResourceson the wrapped resource resolver.- Specified by:
findResourcesin interfaceResourceResolver- Parameters:
query- The query string to use to find the resources.language- The language in which the query is formulated. The language should always be specified. However for compatibility with older version, if no language is specified, "xpath" is used.- Returns:
- a wrapped iterator obtained through the wrapped resource resolver
-
queryResources
@NotNull public @NotNull Iterator<Map<String,Object>> queryResources(@NotNull @NotNull String query, String language) Description copied from interface:ResourceResolverQueries the storage using the given query formulated in the given language.The semantic meaning of the query and language depend on the actual implementation and storage used for the resources. For JCR repository being used as storage, the query and language parameters are used to create a JCR
Querythrough theQueryManager. The result returned is then based on theRowIteratorprovided by the query result. The map returned for each row is indexed by the column name and the column value is the JCRValueobject converted into the respective Java object, such asBooleanfor a value of property type Boolean.- Specified by:
queryResourcesin interfaceResourceResolver- Parameters:
query- The query string to use to find the resources.language- The language in which the query is formulated. The language should always be specified. However for compatibility with older version, if no language is specified, "xpath" is used.- Returns:
- An
IteratorofMapinstances providing access to the query result.
-
hasChildren
Description copied from interface:ResourceResolverChecks if the specified resource has any direct child resources.- Specified by:
hasChildrenin interfaceResourceResolver- Parameters:
resource- the resource to check for direct children- Returns:
trueif the resource has any child resources
-
clone
@NotNull public @NotNull ResourceResolver clone(Map<String, Object> authenticationInfo) throws LoginExceptionWraps and returns theResourceResolverobtained by callingcloneon the wrapped resource resolver.- Specified by:
clonein interfaceResourceResolver- Parameters:
authenticationInfo- The map or credential data to overlay the original credential data with for the creation of a new resource resolver. This may benullin which case the same credential data is used as was used to create this instance.- Returns:
- a wrapped resource resolver
- Throws:
LoginException- If an error occurs creating the newResourceResolverwith the provided credential data.
-
isLive
public boolean isLive()Description copied from interface:ResourceResolverReturnstrueif this resource resolver is still usable. This method tests different things like if it has not been closed yet or if any of the used resource providers is not usable anymore.Unlike the other methods defined in this interface, this method will never throw an exception even after the resource resolver has been
closed.- Specified by:
isLivein interfaceResourceResolver- Returns:
trueif the resource resolver is still usable. Once the resource resolver has been closed or a used resource provider has been unregistered, this method returnsfalse.
-
close
public void close()Description copied from interface:ResourceResolverClose this resource resolver. This method should be called by clients when the resource resolver is not used anymore. Once this method has been called, the resource resolver is considered unusable and will throw exceptions if still used - with the exception of this method, which can be called several times with no ill effects. A resolver may also be closed implicitly in case when theResourceResolverFactorywhich was used to create this resolver is no longer active or any of the used resource providers is no longer active. All objects in the map maintained byResourceResolver.getPropertyMap()implementing theCloseableinterface, will be closed by callingCloseable#close()on each of them. Any exception thrown by this call will be ignored. The order in which the objects are closed is not defined.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Specified by:
closein interfaceResourceResolver- See Also:
-
getUserID
Description copied from interface:ResourceResolverGet the user ID, if any, associated with this resource resolver. The meaning of this identifier is an implementation detail defined by the underlying repository. This method may return null.- Specified by:
getUserIDin interfaceResourceResolver- Returns:
- the user ID
-
getAttributeNames
Description copied from interface:ResourceResolverReturns an iterator of attribute names whose value can be retrieved calling theResourceResolver.getAttribute(String)method. This iterator will not include any attributes which are not accessible.- Specified by:
getAttributeNamesin interfaceResourceResolver- Returns:
- An iterator of attribute names
-
getAttribute
Description copied from interface:ResourceResolverReturns the value of the given resource resolver attribute ornullif the attribute is not set (or not visible as is the case of theResourceResolverFactory.PASSWORDor other security sensitive attributes).- Specified by:
getAttributein interfaceResourceResolver- Parameters:
name- The name of the attribute to access- Returns:
- The value of the attribute or
nullif the attribute is not set or not accessible.
-
delete
Description copied from interface:ResourceResolverDelete the resource Deleting a non existing resource leads to no operation nor exception. The changes are transient and require a call toResourceResolver.commit()for persisting.- Specified by:
deletein interfaceResourceResolver- Parameters:
resource- The resource to delete- Throws:
PersistenceException- If the operation fails.
-
create
@NotNull public @NotNull Resource create(@NotNull @NotNull Resource parent, @NotNull @NotNull String name, Map<String, Object> properties) throws PersistenceExceptionWraps theResourceobtained by callingcreateon the wrapped resource resolver.- Specified by:
createin interfaceResourceResolver- Parameters:
parent- The parent resourcename- The name of the child resource - this is a plain name, not a path!properties- Optional properties for the resource- Returns:
- a wrapped resource obtained through the wrapped resource resolver
- Throws:
PersistenceException- If the operation fails in the underlying resource provider, e.g. in case a resource of that name does already exist.
-
orderBefore
public boolean orderBefore(@NotNull @NotNull Resource parent, @NotNull @NotNull String name, @Nullable @Nullable String followingSiblingName) throws UnsupportedOperationException, PersistenceException, IllegalArgumentException Description copied from interface:ResourceResolverOrders the child resources returned byResourceResolver.getChildren(Resource)andResourceResolver.listChildren(Resource)so that a given resource is listed before the given sibling resource. The changes are transient and require a call toResourceResolver.commit()for persisting.- Specified by:
orderBeforein interfaceResourceResolver- Parameters:
parent- the parent resource containing the child resources to order.name- the name of the child resource inparentto order. Must be an existing child name.followingSiblingName- the name of the resource child inparentwhich should come after the reordered resource. Ifnullis given the resource is ordered as last among all sibling resources.- Returns:
truein case the order of the child resources inparenthas been changed,falseif the given resource were already in the desired order.- Throws:
UnsupportedOperationException- in case the underlying resource provider does not support ordering or the child resources ofparentare provided by different providers.PersistenceException- If the operation fails in the underlying resource provider, e.g. in case the parent resource does not support orderable children.IllegalArgumentException- if eithernameorfollowingSiblingNameare not existing child resource names ofparent.- See Also:
-
revert
public void revert()Description copied from interface:ResourceResolverRevert all pending changes.- Specified by:
revertin interfaceResourceResolver
-
commit
Description copied from interface:ResourceResolverPersist all pending changes.- Specified by:
commitin interfaceResourceResolver- Throws:
PersistenceException- If persisting the changes fails.
-
hasChanges
public boolean hasChanges()Description copied from interface:ResourceResolverAre there any pending changes?- Specified by:
hasChangesin interfaceResourceResolver- Returns:
trueif there are pending changes.
-
getParentResourceType
Description copied from interface:ResourceResolverReturns the super type of the given resource. This method checks first if the resource itself knows its super type by callingResource.getResourceSuperType(). If that returnsnullResourceResolver.getParentResourceType(String)is invoked with the resource type of the resource.- Specified by:
getParentResourceTypein interfaceResourceResolver- Parameters:
resource- The resource to return the resource super type for.- Returns:
- The resource super type or
null. This method also returnsnullif the provided resource isnull
-
getParentResourceType
Description copied from interface:ResourceResolverReturns the super type of the given resource type. This method converts the resource type to a resource path and checks the corresponding resource (considering the search path). If the resource exists, theResource.getResourceSuperType()method is called.- Specified by:
getParentResourceTypein interfaceResourceResolver- Parameters:
resourceType- The resource type whose super type is to be returned.- Returns:
- the super type of the
resourceTypeornullif the resource given by the resource type does not exist or if it returnsnullfor its super type. It also returnsnullifresourceTypeis null.
-
isResourceType
Description copied from interface:ResourceResolverReturnstrueif the resource type or any of the resource's super type(s) equals the given resource type. In case the type of the given resource or the given resource type starts with one of the resource resolver's search paths it is converted to a relative resource type by stripping off the resource resolver's search path before doing the comparison.- Specified by:
isResourceTypein interfaceResourceResolver- 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.
-
refresh
public void refresh()Description copied from interface:ResourceResolverThe resolver is updated to reflect the latest state. Resources which have changes pending are not discarded.- Specified by:
refreshin interfaceResourceResolver
-
copy
Wraps theResourceobtained by callingcopyon the wrapped resource resolver.- Specified by:
copyin interfaceResourceResolver- Parameters:
srcAbsPath- the path of the resource to be copied.destAbsPath- the location to which the resource atsrcAbsPathis to be copied.- Returns:
- a wrapped resource obtained through the wrapped resource resolver
- Throws:
PersistenceException- If an error occurs.
-
move
Wraps theResourceobtained by callingmoveon the wrapped resource resolver.- Specified by:
movein interfaceResourceResolver- Parameters:
srcAbsPath- the path of the resource to be moved.destAbsPath- the location to which the resource atsrcAbsPathis to be moved.- Returns:
- a wrapped resource obtained through the wrapped resource resolver
- Throws:
PersistenceException- If an error occurs.
-
getPropertyMap
Description copied from interface:ResourceResolverReturns a mutable map to store temporary objects. This map is suited to store objects which share the same lifecycle as the resource resolver. The resource resolver itself does not use this map. The resource resolver will clear the map duringResourceResolver.close(), so afterwards the map is empty. If a stored value implements theCloseableinterface, the ResourceResolver will invoke theclosemethod} of the value before clearing the map. Clients should not use this map to store objects which have a lifecycle beyond the resource resolver. Any object stored into this map after the resource resolver has been closed will not be closed. The returned map is not thread-safe.- Specified by:
getPropertyMapin interfaceResourceResolver- Returns:
- the property map
- See Also:
-
adaptTo
Description copied from interface:AdaptableAdapts the adaptable to another type.Please note that it is explicitly left as an implementation detail whether each call to this method with the same
typeyields the same object or a new object on each call.Implementations of this method should document their adapted types as well as their behaviour with respect to returning newly created or same instances on each call.
- Specified by:
adaptToin interfaceAdaptable- Type Parameters:
AdapterType- The generic type to which this object is adapted to- Parameters:
type- The Class object of the target type, such asjavax.jcr.Node.classorjava.io.File.class- Returns:
- The adapter target or
nullif the object cannot adapt to the requested type
-