ro.isdc.wro.extensions.processor.js
Class GoogleClosureCompressorProcessor

java.lang.Object
  extended by ro.isdc.wro.extensions.processor.js.GoogleClosureCompressorProcessor
All Implemented Interfaces:
ResourcePostProcessor, ResourcePreProcessor

@Minimize
@SupportedResourceType(value=JS)
public class GoogleClosureCompressorProcessor
extends Object
implements ResourcePostProcessor, ResourcePreProcessor

Uses Google closure compiler for js minimization.

In order to make this class Context agnostic, set the encoding explicitly using setEncoding(String).

Author:
Alex Objelean
See Also:
http://blog.bolinfest.com/2009/11/calling-closure-compiler-from-java.html

Field Summary
static String ALIAS_ADVANCED
           
static String ALIAS_SIMPLE
           
static String ALIAS_WHITESPACE_ONLY
           
 
Constructor Summary
GoogleClosureCompressorProcessor()
          Uses google closure compiler with default compilation level: CompilationLevel.SIMPLE_OPTIMIZATIONS
GoogleClosureCompressorProcessor(com.google.javascript.jscomp.CompilationLevel compilationLevel)
          Uses google closure compiler with specified compilation level.
 
Method Summary
protected  com.google.javascript.jscomp.SourceFile[] getExterns(Resource resource)
           
protected  com.google.javascript.jscomp.CompilerOptions newCompilerOptions()
           
protected  void onException(Exception e)
          Invoked when an exception occurs during processing.
 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.
 GoogleClosureCompressorProcessor setCompilationLevel(com.google.javascript.jscomp.CompilationLevel compilationLevel)
           
 GoogleClosureCompressorProcessor setCompilerOptions(com.google.javascript.jscomp.CompilerOptions compilerOptions)
           
 GoogleClosureCompressorProcessor setEncoding(String encoding)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ALIAS_SIMPLE

public static final String ALIAS_SIMPLE
See Also:
Constant Field Values

ALIAS_ADVANCED

public static final String ALIAS_ADVANCED
See Also:
Constant Field Values

ALIAS_WHITESPACE_ONLY

public static final String ALIAS_WHITESPACE_ONLY
See Also:
Constant Field Values
Constructor Detail

GoogleClosureCompressorProcessor

public GoogleClosureCompressorProcessor()
Uses google closure compiler with default compilation level: CompilationLevel.SIMPLE_OPTIMIZATIONS


GoogleClosureCompressorProcessor

public GoogleClosureCompressorProcessor(com.google.javascript.jscomp.CompilationLevel compilationLevel)
Uses google closure compiler with specified compilation level.

Parameters:
compilationLevel - not null CompilationLevel enum.
Method Detail

process

public 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.

onException

protected void onException(Exception e)
Invoked when an exception occurs during processing. Default implementation wraps the exception into WroRuntimeException and throws it further.

Parameters:
e - Exception thrown during processing.

setEncoding

public GoogleClosureCompressorProcessor setEncoding(String encoding)
Parameters:
encoding - the encoding to set

getExterns

protected com.google.javascript.jscomp.SourceFile[] getExterns(Resource resource)
Parameters:
resource - Currently processed resource. The resource can be null, when the closure compiler is used as a post processor.
Returns:
An Array of externs files for the resource to process.

setCompilerOptions

public GoogleClosureCompressorProcessor setCompilerOptions(com.google.javascript.jscomp.CompilerOptions compilerOptions)
Parameters:
compilerOptions - the compilerOptions to set

setCompilationLevel

public GoogleClosureCompressorProcessor setCompilationLevel(com.google.javascript.jscomp.CompilationLevel compilationLevel)
Parameters:
compilationLevel - the compilationLevel to set

newCompilerOptions

protected com.google.javascript.jscomp.CompilerOptions newCompilerOptions()
Returns:
default CompilerOptions object to be used by compressor.

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


Copyright © 2008-2013. All Rights Reserved.