Package org.kuali.rice.krad.uif.util
Class ScriptUtils
java.lang.Object
org.kuali.rice.krad.uif.util.ScriptUtils
Utility class for generating JavaScript
- Author:
- Kuali Rice Team (rice.collab@kuali.org)
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic StringappendScript(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 addedstatic StringbuildEventHandlerScript(String id, String eventName, String eventScript) Builds the JavaScript string for binding the given script to the component with the given id for the given event name (using jQuery)static StringbuildFunctionCall(String functionName, Object... arguments) Helper method to build a JS string that will invoke the given function with the given argumentsstatic StringconvertStringListToJsArray(List<String> list) Converts a list of string to a valid js string arraystatic StringconvertToJsValue(String value) Convert a string to a javascript value - especially for use for options used to initialize widgets such as the tree and rich tablestatic StringconvertToJsValue(Map<String, String> stringMap) Converts a map of string values to a json equivalent by converting the string values through the convertToJsValue(String) method; this will output a string representation of the map in json formatstatic StringescapeHtml(String string) escapes a string usingStringEscapeUtils.escapeHtml(String)escapeHtml(List<String> strings) escape an array of stringsstatic StringescapeJSONString(String jsonString) Escapes double quotes present in the given stringstatic StringescapeName(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 StringBuilds a JSON string form the given mapstatic StringtranslateValue(Object value) Translates an Object to a String for representing the given Object as a JavaScript value
-
Constructor Details
-
ScriptUtils
public ScriptUtils()
-
-
Method Details
-
translateValue
Translates an Object to a String for representing the given Object as a JavaScript valueHandles 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:
- JS value
-
toJSON
Builds a JSON string form the given map- Parameters:
map- map to translate- Returns:
- String in JSON format
-
escapeJSONString
Escapes double quotes present in the given string- Parameters:
jsonString- string to escape- Returns:
- escaped string
-
convertToJsValue
Converts a map of string values to a json equivalent by converting the string values through the convertToJsValue(String) method; this will output a string representation of the map in json format- Parameters:
stringMap- the map of String values to convert to a simple json object representation- Returns:
- the json object as a string (for use in js)
-
convertToJsValue
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
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- name to escape- Returns:
- name, with single quotes escape
-
convertStringListToJsArray
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
escapes a string usingStringEscapeUtils.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
escape an array of strings- Parameters:
strings- an array of strings to escape- Returns:
- the array, with the strings escaped
-
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
-
buildFunctionCall
Helper method to build a JS string that will invoke the given function with the given arguments- Parameters:
functionName- name of the JS function to invokearguments- zero or more arguments to pass, each will be converted to the corresponding JS type- Returns:
- JS String for invoking the function
-
buildEventHandlerScript
Builds the JavaScript string for binding the given script to the component with the given id for the given event name (using jQuery)- Parameters:
id- id of the element to handle the event foreventName- name of the event the script will handleeventScript- script to be executed when the event is thrown, if blank an empty string will be returned- Returns:
- JS event handler script
-