@ConsumerType public class ResourceResolverWrapper extends java.lang.Object implements 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.PROPERTY_RESOURCE_TYPE, REQUEST_ATTR_WORKSPACE_INFO, USER_IMPERSONATOR
Constructor and Description |
---|
ResourceResolverWrapper(ResourceResolver resolver)
Creates a new wrapper instance, delegating all calls to the given
resolver . |
Modifier and Type | Method and Description |
---|---|
<AdapterType> |
adaptTo(java.lang.Class<AdapterType> type)
Adapts the adaptable to another type.
|
ResourceResolver |
clone(java.util.Map<java.lang.String,java.lang.Object> authenticationInfo)
Wraps and returns the
ResourceResolver obtained by calling clone on the wrapped resource resolver. |
void |
close()
Close this resource resolver.
|
void |
commit()
Persist all pending changes.
|
Resource |
copy(java.lang.String srcAbsPath,
java.lang.String destAbsPath)
Wraps the
Resource obtained by calling copy on the wrapped resource resolver. |
Resource |
create(Resource parent,
java.lang.String name,
java.util.Map<java.lang.String,java.lang.Object> properties)
Wraps the
Resource obtained by calling create on the wrapped resource resolver. |
void |
delete(Resource resource)
Delete the resource
Deleting a non existing resource leads to no operation nor exception.
|
java.util.Iterator<Resource> |
findResources(java.lang.String query,
java.lang.String language)
Wraps and returns the
Iterator obtained by calling findResources on the wrapped resource resolver. |
java.lang.Object |
getAttribute(java.lang.String name)
Returns the value of the given resource resolver attribute or
null if the attribute is not set (or not visible as is the
case of the ResourceResolverFactory.PASSWORD or other security
sensitive attributes). |
java.util.Iterator<java.lang.String> |
getAttributeNames()
Returns an iterator of attribute names whose value can be retrieved
calling the
ResourceResolver.getAttribute(String) method. |
java.lang.Iterable<Resource> |
getChildren(Resource parent)
Wraps and returns the
Iterable obtained by calling getChildren on the wrapped resource resolver. |
Resource |
getParent(Resource child)
Wraps and returns the
Resource obtained by calling getParent on the wrapped resource resolver. |
java.lang.String |
getParentResourceType(Resource resource)
Returns the super type of the given resource.
|
java.lang.String |
getParentResourceType(java.lang.String resourceType)
Returns the super type of the given resource type.
|
Resource |
getResource(Resource base,
java.lang.String path)
Wraps and returns the
Resource obtained by calling getResource on the wrapped resource resolver. |
Resource |
getResource(java.lang.String path)
Wraps and returns the
Resource obtained by calling getResource on the wrapped resource resolver. |
java.lang.String[] |
getSearchPath()
Returns the search path used by the
ResourceResolver.getResource(String) method
to search for resources by relative path. |
java.lang.String |
getUserID()
Get the user ID, if any, associated with this resource resolver.
|
boolean |
hasChanges()
Are there any pending changes?
|
boolean |
hasChildren(Resource resource)
Checks if the specified resource has any direct child resources.
|
boolean |
isLive()
Returns
true if this resource resolver is still usable. |
boolean |
isResourceType(Resource resource,
java.lang.String resourceType)
Returns
true if the resource type or any of the resource's
super type(s) equals the given resource type. |
java.util.Iterator<Resource> |
listChildren(Resource parent)
Wraps and returns the
Iterator obtained by calling listChildren on the wrapped resource resolver. |
java.lang.String |
map(javax.servlet.http.HttpServletRequest request,
java.lang.String resourcePath)
Returns an URL mapped from the (resource) path applying the reverse
mapping used by the
ResourceResolver.resolve(HttpServletRequest, String) such
that when the path is given to the
ResourceResolver.resolve(HttpServletRequest, String) method the same resource is
returned. |
java.lang.String |
map(java.lang.String resourcePath)
Returns a path mapped from the (resource) path applying the reverse
mapping used by the
ResourceResolver.resolve(String) such that when the path is
given to the ResourceResolver.resolve(String) method the same resource is
returned. |
Resource |
move(java.lang.String srcAbsPath,
java.lang.String destAbsPath)
Wraps the
Resource obtained by calling move on the wrapped resource resolver. |
java.util.Iterator<java.util.Map<java.lang.String,java.lang.Object>> |
queryResources(java.lang.String query,
java.lang.String language)
Queries the storage using the given query formulated in the given
language.
|
void |
refresh()
The resolver is updated to reflect the latest state.
|
Resource |
resolve(javax.servlet.http.HttpServletRequest request)
Wraps and returns the
Resource obtained by calling resolve on the wrapped resource resolver. |
Resource |
resolve(javax.servlet.http.HttpServletRequest request,
java.lang.String absPath)
Wraps and returns the
Resource obtained by calling resolve on the wrapped resource resolver. |
Resource |
resolve(java.lang.String absPath)
Wraps and returns the
Resource obtained by calling resolve on the wrapped resource resolver. |
void |
revert()
Revert all pending changes.
|
public ResourceResolverWrapper(ResourceResolver resolver)
resolver
.resolver
- the wrapped resource resolver@Nonnull public Resource resolve(@Nonnull javax.servlet.http.HttpServletRequest request, @Nonnull java.lang.String absPath)
Resource
obtained by calling resolve
on the wrapped resource resolver.resolve
in interface ResourceResolver
request
- The http servlet request object providing more hints at
how to resolve the absPath
. This parameter may be
null
in which case the implementation should use
reasonable defaults.absPath
- The absolute path to be resolved to a resource. If this
parameter is null
, 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.@Nonnull public Resource resolve(@Nonnull java.lang.String absPath)
Resource
obtained by calling resolve
on the wrapped resource resolver.resolve
in interface ResourceResolver
absPath
- The absolute path to be resolved to a resource. If this
parameter is null
, 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.@Nonnull public Resource resolve(@Nonnull javax.servlet.http.HttpServletRequest request)
Resource
obtained by calling resolve
on the wrapped resource resolver.resolve
in interface ResourceResolver
request
- The http servlet request object used to resolve the
resource for. This must not be null
.@Nonnull public java.lang.String map(@Nonnull java.lang.String resourcePath)
ResourceResolver
ResourceResolver.resolve(String)
such that when the path is
given to the ResourceResolver.resolve(String)
method the same resource is
returned.
Note, that technically the resourcePath
need not refer to an
existing resource. This method just applies the mappings and returns the
resulting string. If the resourcePath
does not address an
existing resource roundtripping may of course not work and calling
ResourceResolver.resolve(String)
with the path returned may return
null
.
This method is intended as the reverse operation of the
ResourceResolver.resolve(String)
method.
map
in interface ResourceResolver
resourcePath
- The path for which to return a mapped path.public java.lang.String map(@Nonnull javax.servlet.http.HttpServletRequest request, @Nonnull java.lang.String resourcePath)
ResourceResolver
ResourceResolver.resolve(HttpServletRequest, String)
such
that when the path is given to the
ResourceResolver.resolve(HttpServletRequest, String)
method the same resource is
returned.
Note, that technically the resourcePath
need not refer to an
existing resource. This method just applies the mappings and returns the
resulting string. If the resourcePath
does not address an
existing resource roundtripping may of course not work and calling
ResourceResolver.resolve(HttpServletRequest, String)
with the path returned may
return null
.
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.
map
in interface ResourceResolver
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.public Resource getResource(@Nonnull java.lang.String path)
Resource
obtained by calling getResource
on the wrapped resource resolver.getResource
in interface ResourceResolver
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.public Resource getResource(Resource base, @Nonnull java.lang.String path)
Resource
obtained by calling getResource
on the wrapped resource resolver.getResource
in interface ResourceResolver
base
- The base Resource
against which a relative path
argument given by path
is resolved. This
parameter may be null
if the path
is
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 given base
resource
is returned. The path may contain relative path specifiers
like .
(current location) and ..
(parent location), which are resolved by this method.@Nonnull public java.lang.String[] getSearchPath()
ResourceResolver
ResourceResolver.getResource(String)
method
to search for resources by relative path. If no search path is set an
empty array 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.
getSearchPath
in interface ResourceResolver
@Nonnull public java.util.Iterator<Resource> listChildren(@Nonnull Resource parent)
Iterator
obtained by calling listChildren
on the wrapped resource resolver.listChildren
in interface ResourceResolver
parent
- The Resource
whose children are requested.public Resource getParent(@Nonnull Resource child)
Resource
obtained by calling getParent
on the wrapped resource resolver.getParent
in interface ResourceResolver
child
- The Resource
whose parent is requested.@Nonnull public java.lang.Iterable<Resource> getChildren(@Nonnull Resource parent)
Iterable
obtained by calling getChildren
on the wrapped resource resolver.getChildren
in interface ResourceResolver
parent
- The Resource
whose children are requested.@Nonnull public java.util.Iterator<Resource> findResources(@Nonnull java.lang.String query, java.lang.String language)
Iterator
obtained by calling findResources
on the wrapped resource resolver.findResources
in interface ResourceResolver
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.@Nonnull public java.util.Iterator<java.util.Map<java.lang.String,java.lang.Object>> queryResources(@Nonnull java.lang.String query, java.lang.String language)
ResourceResolver
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 Query
through the QueryManager
.
The result returned is then based on the RowIterator
provided by the query result. The map returned for each row is indexed by
the column name and the column value is the JCR Value
object
converted into the respective Java object, such as Boolean
for a value of property type Boolean.
queryResources
in interface ResourceResolver
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.Iterator
of Map
instances providing
access to the query result.public boolean hasChildren(@Nonnull Resource resource)
ResourceResolver
hasChildren
in interface ResourceResolver
resource
- the resource to check for direct childrentrue
if the resource has any child resources@Nonnull public ResourceResolver clone(java.util.Map<java.lang.String,java.lang.Object> authenticationInfo) throws LoginException
ResourceResolver
obtained by calling clone
on the wrapped resource resolver.clone
in interface ResourceResolver
authenticationInfo
- The map or credential data to overlay the
original credential data with for the creation of a new
resource resolver. This may be null
in which case
the same credential data is used as was used to create this
instance.LoginException
- If an error occurs creating the new
ResourceResolver
with the provided credential
data.public boolean isLive()
ResourceResolver
true
if 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
.
isLive
in interface ResourceResolver
true
if the resource resolver is still usable.
Once the resource resolver has been closed or a used resource
provider has been unregistered, this method returns false
.public void close()
ResourceResolver
ResourceResolverFactory
which was used to create this resolver is no longer active or
any of the used resource providers is no longer active.close
in interface java.io.Closeable
close
in interface java.lang.AutoCloseable
close
in interface ResourceResolver
Resource Resolver (section lifecycle)
public java.lang.String getUserID()
ResourceResolver
getUserID
in interface ResourceResolver
@Nonnull public java.util.Iterator<java.lang.String> getAttributeNames()
ResourceResolver
ResourceResolver.getAttribute(String)
method. This iterator will not
include any attributes which are not accessible.getAttributeNames
in interface ResourceResolver
public java.lang.Object getAttribute(@Nonnull java.lang.String name)
ResourceResolver
null
if the attribute is not set (or not visible as is the
case of the ResourceResolverFactory.PASSWORD
or other security
sensitive attributes).getAttribute
in interface ResourceResolver
name
- The name of the attribute to accessnull
if the attribute
is not set or not accessible.public void delete(@Nonnull Resource resource) throws PersistenceException
ResourceResolver
delete
in interface ResourceResolver
resource
- The resource to deletePersistenceException
- If the operation fails.@Nonnull public Resource create(@Nonnull Resource parent, @Nonnull java.lang.String name, java.util.Map<java.lang.String,java.lang.Object> properties) throws PersistenceException
Resource
obtained by calling create
on the wrapped resource resolver.create
in interface ResourceResolver
parent
- The parent resourcename
- The name of the child resource - this is a plain name, not a path!properties
- Optional properties for the resourcePersistenceException
- If the operation fails.public void revert()
ResourceResolver
revert
in interface ResourceResolver
public void commit() throws PersistenceException
ResourceResolver
commit
in interface ResourceResolver
PersistenceException
- If persisting the changes fails.public boolean hasChanges()
ResourceResolver
hasChanges
in interface ResourceResolver
true
if there are pending changes.public java.lang.String getParentResourceType(Resource resource)
ResourceResolver
Resource.getResourceSuperType()
. If that returns
null
ResourceResolver.getParentResourceType(String)
is invoked with the resource type of the resource.getParentResourceType
in interface ResourceResolver
resource
- The resource to return the resource super type for.null
. This
method also returns null
if the
provided resource is null
public java.lang.String getParentResourceType(java.lang.String resourceType)
ResourceResolver
Resource.getResourceSuperType()
method
is called.getParentResourceType
in interface ResourceResolver
resourceType
- The resource type whose super type is to be returned.resourceType
or
null
if the resource given by the resource type does not exist or
if it returns null
for its super type. It also returns
null
if resourceType
is null.public boolean isResourceType(Resource resource, java.lang.String resourceType)
ResourceResolver
true
if 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.isResourceType
in interface ResourceResolver
resource
- The resource to checkresourceType
- The resource type to check this resource against.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
.public void refresh()
ResourceResolver
refresh
in interface ResourceResolver
public Resource copy(java.lang.String srcAbsPath, java.lang.String destAbsPath) throws PersistenceException
Resource
obtained by calling copy
on the wrapped resource resolver.copy
in interface ResourceResolver
srcAbsPath
- the path of the resource to be copied.destAbsPath
- the location to which the resource at
srcAbsPath
is to be copied.PersistenceException
- If an error occurs.public Resource move(java.lang.String srcAbsPath, java.lang.String destAbsPath) throws PersistenceException
Resource
obtained by calling move
on the wrapped resource resolver.move
in interface ResourceResolver
srcAbsPath
- the path of the resource to be moved.destAbsPath
- the location to which the resource at
srcAbsPath
is to be moved.PersistenceException
- If an error occurs.public <AdapterType> AdapterType adaptTo(@Nonnull java.lang.Class<AdapterType> type)
Adaptable
Please note that it is explicitly left as an implementation detail whether
each call to this method with the same type
yields 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.
adaptTo
in interface Adaptable
AdapterType
- The generic type to which this object is adapted
totype
- The Class object of the target type, such as
javax.jcr.Node.class
or
java.io.File.class
null
if the object cannot
adapt to the requested typeCopyright © 2018 The Apache Software Foundation. All rights reserved.