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

java.lang.Object
  extended by ro.isdc.wro.model.resource.processor.impl.css.AbstractCssImportPreProcessor
All Implemented Interfaces:
ImportAware, ResourcePreProcessor
Direct Known Subclasses:
CssImportPreProcessor

@SupportedResourceType(value=CSS)
public abstract class AbstractCssImportPreProcessor
extends Object
implements ResourcePreProcessor, ImportAware

CssImport Processor responsible for handling css @import statement. It is implemented as both: preProcessor & postProcessor. It is necessary because preProcessor is responsible for updating model with found imported resources, while post processor removes import occurrences.

When processor finds an import which is not valid, it will check the WroConfiguration.isIgnoreMissingResources() flag. If it is set to false, the processor will fail.

Author:
Alex Objelean

Constructor Summary
AbstractCssImportPreProcessor()
           
 
Method Summary
protected abstract  String doTransform(String cssContent, List<Resource> importedResources)
          Perform actual transformation of provided cssContent and the list of found import resources.
protected  List<String> findImports(String css)
          Extracts a list of imports from css content.
 boolean isImportAware()
          
protected  void onImportDetected(String foundImportUri)
          Invoked when an import is detected.
protected  void onRecursiveImportDetected()
          Invoked when a recursive import is detected.
 void process(Resource resource, Reader reader, Writer writer)
          Process a content supplied by a reader and perform some sort of processing.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractCssImportPreProcessor

public AbstractCssImportPreProcessor()
Method Detail

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.
It is not require to explicitly handle exception. When the processing fails, the following can happen:
It is not required to close the reader and writers, because these will be closed for you.

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 an exception occurs. The future version will change the exception type to Exception, because any exception may occur during processing. The processing failure will be handled based on value of WroConfiguration.isIgnoreFailingProcessor() configuration flag.

findImports

protected List<String> findImports(String css)
Extracts a list of imports from css content.

Returns:
a list of found imports.

doTransform

protected abstract String doTransform(String cssContent,
                                      List<Resource> importedResources)
                               throws IOException
Perform actual transformation of provided cssContent and the list of found import resources.

Parameters:
cssContent - the css to transform.
importedResources - the list of found imports.
Throws:
IOException

onImportDetected

protected void onImportDetected(String foundImportUri)
Invoked when an import is detected. By default this method does nothing.

Parameters:
foundImportUri - the uri of the detected imported resource

onRecursiveImportDetected

protected void onRecursiveImportDetected()
Invoked when a recursive import is detected. Used to assert the recursive import detection correct behavior. By default this method does nothing.


isImportAware

public boolean isImportAware()

Specified by:
isImportAware in interface ImportAware
Returns:
flag indicating if the implementor of this interface should process also imported (referred by @import directive) resources.


Copyright © 2008-2013. All Rights Reserved.