nl.imsystems.atag.util
Class Utils

java.lang.Object
  extended by nl.imsystems.atag.util.Utils

public class Utils
extends Object

Support functions used by ATag.

Author:
kayvan


Method Summary
static String asString(Object obj)
          Returns a String representation of the object parameter.
static String capFirstChar(String str)
          Capitalizes the first char of a given String.
static String createAttribute(String name, Object value)
          Creates a single attribute for insertion into x/html tags.
static String createCSV(Collection elements, boolean quote)
          Creates a comma separated String, given a Collection of objects.
static String createDelimitedString(Collection elements, char delimiter, boolean quote)
          Creates a delimited String, given a Collection of objects.
static String createEventHandlerFunct(String url)
          Creates a javascript call to the ATag event handler function.
static String createEventHandlerFunctForm(String url)
          Creates a javascript call to the ATag event handler function.
static String createLitralJSArray(Collection elements, boolean quote)
          Creates a literal javascript array.
static Object getValueFromBindPath(PageContext pageContext, String bindPath)
          Attempts to retrieve an object from any of the webapp scopes, given the path to the object.
static String insertAttributes(String content, String attributes)
          Looks in the content parameter for the first occurance of an x/html element, and inserts the attributes parameter into that element.
static List mapToStringList(Map map, char separator)
          Creates a List of Strings by joining the key value of every entry in the map, with its associated value, separated by the separator char.
static String resolveRelativePath(String base, String path, char separator)
          Resolves a relative path such as ../../path/to/it.
static String[] tokenize(String str, String delim)
          Tokenizes a given String.
static String[] tokenize(String str, String delim, boolean include)
          Tokenizes a given String.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

asString

public static String asString(Object obj)
Returns a String representation of the object parameter.

Parameters:
obj - The object to convert to String.
Returns:
A String representation obj, or a blank String if obj is null

createDelimitedString

public static String createDelimitedString(Collection elements,
                                           char delimiter,
                                           boolean quote)
Creates a delimited String, given a Collection of objects.

Parameters:
elements - The objects to concatenate
delimiter - The char to use as delimiter
quote - Set true to wrap each element in single quote
Returns:
A String composed of all elements in the collection, separeted by the delimiter char

createCSV

public static String createCSV(Collection elements,
                               boolean quote)
Creates a comma separated String, given a Collection of objects.

Parameters:
elements - The objects to concatenate
quote - Set true to wrap each element in single quote
Returns:
A String composed of all elements in the collection, separeted by a comma

createLitralJSArray

public static String createLitralJSArray(Collection elements,
                                         boolean quote)
Creates a literal javascript array.

Parameters:
elements - The elements of the array
quote - Set true to wrap each element in single quote
Returns:
A String composed of all elements in the collection, separeted by a comma and wrapped in []

createAttribute

public static String createAttribute(String name,
                                     Object value)
Creates a single attribute for insertion into x/html tags. Prepends the attribute text with a space.

Parameters:
name - Name of attribute
value - Attribute value
Returns:
' name="value"'

createEventHandlerFunct

public static String createEventHandlerFunct(String url)
Creates a javascript call to the ATag event handler function.

Parameters:
url - Optionl parameter as the location to send the event
Returns:
A javascript function call to the ATag event handler function

createEventHandlerFunctForm

public static String createEventHandlerFunctForm(String url)
Creates a javascript call to the ATag event handler function. A variation to the above which posts the entire form as opposed to only the event source component.

Parameters:
url - Optionl parameter as the location to send the event
Returns:
A javascript function call to the form version of the ATag event handler function

insertAttributes

public static String insertAttributes(String content,
                                      String attributes)
Looks in the content parameter for the first occurance of an x/html element, and inserts the attributes parameter into that element.

Parameters:
content - The x/html content
attributes - The attributes to insert
Returns:
The content with attributes inserted or content, if no x/html element is found

tokenize

public static String[] tokenize(String str,
                                String delim)
Tokenizes a given String.

Parameters:
str - The String to tokenize
delim - A String containing all chars that should be treated as delimiters
Returns:
An array of tokens not including the delimiters

tokenize

public static String[] tokenize(String str,
                                String delim,
                                boolean include)
Tokenizes a given String.

Parameters:
str - The String to tokenize
delim - A String containing all chars that should be treated as delimiters
include - Set true to include the delimiter in the resulting tokens array
Returns:
An array of tokens

resolveRelativePath

public static String resolveRelativePath(String base,
                                         String path,
                                         char separator)
Resolves a relative path such as ../../path/to/it.

Parameters:
base - Current location as an absolute path
path - The relative path to resolve
separator - Path separator char
Returns:
An absolute path based on resolving the relative path

getValueFromBindPath

public static Object getValueFromBindPath(PageContext pageContext,
                                          String bindPath)
Attempts to retrieve an object from any of the webapp scopes, given the path to the object.

Parameters:
pageContext - The current page context
bindPath - The path to the object
Returns:
The object or null of no object found at the supplied path

capFirstChar

public static String capFirstChar(String str)
Capitalizes the first char of a given String.

Parameters:
str - The String to capitalize
Returns:
The String with first char capitalized

mapToStringList

public static List mapToStringList(Map map,
                                   char separator)
Creates a List of Strings by joining the key value of every entry in the map, with its associated value, separated by the separator char.

Parameters:
map - The Map to convert
separator - The separator to use between key and value
Returns:
A List of Strings