public class CssLinkResourceTransformer extends ResourceTransformerSupport
ResourceTransformer
implementation that modifies links in a CSS
file to match the public URL paths that should be exposed to clients (e.g.
with an MD5 content-based hash inserted in the URL).
The implementation looks for links in CSS @import
statements and
also inside CSS url()
functions. All links are then passed through the
ResourceResolverChain
and resolved relative to the location of the
containing CSS file. If successfully resolved, the link is modified, otherwise
the original link is preserved.
Modifier and Type | Class and Description |
---|---|
protected static class |
CssLinkResourceTransformer.AbstractLinkParser |
private static class |
CssLinkResourceTransformer.ContentChunkInfo |
private static class |
CssLinkResourceTransformer.ImportLinkParser |
protected static interface |
CssLinkResourceTransformer.LinkParser
Extract content chunks that represent links.
|
private static class |
CssLinkResourceTransformer.UrlFunctionLinkParser |
Modifier and Type | Field and Description |
---|---|
private static java.nio.charset.Charset |
DEFAULT_CHARSET |
private java.util.List<CssLinkResourceTransformer.LinkParser> |
linkParsers |
private static Log |
logger |
Constructor and Description |
---|
CssLinkResourceTransformer() |
Modifier and Type | Method and Description |
---|---|
private boolean |
hasScheme(java.lang.String link) |
private java.util.List<CssLinkResourceTransformer.ContentChunkInfo> |
parseContent(java.lang.String cssContent) |
<any> |
transform(ServerWebExchange exchange,
Resource inputResource,
ResourceTransformerChain transformerChain)
Transform the given resource.
|
private <any> |
transformContent(java.lang.String cssContent,
Resource resource,
ResourceTransformerChain chain,
ServerWebExchange exchange) |
getResourceUrlProvider, resolveUrlPath, setResourceUrlProvider, toAbsolutePath
private static final java.nio.charset.Charset DEFAULT_CHARSET
private static final Log logger
private final java.util.List<CssLinkResourceTransformer.LinkParser> linkParsers
public <any> transform(ServerWebExchange exchange, Resource inputResource, ResourceTransformerChain transformerChain)
ResourceTransformer
exchange
- the current exchangeinputResource
- the resource to transformtransformerChain
- the chain of remaining transformers to delegate toprivate <any> transformContent(java.lang.String cssContent, Resource resource, ResourceTransformerChain chain, ServerWebExchange exchange)
private java.util.List<CssLinkResourceTransformer.ContentChunkInfo> parseContent(java.lang.String cssContent)
private boolean hasScheme(java.lang.String link)