net.sf.tacos.util
Class ScriptUtils

java.lang.Object
  extended by net.sf.tacos.util.ScriptUtils

public final class ScriptUtils
extends Object

Provides commonly used string functions not provided by other String based libraries.

Author:
jkuhnert, sunfmin

Field Summary
static String BEGIN_COMMENT
          XML cdata start
static String END_COMMENT
          XML character data end
static Pattern SCRIPT_INCLUDE_PATTERN
          regexp pattern matching js package include statements
static Pattern SCRIPT_PATTERN
          Regexp represenging javascript matches
 
Constructor Summary
ScriptUtils()
           
 
Method Summary
static Map createParamsMap(String initializer, String delim)
          Creates a parameters map using the specified initializer and delimiter.
static String ensureValidScriptTags(String input)
          Takes any tags found in the specified input string and replaces their contents into one large block (meaning if multiple script blocks are found, they will be turned into one), with the addition of BEGIN_COMMENT inserted before the logic block and END_COMMENT inserted after the logic block.
static String escapeJavaScriptHash(String jshash)
          input: {paramA:{param1: val"u\e1 , param2: "value2"}, "paramB":'valueB'} output: {'paramA':{'param1': 'val\"u\\e1' , 'param2': 'value2'}, 'paramB':'valueB'}
static org.apache.tapestry.IComponent getContainer(org.apache.tapestry.IComponent comp)
          Returns the component's container, or the page if it's null.
static String getFieldId(org.apache.tapestry.IComponent comp, String uniqueId)
          Gets the unique ID from a component.
static void parseJSIncludes(String input, StringBuffer appender)
          Parses any tags found in input string.
static String toJsStringArray(Iterator values)
          Create a list of quoted strings.
static String toJsStringArray(String[] a, int offset, int length)
          Create a list of quoted strings.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

BEGIN_COMMENT

public static final String BEGIN_COMMENT
XML cdata start

See Also:
Constant Field Values

END_COMMENT

public static final String END_COMMENT
XML character data end

See Also:
Constant Field Values

SCRIPT_PATTERN

public static final Pattern SCRIPT_PATTERN
Regexp represenging javascript matches


SCRIPT_INCLUDE_PATTERN

public static final Pattern SCRIPT_INCLUDE_PATTERN
regexp pattern matching js package include statements

Constructor Detail

ScriptUtils

public ScriptUtils()
Method Detail

ensureValidScriptTags

public static String ensureValidScriptTags(String input)
Takes any tags found in the specified input string and replaces their contents into one large block (meaning if multiple script blocks are found, they will be turned into one), with the addition of BEGIN_COMMENT inserted before the logic block and END_COMMENT inserted after the logic block.

Parameters:
input - The string to replace tags on
Returns:
The properly formatted string, if any formatting needed to occur.

parseJSIncludes

public static void parseJSIncludes(String input,
                                   StringBuffer appender)
Parses any tags found in input string. The formatted and dojo-bound script loading logic is appended to the appender parameter.

Parameters:
input - The string to grab js includes from
appender - The buffer to add dojo js load calls into

toJsStringArray

public static String toJsStringArray(String[] a,
                                     int offset,
                                     int length)
Create a list of quoted strings. The list is suitable for initializing a JavaScript array.


toJsStringArray

public static String toJsStringArray(Iterator values)
Create a list of quoted strings. The list is suitable for initializing a JavaScript array.


escapeJavaScriptHash

public static String escapeJavaScriptHash(String jshash)
input: {paramA:{param1: val"u\e1 , param2: "value2"}, "paramB":'valueB'} output: {'paramA':{'param1': 'val\"u\\e1' , 'param2': 'value2'}, 'paramB':'valueB'}

Parameters:
jshash -
Returns:
escaped hash

createParamsMap

public static Map createParamsMap(String initializer,
                                  String delim)
Creates a parameters map using the specified initializer and delimiter. Parameters are in the form "param=value".

Parameters:
initializer - the initializer.
Returns:
The params map.

getFieldId

public static String getFieldId(org.apache.tapestry.IComponent comp,
                                String uniqueId)
Gets the unique ID from a component. If the component is a form field, it gets the client id. If not, then it gets the normal id.

Parameters:
comp - the component to extract the id from.
uniqueId - optional unique id. Overrides the component's id.
Returns:
The component id.

getContainer

public static org.apache.tapestry.IComponent getContainer(org.apache.tapestry.IComponent comp)
Returns the component's container, or the page if it's null.

Parameters:
comp - the component.
Returns:
The component's container.