Package org.apache.sling.api.resource

# Interface ResourceResolver

All Superinterfaces:
  `Adaptable`, `AutoCloseable`, `Closeable`

All Known Implementing Classes:
  `ResourceResolverWrapper`

@ProviderType public interface ResourceResolver extends Adaptable, Closeable
The `ResourceResolver` defines the API which may be used to resolve `Resource` objects and work with such resources like creating, editing or updating them. The resource resolver is available to the request processing servlet through the `SlingHttpServletRequest.getResourceResolver()` method. A resource resolver can also be created through the `ResourceResolverFactory` service.

The `ResourceResolver` is also an `Adaptable` to get adapters to other types. A JCR based resource resolver might support adapting to the JCR Session used by the resolver to access the JCR Repository.

A `ResourceResolver` is generally not thread safe! As a consequence, an application which uses the resolver, its returned resources and/or objects resulting from adapting either the resolver or a resource, must provide proper synchronization to ensure no more than one thread concurrently operates against a single resolver, resource or resulting objects.

Accessing Resources

This interface defines two kinds of methods to access resources: The `resolve` methods and the `getResource` methods. The difference lies in the algorithm applied to find the requested resource and in the behavior in case a resource cannot be found:

Accessing Resources
Method Kind | Access Algorithm | Missing Resource
--- | --- | ---
resolve | Path is always assumed to be absolute. Uses elaborate resource resolution algorithm. This kind of method is intended to resolve request URLs to resources. | Returns `NonExistingResource`
getResource | Directly access resources with absolute path. For relative paths, the `search path` is applied. This method is intended to be used by request processing scripts to access further resources as required. | Returns `null`

Resource Handling

A resource resolver provides various methods to manage resources. All changes are transient and require to commit them at the end.

- `create(Resource, String, Map)` for creating a new resource.
- `delete(Resource)` to delete a resource.
- `Adaptable.adaptTo(Class)` allows to adapt a resource to a `ModifiableValueMap` to update a resource.
- `move(String, String)` to move resources.
- `copy(String, String)` to copy resources.
- `commit()` commits all staged changes.
- `revert()` reverts all staged changes.

The resource tree accessible through the resource resolver is backed by one or more `ResourceProvider`s. In general it is advisable to limit transient changes to a single resource provider. The `commit()` is not using a two phase commit, therefore if there is more than one resource provider involved and one of them fails in persisting, changes already committed to other providers are not reverted.

External changes

Changes which happen outside of the Resource API provided by Sling are not required to be reflected immediately within an already opened ResourceResolver and its associated resources. For example, if the ResourceResolver is backed by a JCR implementation, any changes within the JCR session (which is an implementation detail of the respective ResourceResolver implementation) are not required to be reflected within its Resource Resolver.

Lifecycle

A Resource Resolver has a life cycle which begins with the creation of the Resource Resolver using any of the factory methods and ends with calling the `close()` method. It is very important to call the `close()` method once the resource resolver is not used any more to ensure any system resources are properly cleaned up. A Resource Resolver may also be closed implicitly if the `ResourceResolverFactory` which was used to create this resolver is no longer active.

To check whether a Resource Resolver can still be used, the `isLive()` method can be called.

A `ResourceResolver` is only valid for as long as the `ResourceResolverFactory` that created this instance exists. The same applies in general to all objects returned by this instance, especially for all resources. If the `ResourceResolverFactory` does not exist anymore, the resource resolver instances becomes invalid.

Resource Resolver Attributes

The authentication info properties provided to the `ResourceResolverFactory.getResourceResolver(Map)`, `ResourceResolverFactory.getAdministrativeResourceResolver(Map)`, or `clone(Map)` are available through the `getAttributeNames()` and `getAttribute(String)` methods with the exception of security sensitive properties like `ResourceResolverFactory.PASSWORD` which is not exposed.

## Field Summary

