org.kuali.rice.krad.uif.util
Class ScriptUtils

java.lang.Object
  extended by org.kuali.rice.krad.uif.util.ScriptUtils

public class ScriptUtils
extends Object

Utility class for generating JavaScript

Author:
Kuali Rice Team (rice.collab@kuali.org)

Constructor Summary
ScriptUtils()
           
 
Method Summary
static String appendScript(String script, String appendScript)
          Will append the second script parameter to the first if the first is not empty, also checks to see if the first script needs an end semi-colon added
static String convertStringListToJsArray(List<String> list)
          Converts a list of string to a valid js string array
static String convertToJsValue(String value)
          Convert a string to a javascript value - especially for use for options used to initialize widgets such as the tree and rich table
static List<String> escapeHtml(List<String> strings)
          escape an array of strings
static String escapeHtml(String string)
          escapes a string using StringEscapeUtils.escapeHtml(String)
static String escapeJSONString(String jsonString)
          Escapes double quotes present in the given string
static String escapeName(String name)
          Escapes the ' character present in collection names so it can be properly used in js without causing javascript errors due to an early completion of a ' string.
static String toJSON(Map<String,String> map)
          Builds a JSON string form the given map
static String translateValue(Object value)
          Translates an Object to a String for representing the given Object as a JavaScript value
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ScriptUtils

public ScriptUtils()
Method Detail

translateValue

public static String translateValue(Object value)
Translates an Object to a String for representing the given Object as a JavaScript value

Handles null, List, Map, and Set collections, along with non quoting for numeric and boolean types. Complex types are treated as a String value using toString

Parameters:
value - - Object instance to translate
Returns:
String JS value

toJSON

public static String toJSON(Map<String,String> map)
Builds a JSON string form the given map

Parameters:
map - - map to translate
Returns:
String in JSON format

escapeJSONString

public static String escapeJSONString(String jsonString)
Escapes double quotes present in the given string

Parameters:
jsonString - - string to escape
Returns:
String escaped string

convertToJsValue

public static String convertToJsValue(String value)
Convert a string to a javascript value - especially for use for options used to initialize widgets such as the tree and rich table

Parameters:
value - - the string to be converted
Returns:
- the converted value

escapeName

public static String escapeName(String name)
Escapes the ' character present in collection names so it can be properly used in js without causing javascript errors due to an early completion of a ' string.

Parameters:
name -
Returns:

convertStringListToJsArray

public static String convertStringListToJsArray(List<String> list)
Converts a list of string to a valid js string array

Parameters:
list - - list of Strings to be converted
Returns:
String representing the js array

escapeHtml

public static String escapeHtml(String string)
escapes a string using StringEscapeUtils.escapeHtml(String)

The apostrophe character is included as StringEscapeUtils#escapeHtml(String) does not consider it a legal entity.

Parameters:
string - - the string to be escaped
Returns:
- the escaped string - useful for embedding in server side generated JS scripts

escapeHtml

public static List<String> escapeHtml(List<String> strings)
escape an array of strings

Parameters:
strings - - an array of strings to escape
Returns:
- the array, with the strings escaped

appendScript

public static String appendScript(String script,
                                  String appendScript)
Will append the second script parameter to the first if the first is not empty, also checks to see if the first script needs an end semi-colon added

Parameters:
script - - script that will be added to (null is allowed and converted to empty string)
appendScript - - script to append
Returns:
String result of appending the two script parameters


Copyright © 2005-2012 The Kuali Foundation. All Rights Reserved.