Package org.springframework.web.servlet.resource

# Class ResourceTransformerSupport

java.lang.Object
org.springframework.web.servlet.resource.ResourceTransformerSupport

All Implemented Interfaces:
  `ResourceTransformer`

Direct Known Subclasses:
  `CssLinkResourceTransformer`

public abstract class ResourceTransformerSupport extends Object implements ResourceTransformer
A base class for a `ResourceTransformer` with an optional helper method for resolving public links within a transformed resource.

Since:
  4.1
Author:
  Brian Clozel, Rossen Stoyanchev, Juergen Hoeller

## Constructor Summary

Constructors
Constructor
Description
`ResourceTransformerSupport()`

## Method Summary

Modifier and Type
Method
Description
`ResourceUrlProvider`
`getResourceUrlProvider()`
Return the configured `ResourceUrlProvider`.
`protected String`
`resolveUrlPath(String resourcePath, HttpServletRequest request, org.springframework.core.io.Resource resource, ResourceTransformerChain transformerChain)`
A transformer can use this method when a resource being transformed contains links to other resources.
`void`
`setResourceUrlProvider(ResourceUrlProvider resourceUrlProvider)`
Configure a `ResourceUrlProvider` to use when resolving the public URL of links in a transformed resource (for example, import links in a CSS file).
`protected String`
`toAbsolutePath(String path, HttpServletRequest request)`
Transform the given relative request path to an absolute path, taking the path of the given request as a point of reference.

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Methods inherited from interface org.springframework.web.servlet.resource.ResourceTransformer

`transform`

## Constructor Details

### ResourceTransformerSupport

public ResourceTransformerSupport()

## Method Details

### setResourceUrlProvider

public void setResourceUrlProvider(@Nullable ResourceUrlProvider resourceUrlProvider)
Configure a `ResourceUrlProvider` to use when resolving the public URL of links in a transformed resource (for example, import links in a CSS file). This is required only for links expressed as full paths and not for relative links.

### getResourceUrlProvider

@Nullable public ResourceUrlProvider getResourceUrlProvider()
Return the configured `ResourceUrlProvider`.

### resolveUrlPath

@Nullable protected String resolveUrlPath(String resourcePath, HttpServletRequest request, org.springframework.core.io.Resource resource, ResourceTransformerChain transformerChain)
A transformer can use this method when a resource being transformed contains links to other resources. Such links need to be replaced with the public facing link as determined by the resource resolver chain (for example, the public URL may have a version inserted).

Parameters:
  `resourcePath` - the path to a resource that needs to be re-written
  `request` - the current request
  `resource` - the resource being transformed
  `transformerChain` - the transformer chain
Returns:
  the resolved URL, or if not resolvable

### toAbsolutePath

protected String toAbsolutePath(String path, HttpServletRequest request)
Transform the given relative request path to an absolute path, taking the path of the given request as a point of reference. The resulting path is also cleaned from sequences like "path/..".

Parameters:
  `path` - the relative path to transform
  `request` - the referer request
Returns:
  the absolute request path for the given resource path