Top Description Fields Constructors Methods
org.springframework.web.servlet.resource

public abstract Class ResourceTransformerSupport

extends Object
implements ResourceTransformer
Class Inheritance
All Implemented Interfaces
org.springframework.web.servlet.resource.ResourceTransformer
Known Direct Subclasses
org.springframework.web.servlet.resource.CssLinkResourceTransformer
Imports
java.util.Collections, jakarta.servlet.http.HttpServletRequest, org.springframework.core.io.Resource, org.springframework.lang.Nullable, org.springframework.util.Assert, .StringUtils

A base class for a ResourceTransformer with an optional helper method for resolving public links within a transformed resource.
Authors
Brian Clozel, Rossen Stoyanchev, Juergen Hoeller
Since
4.1

Field Summary

Modifier and TypeField and Description
private ResourceUrlProvider

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
private ResourceUrlProvider
public ResourceUrlProvider
getResourceUrlProvider()

Return the configured ResourceUrlProvider.

protected String

Returns:

the resolved URL, or if not resolvable
resolveUrlPath
(String
the path to a resource that needs to be re-written
resourcePath
,
HttpServletRequest
the current request
request
,
Resource
the resource being transformed
resource
,
ResourceTransformerChain
the transformer chain
transformerChain
)

A transformer can use this method when a resource being transformed contains links to other resources.

public void
setResourceUrlProvider(ResourceUrlProvider resourceUrlProvider)

Configure a ResourceUrlProvider to use when resolving the public URL of links in a transformed resource (e.g. import links in a CSS file).

protected String

Returns:

the absolute request path for the given resource path
toAbsolutePath
(String
the relative path to transform
path
,
HttpServletRequest
the referer request
request
)

Transform the given relative request path to an absolute path, taking the path of the given request as a point of reference.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

resourceUrlProviderback to summary
private ResourceUrlProvider resourceUrlProvider
Annotations
@Nullable

Constructor Detail

ResourceTransformerSupportback to summary
public ResourceTransformerSupport()

Method Detail

findResourceUrlProviderback to summary
private ResourceUrlProvider findResourceUrlProvider(HttpServletRequest request)
Annotations
@Nullable
getResourceUrlProviderback to summary
public ResourceUrlProvider getResourceUrlProvider()

Return the configured ResourceUrlProvider.

Annotations
@Nullable
resolveUrlPathback to summary
protected String resolveUrlPath(String resourcePath, HttpServletRequest request, 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 (e.g. the public URL may have a version inserted).

Parameters
resourcePath:String

the path to a resource that needs to be re-written

request:HttpServletRequest

the current request

resource:Resource

the resource being transformed

transformerChain:ResourceTransformerChain

the transformer chain

Returns:String

the resolved URL, or if not resolvable

Annotations
@Nullable
setResourceUrlProviderback to summary
public void setResourceUrlProvider(ResourceUrlProvider resourceUrlProvider)

Configure a ResourceUrlProvider to use when resolving the public URL of links in a transformed resource (e.g. import links in a CSS file). This is required only for links expressed as full paths and not for relative links.

toAbsolutePathback to summary
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:String

the relative path to transform

request:HttpServletRequest

the referer request

Returns:String

the absolute request path for the given resource path