|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.directwebremoting.util.JavascriptUtil
public class JavascriptUtil
Various Javascript code utilities. The escape classes were taken from jakarta-commons-lang which in turn borrowed from Turbine and other projects. The list of authors below is almost certainly far too long, but I'm not sure who really wrote these methods.
| Field Summary | |
|---|---|
static int |
COMPRESS_REMOVE_NEWLINES
Flag for use in javascript compression: Remove all lines endings. |
static int |
COMPRESS_SHRINK_VARS
Flag for use in javascript compression: Shrink variable names. |
static int |
COMPRESS_STRIP_BLANKLINES
Flag for use in javascript compression: Remove blank lines. |
static int |
COMPRESS_STRIP_ML_COMMENTS
Flag for use in javascript compression: Remove multi line comments. |
static int |
COMPRESS_STRIP_SL_COMMENTS
Flag for use in javascript compression: Remove single line comments. |
static int |
COMPRESS_TRIM_LINES
Flag for use in javascript compression: Remove whitespace at the start and end of a line. |
static int |
LEVEL_DEBUGGABLE
Basic compression that leaves the source fully debuggable. |
static int |
LEVEL_NONE
Compression level that leaves the source un-touched. |
static int |
LEVEL_NORMAL
Normal compression makes all changes that will work for generic javascript. |
static int |
LEVEL_ULTRA
LEVEL_ULTRA performs additional compression that makes some assumptions about the style of javascript. |
| Constructor Summary | |
|---|---|
JavascriptUtil()
|
|
| Method Summary | |
|---|---|
static java.lang.String |
compress(java.lang.String text,
int level)
Compress the source code by removing java style comments and removing leading and trailing spaces. |
static java.lang.String |
escapeJavaScript(java.lang.String str)
Escapes the characters in a String using JavaScript String rules. |
static boolean |
isReservedWord(java.lang.String name)
Check to see if the given word is reserved or a bad idea in any known version of JavaScript. |
static java.lang.String |
shrinkVariableNames(java.lang.String text)
Shrink variable names to a minimum. |
static java.lang.String |
stripBlankLines(java.lang.String text)
Remove all blank lines from a string. |
static java.lang.String |
stripMultiLineComments(java.lang.String text)
Remove all the multi-line comments from a block of text |
static java.lang.String |
stripNewlines(java.lang.String text)
Remove all newline characters from a string. |
static java.lang.String |
stripSingleLineComments(java.lang.String text)
Remove all the single-line comments from a block of text |
static java.lang.String |
trimLines(java.lang.String text)
Remove any leading or trailing spaces from a line of code. |
static java.lang.String |
unescapeJavaScript(java.lang.String str)
Unescapes any JavaScript literals found in the String. |
| Methods inherited from class java.lang.Object |
|---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final int COMPRESS_STRIP_SL_COMMENTS
public static final int COMPRESS_STRIP_ML_COMMENTS
public static final int COMPRESS_TRIM_LINES
public static final int COMPRESS_STRIP_BLANKLINES
public static final int COMPRESS_SHRINK_VARS
public static final int COMPRESS_REMOVE_NEWLINES
public static final int LEVEL_NONE
public static final int LEVEL_DEBUGGABLE
public static final int LEVEL_NORMAL
public static final int LEVEL_ULTRA
| Constructor Detail |
|---|
public JavascriptUtil()
| Method Detail |
|---|
public static java.lang.String compress(java.lang.String text,
int level)
text - The javascript (or java) program to compresslevel - The compression level - see LEVEL_* and COMPRESS_* constants.
public static java.lang.String trimLines(java.lang.String text)
text - The javascript program to strip spaces from.
public static java.lang.String stripSingleLineComments(java.lang.String text)
text - The text to remove single-line comments from
public static java.lang.String stripMultiLineComments(java.lang.String text)
text - The text to remove multi-line comments from
public static java.lang.String stripBlankLines(java.lang.String text)
text - The string to strip blank lines from
public static java.lang.String stripNewlines(java.lang.String text)
text - The string to strip newline characters from
public static java.lang.String shrinkVariableNames(java.lang.String text)
text - The javascript program to shrink the variable names in.
public static java.lang.String escapeJavaScript(java.lang.String str)
Escapes the characters in a String using JavaScript String rules.
Escapes any values it finds into their JavaScript String form. Deals correctly with quotes and control-chars (tab, backslash, cr, ff, etc.)
So a tab becomes the characters '\\' and
't'.
The only difference between Java strings and JavaScript strings is that in JavaScript, a single quote must be escaped.
Example:
input string: He didn't say, "Stop!" output string: He didn\'t say, \"Stop!\"
str - String to escape values in, may be null
null if null string inputpublic static java.lang.String unescapeJavaScript(java.lang.String str)
Unescapes any JavaScript literals found in the String.
For example, it will turn a sequence of '\' and 'n'
into a newline character, unless the '\' is preceded by another
'\'.
str - the String to unescape, may be null
String, null if null string inputpublic static boolean isReservedWord(java.lang.String name)
name - The word to check
|
Copyright ¬ 2005 | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||