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:
ResourcePostProcessor, ResourcePreProcessor

public class CssUrlRewritingProcessor
extends AbstractCssUrlRewritingProcessor

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

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

Author:
Alex Objelean

Field Summary
static String ALIAS
           
static String PARAM_RESOURCE_ID
          The name of resource id parameter.
static String PATH_RESOURCES
          Resources mapping path.
 
Fields inherited from class ro.isdc.wro.model.resource.processor.impl.css.AbstractCssUrlRewritingProcessor
PATTERN
 
Constructor Summary
CssUrlRewritingProcessor()
           
 
Method Summary
protected  String getUrlPrefix()
          This method has protected modifier in order to be accessed by unit test class.
 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, isReplaceNeeded, process, process
 
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

PATH_RESOURCES

public static final String PATH_RESOURCES
Resources mapping path. If request uri contains this, the filter will dispatch it to the original resource.

See Also:
Constant Field Values

PARAM_RESOURCE_ID

public static final String PARAM_RESOURCE_ID
The name of resource id parameter.

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 will replacements.

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.

getUrlPrefix

protected String getUrlPrefix()
This method has protected modifier in order to be accessed by unit test class.

Returns:
urlPrefix value.


Copyright © 2008-2011. All Rights Reserved.