com.ail.core
Class Functions

java.lang.Object
  extended by com.ail.core.Functions

public class Functions
extends java.lang.Object

Utility function class.

Version:
$Revision: 1.16 $

Constructor Summary
Functions()
           
 
Method Summary
static java.net.URL absoluteConfigureUrl(Core core, java.lang.String suppliedUrl)
           
static void closeJdbc(java.sql.Connection con, java.sql.Statement st, java.sql.ResultSet rs)
          Close a connection to a JDBC database in a safe fashion.
static java.lang.String configurationNamespaceToProductName(java.lang.String configuratioNamespace)
          Return the product name associated with a configuration namespace.
static TypeEnum enumForName(java.lang.String name, TypeEnum[] enums)
           
static java.lang.String expand(java.lang.String src, Type model)
          Utility method to expand 'variables' embedded in a string with respect to a model.
static void expand(java.io.Writer writer, java.io.InputStream content, Type model)
          Utility method which reads content from a url, expands any variables it finds embedded in the content against the model supplied, and writes the output to a specified writer.
static void expand(java.io.Writer writer, java.lang.String content, Type model)
          Utility method which expands any variables it finds embedded in the passed in content against the model supplied, and writes the output to a specified writer.
static void expand(java.io.Writer writer, java.net.URL url, Type model)
          Utility method which reads content from a url, expands any variables it finds embedded in the content against the model supplied, and writes the output to a specified writer.
static java.lang.String format(java.util.Date date, java.lang.String pattern)
          Translate a Date into a String using the specified format.
static java.lang.String[] getStringArrayFromString(java.lang.String string, java.lang.String separator)
          Builds a String[] from a String with a given character separating values.
static java.lang.String hideNull(java.lang.String s)
          Convert null strings into empty strings.
static java.lang.String loadScriptOrUrlContent(Core core, java.lang.String suppliedUrl, java.lang.String script)
          The script may be local (the value of the script property), or remote (loaded using the url property).
static java.lang.String loadUrlContentAsString(java.net.URL url)
          Load the content from a URL into a String.
static java.lang.String productNameToConfigurationNamespace(java.lang.String productName)
          Return the configuration namespace associated with a product.
static java.lang.String productNameToDefaultType(java.lang.String productName)
          Return the name of a product's default type based on it's namespace.
static java.lang.String valuesAsCsv(java.lang.Object[] e)
          Turn an array of Objects into a comma separated list where each value in the list is the result of calling toString() on the corresponding Object.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Functions

public Functions()
Method Detail

getStringArrayFromString

public static java.lang.String[] getStringArrayFromString(java.lang.String string,
                                                          java.lang.String separator)
Builds a String[] from a String with a given character separating values. Example "val1|val2|val3".

Parameters:
string - String containing values.
separator - Denotes character(s) in between values.
Returns:
String[] of values.

closeJdbc

public static void closeJdbc(java.sql.Connection con,
                             java.sql.Statement st,
                             java.sql.ResultSet rs)
Close a connection to a JDBC database in a safe fashion.

Parameters:
con - Connection to be closed (or null)
st - Statement to be closed (or null)
rs - ResultSet to be closed (or null)

valuesAsCsv

public static java.lang.String valuesAsCsv(java.lang.Object[] e)
Turn an array of Objects into a comma separated list where each value in the list is the result of calling toString() on the corresponding Object.

If the array of objects is empty, an empty string is returned.

Parameters:
e - An array of objects to be CSV'ed
Returns:
A String in comma separated value format.

enumForName

public static TypeEnum enumForName(java.lang.String name,
                                   TypeEnum[] enums)

loadUrlContentAsString

public static java.lang.String loadUrlContentAsString(java.net.URL url)
                                               throws java.io.IOException
Load the content from a URL into a String.

Parameters:
url - URL to load content from
Returns:
Content
Throws:
java.io.IOException

expand

public static java.lang.String expand(java.lang.String src,
                                      Type model)
Utility method to expand 'variables' embedded in a string with respect to a model. Variables are in the form '${<xpath>}', where xpath is an expression compatible with JXPath. The xpath expression is evaluated against model and the result placed into the string returned.

For example: if the src value of "Your quote number is: ${/quoteNumber}" is passed in with a model containing value of 'FQ1234' in it's quoteNumber property; this method would return "Your quote number is: FQ1234".

Parameters:
src -
model -
Returns:
A string matching src but with variable references expanded.

expand

public static void expand(java.io.Writer writer,
                          java.lang.String content,
                          Type model)
Utility method which expands any variables it finds embedded in the passed in content against the model supplied, and writes the output to a specified writer.

Parameters:
writer - Where the expanded output is written no.
content - The String to read content from
model - The model to resolve variable references against

expand

public static void expand(java.io.Writer writer,
                          java.net.URL url,
                          Type model)
Utility method which reads content from a url, expands any variables it finds embedded in the content against the model supplied, and writes the output to a specified writer.

Parameters:
writer - Where the expanded output is written no.
url - The URL to read content from
model - The model to resolve variable references against

expand

public static void expand(java.io.Writer writer,
                          java.io.InputStream content,
                          Type model)
Utility method which reads content from a url, expands any variables it finds embedded in the content against the model supplied, and writes the output to a specified writer.

Parameters:
writer - Where the expanded output is written no.
content - Stream to read content from.
model - The model to resolve variable references against

hideNull

public static java.lang.String hideNull(java.lang.String s)
Convert null strings into empty strings. When a UI component is rendering it'll frequently want to render null strings. The default java behaviour when you ask to output a null String is to write "null" to the output - which isn't what we typically want on the UI.

Parameters:
s - String to check
Returns:
"" if the string was null, or the value of the string if it was not.

format

public static java.lang.String format(java.util.Date date,
                                      java.lang.String pattern)
Translate a Date into a String using the specified format.

Parameters:
date - Date to be converted
pattern - Format for to return date
Returns:
date formatted as pattern

absoluteConfigureUrl

public static java.net.URL absoluteConfigureUrl(Core core,
                                                java.lang.String suppliedUrl)
                                         throws java.net.MalformedURLException
Throws:
java.net.MalformedURLException

loadScriptOrUrlContent

public static java.lang.String loadScriptOrUrlContent(Core core,
                                                      java.lang.String suppliedUrl,
                                                      java.lang.String script)
The script may be local (the value of the script property), or remote (loaded using the url property). This method will return the script no matter where it is.

Returns:
A String representing the script

productNameToConfigurationNamespace

public static java.lang.String productNameToConfigurationNamespace(java.lang.String productName)
Return the configuration namespace associated with a product. The convention is that each product has it's own configuration namespace. The productName is in fact the name of the package containing (as a minimum) the product's Registry.

Parameters:
productName - Name of the product to get the namespace.
Returns:
Configuration namespace where the product's configuration can be found.

configurationNamespaceToProductName

public static java.lang.String configurationNamespaceToProductName(java.lang.String configuratioNamespace)
Return the product name associated with a configuration namespace. The convention is that each product has it's own configuration namespace. The productName is in fact the name of the package containing (as a minimum) the product's Registry.

Parameters:
configuratioNamespace - Namespace to fetch the product name for.
Returns:
Product name associated with the namespace

productNameToDefaultType

public static java.lang.String productNameToDefaultType(java.lang.String productName)
Return the name of a product's default type based on it's namespace.

Parameters:
productName - Name of product to get the default type for.
Returns:
Name of the default type.