ro.isdc.wro.model.resource.processor.impl.css
Class CssUrlRewritingProcessor

java.lang.Object
  extended by ro.isdc.wro.model.resource.processor.impl.css.AbstractCssUrlRewritingProcessor
      extended by ro.isdc.wro.model.resource.processor.impl.css.CssUrlRewritingProcessor
All Implemented Interfaces:
ImportAware, ResourcePostProcessor, ResourcePreProcessor

public class CssUrlRewritingProcessor
extends AbstractCssUrlRewritingProcessor

Note: When used together with CssImportPreProcessor, the CssUrlRewritingProcessor should come first, otherwise it will produce wrong results.

Rewrites background images url of the provided css content. This implementation takes care of most common cases such as those described bellow:

Css resource URI Image URL Computed Image URL
ANY [URL]/1.jpg [URL]/1.jpg
/1.css /a/1.jpg /a/1.jpg
/1.jpg /1.jpg
1.jpg ../1.jpg
../1.jpg ../../1.jpg
/WEB-INF/1.css /a/1.jpg /a/1.jpg
/1.jpg /1.jpg
1.jpg [WRO-PREFIX]?id=/WEB-INF/1.jpg
../1.jpg [WRO-PREFIX]?id=/WEB-INF/../1.jpg
[X]/1.css

where [X] is URL or a classpath resource
where [WRO-PREFIX] is a servletContext prefix
which will map WRO filter to the result url.
/a/1.jpg [WRO-PREFIX]?id=[X]/a/1.jpg
/1.jpg [WRO-PREFIX]?id=[X]/1.jpg
1.jpg [WRO-PREFIX]?id=[X]/1.jpg
../1.jpg [WRO-PREFIX]?id=[X]/../1.jpg

The algorithm requires two types of UriLocator objects, one for resolving url resources & one for classpath resources. Both need to be injected using IoC when creating the instance of CssUrlRewritingProcessor class.

Author:
Alex Objelean

Field Summary
static String ALIAS
           
 
Constructor Summary
CssUrlRewritingProcessor()
           
 
Method Summary
 boolean isUriAllowed(String uri)
           
protected  void onProcessCompleted()
          Invoked when the process operation is completed.
protected  void onUrlReplaced(String replacedUrl)
          Invoked when an url is replaced.
protected  String replaceImageUrl(String cssUri, String imageUrl)
          Replace provided url with the new url if needed.
 
Methods inherited from class ro.isdc.wro.model.resource.processor.impl.css.AbstractCssUrlRewritingProcessor
cleanImageUrl, getUrlPrefix, isImportAware, isReplaceNeeded, newCssUrlInspector, process, process, replaceDeclaration
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ALIAS

public static final String ALIAS
See Also:
Constant Field Values
Constructor Detail

CssUrlRewritingProcessor

public CssUrlRewritingProcessor()
Method Detail

onProcessCompleted

protected void onProcessCompleted()
Invoked when the process operation is completed. Useful to invoke some post processing logic or for custom logging.

Overrides:
onProcessCompleted in class AbstractCssUrlRewritingProcessor

onUrlReplaced

protected void onUrlReplaced(String replacedUrl)
Invoked when an url is replaced. Useful if you need to do something with newly replaced url.

Overrides:
onUrlReplaced in class AbstractCssUrlRewritingProcessor
Parameters:
replacedUrl - the newly computed url created as a result of url rewriting.

replaceImageUrl

protected String replaceImageUrl(String cssUri,
                                 String imageUrl)
Replace provided url with the new url if needed.

Specified by:
replaceImageUrl in class AbstractCssUrlRewritingProcessor
Parameters:
cssUri - Uri of the parsed css.
imageUrl - to replace.
Returns:
replaced url.

isUriAllowed

public final boolean isUriAllowed(String uri)
Parameters:
uri - to check if is allowed.
Returns:
true if passed argument is contained in allowed list.


Copyright © 2008-2013. All Rights Reserved.