Fields
Modifier and Type
Field
Description
`static final String`
`PROPERTY_RESOURCE_SUPER_TYPE`
This is property to be used for setting the resource super type of a resource during either creation (`create(Resource, String, Map)`) or modifying (`ModifiableValueMap`).
`static final String`
`PROPERTY_RESOURCE_TYPE`
This is the property to be used for setting the resource type of a resource during either creation (`create(Resource, String, Map)`) or modifying (`ModifiableValueMap`).
`static final String`
`REQUEST_ATTR_WORKSPACE_INFO`
Deprecated.
`static final String`
`USER_IMPERSONATOR`
The name of the resource resolver attribute which is set if the resource resolver has been impersonated as per the `ResourceResolverFactory.USER_IMPERSONATION` property.

## Method Summary

Modifier and Type
Method
Description
`@NotNull ResourceResolver`
`clone(Map<String,Object> authenticationInfo)`
Returns a new `ResourceResolver` instance based on the given `authenticationInfo` map and the original authentication info used to create this instance.
`void`
`close()`
Close this resource resolver.
`void`
`commit()`
Persist all pending changes.
`Resource`
`copy(String srcAbsPath, String destAbsPath)`
This method copies the subgraph rooted at, and including, the resource at `srcAbsPath` to the new location at `destAbsPath` and adds it as a child node of the resource at `destAbsPath`.
`@NotNull Resource`
`create(@NotNull Resource parent, @NotNull String name, Map<String,Object> properties)`
Add a child resource to the given parent resource.
`void`
`delete(@NotNull Resource resource)`
Delete the resource Deleting a non existing resource leads to no operation nor exception.
`@NotNull Iterator<Resource>`
`findResources(@NotNull String query, String language)`
Searches for resources using the given query formulated in the given language.
`@Nullable Object`
`getAttribute(@NotNull 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).
`@NotNull Iterator<String>`
`getAttributeNames()`
Returns an iterator of attribute names whose value can be retrieved calling the `getAttribute(String)` method.
`@NotNull Iterable<Resource>`
`getChildren(@NotNull Resource parent)`
Returns an `Iterable` of `Resource` objects loaded from the children of the given `Resource`.
`@Nullable Resource`
`getParent(@NotNull Resource child)`
Returns the parent resource of this resource.
`@Nullable String`
`getParentResourceType(String resourceType)`
Returns the super type of the given resource type.
`@Nullable String`
`getParentResourceType(Resource resource)`
Returns the super type of the given resource.
`@NotNull Map<String,Object>`
`getPropertyMap()`
Returns a mutable map to store temporary objects.
`@Nullable Resource`
`getResource(@NotNull String path)`
Returns a `Resource` object for data located at the given path.
`@Nullable Resource`
`getResource(Resource base, @NotNull String path)`
Returns a `Resource` object for data located at the given path.
`@NotNull String[]`
`getSearchPath()`
Returns the search path used by the `getResource(String)` method to search for resources by relative path.
`@Nullable String`
`getUserID()`
Get the user ID, if any, associated with this resource resolver.
`boolean`
`hasChanges()`
Are there any pending changes?
`boolean`
`hasChildren(@NotNull 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, String resourceType)`
Returns `true` if the resource type or any of the resource's super type(s) equals the given resource type.
`@NotNull Iterator<Resource>`
`listChildren(@NotNull Resource parent)`
Returns an `Iterator` of `Resource` objects loaded from the children of the given `Resource`.
`@NotNull String`
`map(@NotNull jakarta.servlet.http.HttpServletRequest request, @NotNull String resourcePath)`
Returns an URL mapped from the (resource) path applying the reverse mapping used by the `resolve(HttpServletRequest, String)` such that when the path is given to the `resolve(HttpServletRequest, String)` method the same resource is returned.
`@NotNull String`
`map(@NotNull String resourcePath)`
Returns a (request) path mapped from the (resource) path applying the reverse mapping used by the `resolve(String)` such that when the path is given to the `resolve(String)` method the same resource is returned.
`@NotNull String`
`map(javax.servlet.http.HttpServletRequest request, @NotNull String resourcePath)`
Deprecated.
Use `map(HttpServletRequest, String)` instead.
`Resource`
`move(String srcAbsPath, String destAbsPath)`
This method moves the subgraph rooted at, and including, the resource at `srcAbsPath` to the new location at `destAbsPath` and adds it as a child node of the resource at `destAbsPath`.
`boolean`
`orderBefore(@NotNull Resource parent, @NotNull String name, @Nullable String followingSiblingName)`
Orders the child resources returned by `getChildren(Resource)` and `listChildren(Resource)` so that a given resource is listed before the given sibling resource.
`@NotNull Iterator<Map<String,Object>>`
`queryResources(@NotNull String query, 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.
`@NotNull Resource`
`resolve(@NotNull jakarta.servlet.http.HttpServletRequest request, @NotNull String absPath)`
Resolves the resource from the given `absPath` optionally taking `HttpServletRequest` into account, such as the value of the `Host` request header.
`@NotNull Resource`
`resolve(@NotNull String absPath)`
Resolves the resource from the given absolute path.
`@NotNull Resource`
`resolve(javax.servlet.http.HttpServletRequest request)`
Deprecated.
as of 2.0.4, use `resolve(HttpServletRequest, String)` instead.
`@NotNull Resource`
`resolve(javax.servlet.http.HttpServletRequest request, @NotNull String absPath)`
Deprecated.
Use `resolve(HttpServletRequest, String)` instead.
`void`
`revert()`
Revert all pending changes.

### Methods inherited from interface org.apache.sling.api.adapter.Adaptable

`adaptTo`

## Field Details

### REQUEST_ATTR_WORKSPACE_INFO

@Deprecated static final String REQUEST_ATTR_WORKSPACE_INFO
Deprecated.
A request attribute containing the workspace to use for `resolve(javax.servlet.http.HttpServletRequest)` and `resolve(javax.servlet.http.HttpServletRequest, String)` if not the default workspace should be used to resolve the resource.

Since:
  2.1 (Sling API Bundle 2.1.0)

### USER_IMPERSONATOR

static final String USER_IMPERSONATOR
The name of the resource resolver attribute which is set if the resource resolver has been impersonated as per the `ResourceResolverFactory.USER_IMPERSONATION` property. The value of this attribute is the name of the primary user provided to the resource resolver factory method.

Since:
  2.1 (Sling API Bundle 2.1.0)
See Also:
  - Constant Field Values

### PROPERTY_RESOURCE_TYPE

static final String PROPERTY_RESOURCE_TYPE
This is the property to be used for setting the resource type of a resource during either creation (`create(Resource, String, Map)`) or modifying (`ModifiableValueMap`). This property is usually also exposed via `Resource.getValueMap()`.

Since:
  2.3 (Sling API Bundle 2.4.0)
See Also:
  - Constant Field Values

### PROPERTY_RESOURCE_SUPER_TYPE

static final String PROPERTY_RESOURCE_SUPER_TYPE
This is property to be used for setting the resource super type of a resource during either creation (`create(Resource, String, Map)`) or modifying (`ModifiableValueMap`). This property is usually also exposed via `Resource.getValueMap()`.

Since:
  2.15.0 (Sling API Bundle 3.0.0)
See Also:
  - Constant Field Values

## Method Details

### resolve

@NotNull @NotNull Resource resolve(@NotNull @NotNull jakarta.servlet.http.HttpServletRequest request, @NotNull @NotNull String absPath)
Resolves the resource from the given `absPath` optionally taking `HttpServletRequest` into account, such as the value of the `Host` request header. Returns a `NonExistingResource` if the path cannot be resolved to an existing and accessible resource.

The difference between this method and the `resolve(String)` method is, that this method may take request properties like the scheme, the host header or request parameters into account to resolve the resource.

Parameters:
  `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.
Returns:
  The `Resource` addressed by the `absPath` or a `NonExistingResource` if no such resource can be resolved.
Throws:
  `SlingException` - Or a subclass thereof may be thrown if an error occurs trying to resolve the resource.
  `IllegalStateException` - if this resource resolver has already been `closed`.
Since:
  2.14.0
See Also:
  - Mappings for Resource Resolution

### resolve

@Deprecated @NotNull @NotNull Resource resolve(@NotNull javax.servlet.http.HttpServletRequest request, @NotNull @NotNull String absPath)
Deprecated.
Use `resolve(HttpServletRequest, String)` instead.
Resolves the resource from the given `absPath` optionally taking `HttpServletRequest` into account, such as the value of the `Host` request header. Returns a `NonExistingResource` if the path cannot be resolved to an existing and accessible resource.

The difference between this method and the `resolve(String)` method is, that this method may take request properties like the scheme, the host header or request parameters into account to resolve the resource.

Parameters:
  `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.
Returns:
  The `Resource` addressed by the `absPath` or a `NonExistingResource` if no such resource can be resolved.
Throws:
  `SlingException` - Or a subclass thereof may be thrown if an error occurs trying to resolve the resource.
  `IllegalStateException` - if this resource resolver has already been `closed`.
Since:
  2.0.4 (Sling API Bundle 2.0.4)
See Also:
  - Mappings for Resource Resolution

### resolve

@NotNull @NotNull Resource resolve(@NotNull @NotNull String absPath)
Resolves the resource from the given absolute path. Returns a `NonExistingResource` if the path cannot be resolved to an existing and accessible resource.

This method is intended to apply the same algorithm to the absolute path as is used by the `resolve(HttpServletRequest, String)` method except for cases where the latter uses request property such as request headers or request parameters to resolve a resource.

It is ok for the implementation of this method to just call the `resolve(HttpServletRequest, String)` method with `null` as the request argument.

Parameters:
  `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.
Returns:
  The `Resource` addressed by the `absPath` or a `NonExistingResource` if no such resource can be resolved.
Throws:
  `SlingException` - Or a subclass thereof may be thrown if an error occurs trying to resolve the resource.
  `IllegalStateException` - if this resource resolver has already been `closed`.
See Also:
  - Mappings for Resource Resolution

### resolve

@Deprecated @NotNull @NotNull Resource resolve(@NotNull javax.servlet.http.HttpServletRequest request)
Deprecated.
as of 2.0.4, use `resolve(HttpServletRequest, String)` instead.
Resolves the resource from the given `HttpServletRequest`. Returns a `NonExistingResource` if the path cannot be resolved to an existing and accessible resource.

This method is deprecated as of API version 2.0.4 and should not be used anymore. Implementations are expected to implement this method calling the `resolve(HttpServletRequest, String)` where the `absPath` argument is the result of calling the `getPathInfo()` on the `request` object.

Parameters:
  `request` - The http servlet request object used to resolve the resource for. This must not be `null`.
Returns:
  The `Resource` addressed by `HttpServletRequest.getPathInfo()` or a `NonExistingResource` if no such resource can be resolved.
Throws:
  `NullPointerException` - If `request` is `null` .
  `SlingException` - Or a subclass thereof may be thrown if an error occurs trying to resolve the resource.
  `IllegalStateException` - if this resource resolver has already been `closed`.
See Also:
  - Mappings for Resource Resolution

### map

@NotNull @NotNull String map(@NotNull @NotNull String resourcePath)
Returns a (request) path mapped from the (resource) path applying the reverse mapping used by the `resolve(String)` such that when the path is given to the `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 `resolve(String)` with the path returned may return `null`.

This method is intended as the reverse operation of the `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 `resolve(String)`.

Parameters:
  `resourcePath` - The path for which to return a mapped path.
Returns:
  The mapped path or `resourcePath` in case no mapping is found.
Throws:
  `IllegalStateException` - if this resource resolver has already been `closed`.
See Also:
  - `ResourceMapper.getMapping(String, HttpServletRequest)`
  - Percent-Encoding
  - Mappings for Resource Resolution

### map

@NotNull @NotNull String map(@NotNull @NotNull jakarta.servlet.http.HttpServletRequest request, @NotNull @NotNull String resourcePath)
Returns an URL mapped from the (resource) path applying the reverse mapping used by the `resolve(HttpServletRequest, String)` such that when the path is given to the `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 `resolve(HttpServletRequest, String)` with the path returned may return `null`.

This method is intended as the reverse operation of the `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 `resolve(String)`.

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 `resourcePath` in case no mapping is found.
Throws:
  `IllegalStateException` - if this resource resolver has already been `closed`.
Since:
  2.14.0 (Sling API Bundle 2.0.4)
See Also:
  - `ResourceMapper.getMapping(String, HttpServletRequest)`
  - Percent-Encoding
  - Mappings for Resource Resolution

### map

@Deprecated @NotNull @NotNull String map(@NotNull javax.servlet.http.HttpServletRequest request, @NotNull @NotNull String resourcePath)
Deprecated.
Use `map(HttpServletRequest, String)` instead.
Returns an URL mapped from the (resource) path applying the reverse mapping used by the `resolve(HttpServletRequest, String)` such that when the path is given to the `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 `resolve(HttpServletRequest, String)` with the path returned may return `null`.

This method is intended as the reverse operation of the `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 `resolve(String)`.

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 `resourcePath` in case no mapping is found.
Throws:
  `IllegalStateException` - if this resource resolver has already been `closed`.
Since:
  2.0.4 (Sling API Bundle 2.0.4)
See Also:
  - `ResourceMapper.getMapping(String, HttpServletRequest)`
  - Percent-Encoding
  - Mappings for Resource Resolution

### getResource

@Nullable @Nullable Resource getResource(@NotNull @NotNull String path)
Returns a `Resource` object for data located at the given path.

This specification does not define the location for resources or the semantics for resource paths. For an implementation reading content from a Java Content Repository, the path could be a `javax.jcr.Item` path from which the resource object is loaded. In contrast to the `resolve(String)` method, this method does not apply any logic to the path, so the path is used as-is to fetch the content.

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:
  The `Resource` object loaded from the path or `null` if the path does not resolve to a resource.
Throws:
  `SlingException` - If an error occurs trying to load the resource object from the path.
  `IllegalStateException` - if this resource resolver has already been `closed`.

### getResource

@Nullable @Nullable Resource getResource(Resource base, @NotNull @NotNull String path)
Returns a `Resource` object for data located at the given path.

This specification does not define the location for resources or the semantics for resource paths. For an implementation reading content from a Java Content Repository, the path could be a `javax.jcr.Item` path from which the resource object is loaded.

Parameters:
  `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.
Returns:
  The `Resource` object loaded from the path or `null` if the path does not resolve to a resource.
Throws:
  `SlingException` - If an error occurs trying to load the resource object from the path or if `base` is `null` and `path` is relative.
  `IllegalStateException` - if this resource resolver has already been `closed`.

### getSearchPath

@NotNull @NotNull String[] getSearchPath()
Returns the search path used by the `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.

Returns:
  The array of search paths
Throws:
  `IllegalStateException` - if this resource resolver has already been `closed`.

### listChildren

@NotNull @NotNull Iterator<Resource> listChildren(@NotNull @NotNull Resource parent)
Returns an `Iterator` of `Resource` objects loaded from the children of the given `Resource`.

This specification does not define what the term "child" means. This is left to the implementation to define. For example an implementation reading content from a Java Content Repository, the children could be the `Resource` objects loaded from child items of the `Item` of the given `Resource`.

Parameters:
  `parent` - The `Resource` whose children are requested.
Returns:
  An `Iterator` of `Resource` objects.
Throws:
  `NullPointerException` - If `parent` is `null`.
  `SlingException` - If any error occurs acquiring the child resource iterator.
  `IllegalStateException` - if this resource resolver has already been `closed`.

### getParent

@Nullable @Nullable Resource getParent(@NotNull @NotNull Resource child)
Returns the parent resource of this resource.

This method is implemented by getting the parent resource path first calling the `ResourceUtil.getParent(String)` method and then to retrieve that resource.

Parameters:
  `child` - The `Resource` whose parent is requested.
Returns:
  The parent resource or `null`.
Throws:
  `NullPointerException` - If `child` is `null`.
  `SlingException` - If any error occurs acquiring the parent resource.
  `IllegalStateException` - if this resource resolver has already been `closed`.
Since:
  2.9 (Sling API Bundle 2.11.0)

### getChildren

@NotNull @NotNull Iterable<Resource> getChildren(@NotNull @NotNull Resource parent)
Returns an `Iterable` of `Resource` objects loaded from the children of the given `Resource`.

This specification does not define what the term "child" means. This is left to the implementation to define. For example an implementation reading content from a Java Content Repository, the children could be the `Resource` objects loaded from child items of the `Item` of the given `Resource`.

Parameters:
  `parent` - The `Resource` whose children are requested.
Returns:
  An `Iterable` of `Resource` objects.
Throws:
  `NullPointerException` - If `parent` is `null`.
  `SlingException` - If any error occurs acquiring the child resource iterator.
  `IllegalStateException` - if this resource resolver has already been `closed`.
Since:
  2.2 (Sling API Bundle 2.2.0)

### findResources

@NotNull @NotNull Iterator<Resource> findResources(@NotNull @NotNull String query, String language)
Searches for resources 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 `Query` through the `QueryManager`. The result returned is then based on the `NodeIterator` provided by the query result.

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 `Iterator` of `Resource` objects matching the query.
Throws:
  `QuerySyntaxException` - If the query is not syntactically correct according to the query language indicator.
  `SlingException` - If an error occurs querying for the resources.
  `IllegalStateException` - if this resource resolver has already been `closed`.

### queryResources

@NotNull @NotNull Iterator<Map<String,Object>> queryResources(@NotNull @NotNull String query, String language)
Queries 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 `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.

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 `Iterator` of `Map` instances providing access to the query result.
Throws:
  `QuerySyntaxException` - If the query is not syntactically correct according to the query language indicator.
  `SlingException` - If an error occurs querying for the resources.
  `IllegalStateException` - if this resource resolver has already been `closed`.

### hasChildren

boolean hasChildren(@NotNull @NotNull Resource resource)
Checks if the specified resource has any direct child resources.

Parameters:
  `resource` - the resource to check for direct children
Returns:
  `true` if the resource has any child resources
Throws:
  `IllegalStateException` - if this resource resolver has already been `closed`.
Since:
  2.4.4 (Sling API Bundle 2.5.0)

### clone

@NotNull @NotNull ResourceResolver clone(Map<String,Object> authenticationInfo) throws LoginException
Returns a new `ResourceResolver` instance based on the given `authenticationInfo` map and the original authentication info used to create this instance.

The new resource resolver is created according to the following algorithm:

     Map<String, Object> newAuthenticationInfo = new HashMap(
         authenticationInfoOfThisInstance);
     newAuthenticationInfo.addAll(authenticationInfo);
     return resourceResolverFactory.getResourceResolver(newAuthenticationInfo);

Parameters:
  `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.
Returns:
  A new `ResourceResolver`
Throws:
  `LoginException` - If an error occurs creating the new `ResourceResolver` with the provided credential data.
  `IllegalStateException` - if this resource resolver has already been `closed`.
Since:
  2.1 (Sling API Bundle 2.1.0)

### isLive

boolean isLive()
Returns `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`.

Returns:
  `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`.
Since:
  2.1 (Sling API Bundle 2.1.0)

### close

void close()
Close 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 the `ResourceResolverFactory` which 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 by `getPropertyMap()` implementing the `Closeable` interface, will be closed by calling `Closeable#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:
  `close` in interface `AutoCloseable`
Specified by:
  `close` in interface `Closeable`
Since:
  2.1 (Sling API Bundle 2.1.0)
See Also:
  - `Resource Resolver (section lifecycle)`
  - `getPropertyMap()`

### getUserID

@Nullable @Nullable String getUserID()
Get 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.

Returns:
  the user ID
Throws:
  `IllegalStateException` - if this resource resolver has already been `closed`.
Since:
  2.1 (Sling API Bundle 2.1.0)

### getAttributeNames

@NotNull @NotNull Iterator<String> getAttributeNames()
Returns an iterator of attribute names whose value can be retrieved calling the `getAttribute(String)` method. This iterator will not include any attributes which are not accessible.

Returns:
  An iterator of attribute names
Throws:
  `IllegalStateException` - if this resource resolver has already been `closed`.

### getAttribute

@Nullable @Nullable Object getAttribute(@NotNull @NotNull 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).

Parameters:
  `name` - The name of the attribute to access
Returns:
  The value of the attribute or `null` if the attribute is not set or not accessible.
Throws:
  `NullPointerException` - if `name` is `null`.
  `IllegalStateException` - if this resource resolver has already been `closed`.

### delete

void delete(@NotNull @NotNull Resource resource) throws PersistenceException
Delete the resource Deleting a non existing resource leads to no operation nor exception. The changes are transient and require a call to `commit()` for persisting.

Parameters:
  `resource` - The resource to delete
Throws:
  `NullPointerException` - if the resource parameter is null
  `UnsupportedOperationException` - If the resource provider does not allow to delete this resource.
  `PersistenceException` - If the operation fails.
  `IllegalStateException` - if this resource resolver has already been `closed`.
Since:
  2.2 (Sling API Bundle 2.2.0)

### create

@NotNull @NotNull Resource create(@NotNull @NotNull Resource parent, @NotNull @NotNull String name, Map<String,Object> properties) throws PersistenceException
Add a child resource to the given parent resource. The changes are transient and require a call to `commit()` for persisting. The mandatory resource type is either determined by the property "sling:resourceType" or set by the underlying resource provider to some value. The optional resource super type is determined by the property "sling:resourceSuperType".

Parameters:
  `parent` - The parent resource
  `name` - The name of the child resource - this is a plain name, not a path! The name must neither contain a slash nor consist out of dots only. The underlying resource provider may impose further restrictions on the name.
  `properties` - Optional properties for the resource (may be `null`).
Returns:
  The new resource
Throws:
  `NullPointerException` - if the resource parameter or name parameter is null
  `IllegalArgumentException` - if the name contains a slash or consists out of dots only.
  `UnsupportedOperationException` - If the underlying resource provider does not support write operations.
  `PersistenceException` - If the operation fails in the underlying resource provider, e.g. in case a resource of that name does already exist.
  `IllegalStateException` - if this resource resolver has already been `closed`.
Since:
  2.2 (Sling API Bundle 2.2.0)
See Also:
  - `ResourceUtil.escapeName(String)`

### orderBefore

boolean orderBefore(@NotNull @NotNull Resource parent, @NotNull @NotNull String name, @Nullable @Nullable String followingSiblingName) throws UnsupportedOperationException, PersistenceException, IllegalArgumentException
Orders the child resources returned by `getChildren(Resource)` and `listChildren(Resource)` so that a given resource is listed before the given sibling resource. The changes are transient and require a call to `commit()` for persisting.

Parameters:
  `parent` - the parent resource containing the child resources to order.
  `name` - the name of the child resource in `parent` to order. Must be an existing child name.
  `followingSiblingName` - the name of the resource child in `parent` which should come after the reordered resource. If `null` is given the resource is ordered as last among all sibling resources.
Returns:
  `true` in case the order of the child resources in `parent` has been changed, `false` if 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 of `parent` are provided by different providers.
  `IllegalArgumentException` - if either `name` or `followingSiblingName` are not existing child resource names of `parent`.
  `PersistenceException` - If the operation fails in the underlying resource provider, e.g. in case the parent resource does not support orderable children.
  `IllegalStateException` - if this resource resolver has already been `closed`.
Since:
  2.13.0 (Sling API Bundle 2.24.0)
See Also:
  - `listChildren(Resource)`
  - `getChildren(Resource)`

### revert

void revert()
Revert all pending changes.

Throws:
  `IllegalStateException` - if this resource resolver has already been `closed`.
Since:
  2.2 (Sling API Bundle 2.2.0)

### commit

void commit() throws PersistenceException
Persist all pending changes.

Throws:
  `PersistenceException` - If persisting the changes fails.
  `IllegalStateException` - if this resource resolver has already been `closed`.
Since:
  2.2 (Sling API Bundle 2.2.0)

### hasChanges

boolean hasChanges()
Are there any pending changes?

Returns:
  `true` if there are pending changes.
Throws:
  `IllegalStateException` - if this resource resolver has already been `closed`.
Since:
  2.2 (Sling API Bundle 2.2.0)

### getParentResourceType

@Nullable @Nullable String getParentResourceType(Resource resource)
Returns the super type of the given resource. This method checks first if the resource itself knows its super type by calling `Resource.getResourceSuperType()`. If that returns `null` `getParentResourceType(String)` is invoked with the resource type of the resource.

Parameters:
  `resource` - The resource to return the resource super type for.
Returns:
  The resource super type or `null`. This method also returns `null` if the provided resource is `null`
Throws:
  `IllegalStateException` - if this resource resolver has already been `closed`.
Since:
  2.3 (Sling API Bundle 2.4.0)

### getParentResourceType

@Nullable @Nullable String getParentResourceType(String resourceType)
Returns 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, the `Resource.getResourceSuperType()` method is called.

Parameters:
  `resourceType` - The resource type whose super type is to be returned.
Returns:
  the super type of the `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.
Throws:
  `IllegalStateException` - if this resource resolver has already been `closed`.
Since:
  2.3 (Sling API Bundle 2.4.0)

### isResourceType

boolean isResourceType(Resource resource, String resourceType)
Returns `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.

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` or `resourceType` are `null`.
Throws:
  `IllegalStateException` - if this resource resolver has already been `closed`.
Since:
  2.3 (Sling API Bundle 2.4.0)

### refresh

void refresh()
The resolver is updated to reflect the latest state. Resources which have changes pending are not discarded.

Throws:
  `IllegalStateException` - if this resource resolver has already been `closed`.
Since:
  2.3 (Sling API Bundle 2.4.0)

### copy

Resource copy(String srcAbsPath, String destAbsPath) throws PersistenceException
This method copies the subgraph rooted at, and including, the resource at `srcAbsPath` to the new location at `destAbsPath` and adds it as a child node of the resource at `destAbsPath`. If the copy operation is within a single resource provider, the resource provider can use an optimized copy operation. Otherwise the resource resolver copies resources from one provider to another. The resource at `destAbsPath` needs to exist, if not a `PersistenceException` is thrown. If a child resource with the same name already exists at `destAbsPath` a `PersistenceException` is thrown. If the resource at `srcAbsPath` does not exist, a `PersistenceException` is thrown. The changes are transient and require a call to `commit()` for persisting.

Parameters:
  `srcAbsPath` - the path of the resource to be copied.
  `destAbsPath` - the location to which the resource at `srcAbsPath` is to be copied.
Returns:
  The destination resource.
Throws:
  `PersistenceException` - If an error occurs.
  `UnsupportedOperationException` - If one of the destination resource providers does not allow to create a resource at that location.
  `IllegalStateException` - if this resource resolver has already been `closed`.
Since:
  2.9 (Sling API Bundle 2.11.0)

### move

Resource move(String srcAbsPath, String destAbsPath) throws PersistenceException
This method moves the subgraph rooted at, and including, the resource at `srcAbsPath` to the new location at `destAbsPath` and adds it as a child node of the resource at `destAbsPath`. If the move operation is within a single resource provider, the resource provider can use an optimized move operation. Otherwise the resource resolver moves resources from one provider to another. The resource at `destAbsPath` needs to exist, if not a `PersistenceException` is thrown. If a child resource with the same name already exists at `destAbsPath` a `PersistenceException` is thrown. If the resource at `srcAbsPath` does not exist, a `PersistenceException` is thrown. The changes are transient and require a call to `commit()` for persisting.

Parameters:
  `srcAbsPath` - the path of the resource to be copied.
  `destAbsPath` - the location to which the resource at `srcAbsPath` is to be moved.
Returns:
  The destination resource.
Throws:
  `PersistenceException` - If an error occurs.
  `UnsupportedOperationException` - If one of the destination resource providers does not allow to create a resource at that location.
  `IllegalStateException` - if this resource resolver has already been `closed`.
Since:
  2.9 (Sling API Bundle 2.11.0)

### getPropertyMap

@NotNull @NotNull Map<String,Object> getPropertyMap()
Returns 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 during `close()`, so afterwards the map is empty. If a stored value implements the `Closeable` interface, the ResourceResolver will invoke the `close` method} 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.

Returns:
  the property map
Since:
  2.13.0 (Sling API Bundle 2.24.0)
See Also:
  - `close()`