org.riotfamily.common.web.compressor
Class YUIJavaScriptCompressor

java.lang.Object
  extended by org.riotfamily.common.web.compressor.YUIJavaScriptCompressor
All Implemented Interfaces:
Compressor

public class YUIJavaScriptCompressor
extends Object
implements Compressor

Since:
6.5
Author:
Felix Gnass [fgnass at neteye dot de]

Constructor Summary
YUIJavaScriptCompressor()
           
 
Method Summary
 void compress(Reader in, Writer out)
          Reads JavaScript from the the given Reader and writes the compressed code to the specified Writer.
 void compress(Reader in, Writer out, org.mozilla.javascript.ErrorReporter errorReporter)
          Reads JavaScript from the the given Reader and writes the compressed code to the specified Writer.
 void compress(Reader in, Writer out, String fileName)
          Reads JavaScript from the the given Reader and writes the compressed code to the specified Writer.
protected  void compressInternal(Reader in, Writer out, org.mozilla.javascript.ErrorReporter errorReporter)
          Reads JavaScript from the the given Reader and writes the compressed code to the specified Writer.
 void setDefaultErrorReporter(org.mozilla.javascript.ErrorReporter defaultErrorReporter)
          Sets the ErrorReporter used by compress(Reader, Writer).
 void setEnabled(boolean enabled)
          Enables the Compressor.
 void setFailsafe(boolean failsafe)
          Sets whether the uncompressed script should be served in case a syntax error is encountered.
 void setLinebreak(int linebreak)
          Sets the column number after which a line break should be inserted.
 void setMergeStringLiterals(boolean mergeStringLiterals)
          Sets whether concatenated string literals should be merged.
 void setMunge(boolean munge)
          Sets whether the code should be obfuscated.
 void setPreserveAllSemiColons(boolean preserveAllSemiColons)
          Sets whether a semicolons should be preserved.
 void setWarn(boolean warn)
          Sets whether possible errors in the code should be displayed.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

YUIJavaScriptCompressor

public YUIJavaScriptCompressor()
Method Detail

setEnabled

public void setEnabled(boolean enabled)
Enables the Compressor. Per default the compressor is enabled.

Parameters:
enabled - true to enabled, false to disable this compressor

setLinebreak

public void setLinebreak(int linebreak)
Sets the column number after which a line break should be inserted. Default is -1, which means that no breaks will be added.


setMunge

public void setMunge(boolean munge)
Sets whether the code should be obfuscated. If set to false the script will only be minified. Default is true.


setWarn

public void setWarn(boolean warn)
Sets whether possible errors in the code should be displayed. Default is false.


setPreserveAllSemiColons

public void setPreserveAllSemiColons(boolean preserveAllSemiColons)
Sets whether a semicolons should be preserved. Default is false.


setMergeStringLiterals

public void setMergeStringLiterals(boolean mergeStringLiterals)
Sets whether concatenated string literals should be merged. Default is true.


setDefaultErrorReporter

public void setDefaultErrorReporter(org.mozilla.javascript.ErrorReporter defaultErrorReporter)
Sets the ErrorReporter used by compress(Reader, Writer).


setFailsafe

public void setFailsafe(boolean failsafe)
Sets whether the uncompressed script should be served in case a syntax error is encountered. Default is false.


compress

public void compress(Reader in,
                     Writer out)
              throws IOException
Reads JavaScript from the the given Reader and writes the compressed code to the specified Writer. Errors are reported to the default ErrorReorter.

Specified by:
compress in interface Compressor
Throws:
IOException

compress

public void compress(Reader in,
                     Writer out,
                     String fileName)
              throws IOException
Reads JavaScript from the the given Reader and writes the compressed code to the specified Writer. The given fileName will be used in error messages.

Throws:
IOException

compress

public void compress(Reader in,
                     Writer out,
                     org.mozilla.javascript.ErrorReporter errorReporter)
              throws IOException
Reads JavaScript from the the given Reader and writes the compressed code to the specified Writer. Errors are reported to the given ErrorReorter. In failsafe mode the script is first read into a buffer so that it can be written as-is in case of an error. The actual compression is performed in compressInternal(Reader, Writer, ErrorReporter).

Throws:
IOException

compressInternal

protected void compressInternal(Reader in,
                                Writer out,
                                org.mozilla.javascript.ErrorReporter errorReporter)
                         throws org.mozilla.javascript.EvaluatorException,
                                IOException
Reads JavaScript from the the given Reader and writes the compressed code to the specified Writer. Errors are reported to the given ErrorReorter.

Throws:
org.mozilla.javascript.EvaluatorException
IOException