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:
ImportAware, ResourcePostProcessor, ResourcePreProcessor
Direct Known Subclasses:
DuplicatesAwareCssDataUriPreProcessor, FallbackCssDataUriProcessor

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.

Attention: This processor should be added before CssUrlRewritingProcessor, otherwise the url's won't be replaced. For more details, @see DataUri Scheme on Wikipedia

Author:
Alex Objelean

Field Summary
static String ALIAS
           
 
Constructor Summary
CssDataUriPreProcessor()
           
 
Method Summary
protected  DataUriGenerator getDataUriGenerator()
           
protected  boolean isReplaceAccepted(String dataUri)
          Similar to isReplaceAccepted(String), but decides whether the computed dataUri should replace the image url.
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)
          Deprecated. use isReplaceAccepted(String) instead.
 
Methods inherited from class ro.isdc.wro.model.resource.processor.impl.css.AbstractCssUrlRewritingProcessor
cleanImageUrl, getUrlPrefix, isImportAware, newCssUrlInspector, onProcessCompleted, onUrlReplaced, 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

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.

isReplaceAccepted

protected boolean isReplaceAccepted(String dataUri)
Similar to isReplaceAccepted(String), but 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.

replaceWithDataUri

@Deprecated
protected boolean replaceWithDataUri(String dataUri)
Deprecated. use isReplaceAccepted(String) instead.


isReplaceNeeded

protected boolean isReplaceNeeded(String url)
Check if url must be replaced or not. The replacement is not needed if the url of the image is absolute (can be resolved by urlResourceLocator) or if the url is a data uri (base64 encoded value).

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

getDataUriGenerator

protected DataUriGenerator getDataUriGenerator()
Returns:
the DataUriGenerator class responsible for transforming streams into base64 encoded strings.


Copyright © 2008-2013. All Rights Reserved.