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

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

@SupportedResourceType(value=CSS)
public abstract class AbstractCssUrlRewritingProcessor
extends Object
implements ResourcePreProcessor, ResourcePostProcessor

A processor responsible for rewriting url's from inside the css resources.

Author:
Alex Objelean

Field Summary
protected static Pattern PATTERN
          Compiled pattern.
 
Constructor Summary
AbstractCssUrlRewritingProcessor()
           
 
Method Summary
protected  String cleanImageUrl(String imageUrl)
          Cleans the image url by triming result and removing \' or \" characters if such exists.
protected  boolean isReplaceNeeded(String url)
          Check if url must be replaced or not.
protected  void onProcessCompleted()
          Invoked when the process operation is completed.
protected  void onUrlReplaced(String replacedUrl)
          Invoked when an url is replaced.
 void process(Reader reader, Writer writer)
          Perform actual resource processing.
 void process(Resource resource, Reader reader, Writer writer)
          Process a content supplied by a reader and perform some sort of processing.
protected abstract  String replaceImageUrl(String cssUri, String imageUrl)
          Replace provided url with the new url if needed.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PATTERN

protected static final Pattern PATTERN
Compiled pattern.

Constructor Detail

AbstractCssUrlRewritingProcessor

public AbstractCssUrlRewritingProcessor()
Method Detail

process

public void process(Reader reader,
                    Writer writer)
             throws IOException
Perform actual resource processing. The content to be processed is read from source Reader and is written to destination Writer. It is the client responsibility to close both: Reader and writer.

Specified by:
process in interface ResourcePostProcessor
Parameters:
reader - source stream.
writer - destination stream.
Throws:
IOException

process

public final void process(Resource resource,
                          Reader reader,
                          Writer writer)
                   throws IOException
Process a content supplied by a reader and perform some sort of processing. It is important to know that you should use reader for processing instead of trying to access the resource original content using Resource, because this way you can ignore the other preProcessors from the chain.

Specified by:
process in interface ResourcePreProcessor
Parameters:
resource - the original resource as it found in the model.
reader - Reader used to read processed resource content.
writer - Writer where used to write processed results.
Throws:
IOException - when IO exception occurs.

onProcessCompleted

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


onUrlReplaced

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

Parameters:
replacedUrl - the newly computed url created as a result of url rewriting.

replaceImageUrl

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

Parameters:
cssUri - Uri of the parsed css.
imageUrl - to replace.
Returns:
replaced url.

cleanImageUrl

protected final String cleanImageUrl(String imageUrl)
Cleans the image url by triming result and removing \' or \" characters if such exists.

Parameters:
imageUrl - to clean.
Returns:
cleaned image URL.

isReplaceNeeded

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

Parameters:
url - to check.
Returns:
true if url needs to be replaced or remain unchanged.


Copyright © 2008-2011. All Rights Reserved.