Package org.apache.sling.api.resource.mapping

# Interface ResourceMapper

@ProviderType public interface ResourceMapper
Allows access to resource mappings

This interface superceeds the resource mapping functionality present in the `ResourceResolver`. Although the methods present in that interface will continue to work, the resource mapper will provide better APIs to access the resource mappings.

Implementations of this class are obtained by adapting a `ResourceResolver` instance. As such, the mappings returned by its methods reflect the repository permissions of the underyling resolver instance.

## Method Summary

Modifier and Type
Method
Description
`Collection<String>`
`getAllMappings(@NotNull String resourcePath)`
Returns all possible mappings for a given `resourcePath` as paths.
`Collection<String>`
`getAllMappings(@NotNull String resourcePath, @NotNull jakarta.servlet.http.HttpServletRequest request)`
Returns all possible mappings for a given `resourcePath` as URLs.
`Collection<String>`
`getAllMappings(@NotNull String resourcePath, javax.servlet.http.HttpServletRequest request)`
Deprecated.
Use `getAllMappings(String, HttpServletRequest)` instead.
`@NotNull String`
`getMapping(@NotNull 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.
`@NotNull String`
`getMapping(@NotNull String resourcePath, @NotNull jakarta.servlet.http.HttpServletRequest request)`
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.
`@NotNull String`
`getMapping(@NotNull String resourcePath, javax.servlet.http.HttpServletRequest request)`
Deprecated.
Use `getMapping(String, HttpServletRequest)` instead.

## Method Details

### getMapping

@NotNull @NotNull String getMapping(@NotNull @NotNull 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.

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.

Parameters:
  `resourcePath` - The path for which to return a mapped path.
Returns:
  The mapped path.
Throws:
  `IllegalStateException` - if the underlying resource resolver has already been `closed`.
Since:
  1.0.0 (Sling API Bundle 2.19.0)

### getMapping

@NotNull @NotNull String getMapping(@NotNull @NotNull String resourcePath, @NotNull @NotNull jakarta.servlet.http.HttpServletRequest request)
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.

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.

Parameters:
  `resourcePath` - The path for which to return a mapped path.
  `request` - The http servlet request object which may be used to apply more mapping functionality.
Returns:
  The mapped URL.
Throws:
  `IllegalStateException` - if the underlying resource resolver has already been `closed`.
Since:
  1.1.0

### getMapping

@Deprecated @NotNull @NotNull String getMapping(@NotNull @NotNull String resourcePath, @NotNull javax.servlet.http.HttpServletRequest request)
Deprecated.
Use `getMapping(String, HttpServletRequest)` instead.
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.

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.

Parameters:
  `resourcePath` - The path for which to return a mapped path.
  `request` - The http servlet request object which may be used to apply more mapping functionality.
Returns:
  The mapped URL.
Throws:
  `IllegalStateException` - if the underlying resource resolver has already been `closed`.
Since:
  1.0.0 (Sling API Bundle 2.19.0)

### getAllMappings

Collection<String> getAllMappings(@NotNull @NotNull String resourcePath)
Returns all possible mappings for a given `resourcePath` as paths.

This method differs from the `getMapping(String)` variant by guaranteeing that all possible mappings are returned for a specified path.

The mappings are not returned in any particular order.

Parameters:
  `resourcePath` - The path for which to return a mapped path.
Returns:
  a collection of mapped URLs, in no particular order. May not be null or empty.
Throws:
  `IllegalStateException` - if the underlying resource resolver has already been `closed`.
Since:
  1.0.0 (Sling API Bundle 2.19.0)

### getAllMappings

Collection<String> getAllMappings(@NotNull @NotNull String resourcePath, @NotNull @NotNull jakarta.servlet.http.HttpServletRequest request)
Returns all possible mappings for a given `resourcePath` as URLs.

This method differs from the `getMapping(String, HttpServletRequest)` variant by guaranteeing that all possible mappings are returned for a specified path.

The mappings are not returned in any particular order.

Parameters:
  `resourcePath` - The path for which to return a mapped path.
  `request` - The http servlet request object which may be used to apply more mapping functionality.
Returns:
  a collection of mapped URLs, in no particular order. May not be null or empty.
Throws:
  `IllegalStateException` - if the underlying resource resolver has already been `closed`.
Since:
  1.1.0

### getAllMappings

@Deprecated Collection<String> getAllMappings(@NotNull @NotNull String resourcePath, @NotNull javax.servlet.http.HttpServletRequest request)
Deprecated.
Use `getAllMappings(String, HttpServletRequest)` instead.
Returns all possible mappings for a given `resourcePath` as URLs.

This method differs from the `getMapping(String, HttpServletRequest)` variant by guaranteeing that all possible mappings are returned for a specified path.

The mappings are not returned in any particular order.

Parameters:
  `resourcePath` - The path for which to return a mapped path.
  `request` - The http servlet request object which may be used to apply more mapping functionality.
Returns:
  a collection of mapped URLs, in no particular order. May not be null or empty.
Throws:
  `IllegalStateException` - if the underlying resource resolver has already been `closed`.
Since:
  1.0.0 (Sling API Bundle 2.19.0)