com.atlassian.gadgets.dashboard.internal.util
Class JavaScript

java.lang.Object
  extended by com.atlassian.gadgets.dashboard.internal.util.JavaScript

public class JavaScript
extends Object

Escaping that was ripped from Apache Commons-Lang StringUtils class, modified to escape the '<' character as a unicode string as described in AG-1005.


Constructor Summary
JavaScript()
           
 
Method Summary
static String escape(String str)
           Escapes the characters in a String using JavaScript String rules.
static void escape(Writer out, String str)
           Escapes the characters in a String using JavaScript String rules to a Writer.
static String hex(char ch)
           Returns an upper case hexadecimal String for the given character.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JavaScript

public JavaScript()
Method Detail

escape

public static String escape(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!\"
 

Parameters:
str - String to escape values in, may be null
Returns:
String with escaped values, null if null string input

escape

public static void escape(Writer out,
                          String str)
                   throws IOException

Escapes the characters in a String using JavaScript String rules to a Writer.

A null string input has no effect.

Parameters:
out - Writer to write escaped string into
str - String to escape values in, may be null
Throws:
IllegalArgumentException - if the Writer is null
IOException - if error occurs on underlying Writer
See Also:
#escapeJavaScript(java.lang.String)

hex

public static String hex(char ch)

Returns an upper case hexadecimal String for the given character.

Parameters:
ch - The character to convert.
Returns:
An upper case hexadecimal String


Copyright © 2012 Atlassian. All Rights Reserved.