NextApp Echo
App Container 1.0.5

nextapp.echoservlet.util
Class JavaScriptCompressor

java.lang.Object
  extended bynextapp.echoservlet.util.JavaScriptCompressor

public class JavaScriptCompressor
extends java.lang.Object

Compresses the size of JavaScript resource files by removing comments and white space.


Field Summary
private static char CARRIAGE_RETURN
           
private static char LINE_FEED
           
private static char SPACE
           
 
Constructor Summary
private JavaScriptCompressor()
          Non-instantiable class.
 
Method Summary
static java.lang.String compress(java.lang.String script)
          Compresses a JavaScript file.
private static void removeBoxComments(java.lang.StringBuffer buffer)
          Remove Box comments.
private static void removeCharacterAfterAnother(java.lang.StringBuffer buffer, char charToRemove, char charBefore)
          Removes a character after another.
private static void removeCharacterBeforeAnother(java.lang.StringBuffer buffer, char charToRemove, char charAfter)
          Removes one character before another.
private static void removeLineComments(java.lang.StringBuffer buffer)
          Removes line comments.
private static void removeMultipleCharacters(java.lang.StringBuffer buffer, char charToRemove)
          Removes duplicated characters.
private static java.lang.String replaceCRWithLF(java.lang.String string)
          Replaces all Carriage Return characters with a Line Feeds.
private static void replaceCtrlWithSpaces(java.lang.StringBuffer buffer)
          Replaces all Control characters except Linefeeds with Spaces.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LINE_FEED

private static final char LINE_FEED
See Also:
Constant Field Values

CARRIAGE_RETURN

private static final char CARRIAGE_RETURN
See Also:
Constant Field Values

SPACE

private static final char SPACE
See Also:
Constant Field Values
Constructor Detail

JavaScriptCompressor

private JavaScriptCompressor()
Non-instantiable class.

Method Detail

compress

public static java.lang.String compress(java.lang.String script)
Compresses a JavaScript file.

Parameters:
script - The contents of the JavaScript file as a String.
Returns:
A compressed version of the JavaScript file, with its comments and white space removed.

replaceCRWithLF

private static java.lang.String replaceCRWithLF(java.lang.String string)
Replaces all Carriage Return characters with a Line Feeds.


replaceCtrlWithSpaces

private static void replaceCtrlWithSpaces(java.lang.StringBuffer buffer)
Replaces all Control characters except Linefeeds with Spaces.


removeLineComments

private static void removeLineComments(java.lang.StringBuffer buffer)
Removes line comments.


removeBoxComments

private static void removeBoxComments(java.lang.StringBuffer buffer)
Remove Box comments.


removeMultipleCharacters

private static void removeMultipleCharacters(java.lang.StringBuffer buffer,
                                             char charToRemove)
Removes duplicated characters.


removeCharacterBeforeAnother

private static void removeCharacterBeforeAnother(java.lang.StringBuffer buffer,
                                                 char charToRemove,
                                                 char charAfter)
Removes one character before another.


removeCharacterAfterAnother

private static void removeCharacterAfterAnother(java.lang.StringBuffer buffer,
                                                char charToRemove,
                                                char charBefore)
Removes a character after another.


NextApp Echo
App Container 1.0.5