javawebparts.filter
Class JSMin

java.lang.Object
  |
  +--javawebparts.filter.JSMin

public class JSMin
extends java.lang.Object

This class is used to do compression.

Author:
Herman van Rosmalen .

Nested Class Summary
(package private)  class JSMin.UnterminatedCommentException
          This class is thrown when a Comment is not terminated correctly.
(package private)  class JSMin.UnterminatedRegExpLiteralException
          This class is thrown when a RegExp is not terminated correctly.
(package private)  class JSMin.UnterminatedStringLiteralException
          This class is thrown when a String is not terminated correctly.
 
Field Summary
private static int EOF
           
private  java.io.PushbackInputStream in
           
private  java.lang.StringBuffer out
           
private  int theA
           
private  int theB
           
 
Constructor Summary
JSMin()
          Constructor
 
Method Summary
(package private)  void action(int d)
          action -- do something.
 java.lang.String compress(java.lang.String text)
          compress -- Copy the input to the output, deleting the characters which are insignificant to JavaScript.
(package private)  int get()
          get -- return the next character from stdin.
(package private) static boolean isAlphanum(int c)
          isAlphanum -- return true if the character is a letter, digit, underscore, dollar sign, or non-ASCII character.
(package private)  int next()
          This method gets the next character, excluding comments.
(package private)  int peek()
          Get the next character without getting it.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

EOF

private static final int EOF
See Also:
Constant Field Values

in

private java.io.PushbackInputStream in

out

private java.lang.StringBuffer out

theA

private int theA

theB

private int theB
Constructor Detail

JSMin

public JSMin()
Constructor

Method Detail

isAlphanum

static boolean isAlphanum(int c)
isAlphanum -- return true if the character is a letter, digit, underscore, dollar sign, or non-ASCII character.

Parameters:
c - the character from the input as an int.
Returns:
boolean true if it is alphanumeric else false.

get

int get()
  throws java.io.IOException
get -- return the next character from stdin. Watch out for lookahead. If the character is a control character, translate it to a space or linefeed.

Returns:
int the next character as int.
Throws:
java.io.IOException - IOException.

peek

int peek()
   throws java.io.IOException
Get the next character without getting it.

Returns:
int the next character as int.
Throws:
java.io.IOException - IOException.

next

int next()
   throws JSMin.UnterminatedCommentException,
          java.io.IOException
This method gets the next character, excluding comments. peek() is used to see if a '/' is followed by a '/' or '*'.

Returns:
int the next character as int.
Throws:
JSMin.UnterminatedCommentException - UnterminatedCommentException.
java.io.IOException - IOException.

action

void action(int d)
      throws java.io.IOException,
             JSMin.UnterminatedRegExpLiteralException,
             JSMin.UnterminatedCommentException,
             JSMin.UnterminatedStringLiteralException
action -- do something. What you do is determined by the argument: 1 Output A. Copy B to A. Get the next B. 2 Copy B to A. Get the next B. (Delete A). 3 Get the next B. (Delete B). action treats a string as a single character. Wow! action recognizes a regular expression if it is preceded by ( or , or =.

Parameters:
d - Type of action (see above).
Throws:
java.io.IOException - IOException.
JSMin.UnterminatedRegExpLiteralException - UnterminatedRegExpLiteralException.
JSMin.UnterminatedCommentException - UnterminatedCommentException.
JSMin.UnterminatedStringLiteralException - UnterminatedStringLiteralException.

compress

public java.lang.String compress(java.lang.String text)
                          throws java.io.IOException,
                                 JSMin.UnterminatedRegExpLiteralException,
                                 JSMin.UnterminatedCommentException,
                                 JSMin.UnterminatedStringLiteralException
compress -- Copy the input to the output, deleting the characters which are insignificant to JavaScript. Comments will be removed. Tabs will be replaced with spaces. Carriage returns will be replaced with linefeeds. Most spaces and linefeeds will be removed.

Parameters:
text - The text to compress.
Returns:
String The compressed text.
Throws:
java.io.IOException - IOException.
JSMin.UnterminatedRegExpLiteralException - UnterminatedRegExpLiteralException.
JSMin.UnterminatedCommentException - UnterminatedCommentException.
JSMin.UnterminatedStringLiteralException - UnterminatedStringLiteralException.


Copyright 2005 Frank W. Zammetti