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

java.lang.Object
  extended by ro.isdc.wro.model.resource.processor.impl.css.AbstractCssUrlRewritingProcessor
      extended by ro.isdc.wro.model.resource.processor.impl.css.CssDataUriPreProcessor
All Implemented Interfaces:
ResourcePostProcessor, ResourcePreProcessor
Direct Known Subclasses:
DuplicatesAwareCssDataUriPreProcessor

public class CssDataUriPreProcessor
extends AbstractCssUrlRewritingProcessor

Rewrites background images by replacing the url with data uri of the image. If the replacement is not successful, it is left unchanged.

For more details, @see http://en.wikipedia.org/wiki/Data_URI_scheme

Author:
Alex Objelean

Field Summary
static String ALIAS
           
 
Fields inherited from class ro.isdc.wro.model.resource.processor.impl.css.AbstractCssUrlRewritingProcessor
PATTERN
 
Constructor Summary
CssDataUriPreProcessor()
           
 
Method Summary
protected  boolean isReplaceNeeded(String url)
          Check if url must be replaced or not.
protected  String replaceImageUrl(String cssUri, String imageUrl)
          Replace provided url with the new url if needed.
protected  boolean replaceWithDataUri(String dataUri)
          Decides whether the computed dataUri should replace the image url.
 
Methods inherited from class ro.isdc.wro.model.resource.processor.impl.css.AbstractCssUrlRewritingProcessor
cleanImageUrl, onProcessCompleted, onUrlReplaced, 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
Constructor Detail

CssDataUriPreProcessor

public CssDataUriPreProcessor()
Method Detail

replaceImageUrl

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

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

replaceWithDataUri

protected boolean replaceWithDataUri(String dataUri)
                              throws UnsupportedEncodingException
Decides whether the computed dataUri should replace the image url. It is useful when you want to limit the dataUri size. By default the size of dataUri is limited to 32KB (because IE8 has a 32KB limitation).

Parameters:
dataUri - base64 encoded stream.
Returns:
true if dataUri should replace original image url.
Throws:
UnsupportedEncodingException

isReplaceNeeded

protected boolean isReplaceNeeded(String url)
Check if url must be replaced or not.

Overrides:
isReplaceNeeded in class AbstractCssUrlRewritingProcessor
Parameters:
url - to check.
Returns:
true if url needs to be replaced or remain unchanged.


Copyright © 2008-2011. All Rights Reserved.