com.ebasetech.ufs.utility
Class Utility

java.lang.Object
  extended bycom.ebasetech.ufs.utility.Utility
All Implemented Interfaces:
java.io.Serializable

public class Utility
extends java.lang.Object
implements java.io.Serializable

See Also:
Serialized Form

Field Summary
private static java.lang.String COMMA
           
private static java.lang.Object EMPTY
           
private static char SINGLE_QUOTE
           
(package private) static int UTIL_LITERAL
           
 
Constructor Summary
Utility()
          Utility constructor comment.
 
Method Summary
static java.lang.String BuildMapParameterString(java.util.Map params)
          Given an iterator across a collection of key/value pairs, encode those pairs as a comma separated string value
static java.lang.String BuildParameterString(java.util.Iterator parameters)
          Given an iterator over a collection of strings, answer a single string containing those strings in a comma-separated list
static java.lang.String constructQMarkStringFor(java.lang.String attrsString)
          Builds a string like "?,?,?,?" to be used in a prepared statement.
 java.lang.Object evalExpression(java.lang.String expression, com.ebasetech.ufs.kernel.Form form, java.lang.String actionScriptId, com.ebasetech.ufs.validation.Node node, com.ebasetech.ufs.validation.Event event)
          Method : evalExpression Description : Evaluates an expression.
static void ExtractMapParametersFromResultSet(java.sql.ResultSet rs, java.lang.String columnName, java.util.Map target)
          Extract the comma separated key-value pair parameters in the named column into the supplied target list
static void ExtractMapParametersFromString(java.lang.String listString, java.util.Map target)
          Extract the comma separated key-value pair parameters in the supplied string into the supplied target list
static void ExtractParametersFromResultSet(java.sql.ResultSet rs, java.lang.String columnName, java.util.List target)
          Extract the comma separated parameters in the named column into the supplied target list
static void ExtractParametersFromString(java.lang.String listString, java.util.List target)
          Extract the comma separated parameters in the supplied string into the supplied target list
 java.util.HashMap extractParametersFromString(java.lang.String commandText, com.ebasetech.ufs.kernel.StandaloneUFSComponent form, boolean toUpperCase, java.lang.String actionScriptId, com.ebasetech.ufs.validation.Event event, com.ebasetech.ufs.validation.Node node)
          Extracts key/value parameters from a command text string and constructs a HashMap consisting of entry with key = the key and value = the value for each key/value pair For example : input string of "GOTO FORM MYFORM abc=rt4, def=iuy" will result in HashMap with 2 entries : 1.
static java.lang.String FlattenParamsMap(java.util.Map paramsMap)
          flatten the params map into a string of comma separated key-value pairs.
static boolean getBooleanFromSqlStmt(java.lang.String val)
          Answers true/false depending on the char value of the supplied value
static java.lang.String GetCharacterStreamFromResultSet(java.sql.ResultSet rs, java.lang.String columnName)
          extracts a character stream from the result set for the given DB column name
 java.lang.String getFieldPresentationValue(java.lang.String fieldName, com.ebasetech.ufs.kernel.StandaloneUFSComponent form, com.ebasetech.ufs.validation.Event event, com.ebasetech.ufs.validation.Node node)
          Method : getFieldPresentationValue Description : returns the script field value for the passed field name.
 java.lang.String getFieldValue(java.lang.String fieldName, com.ebasetech.ufs.kernel.StandaloneUFSComponent form, com.ebasetech.ufs.validation.Event event, com.ebasetech.ufs.validation.Node node)
          Method : getFieldValue Description : returns the script field value for the passed field name.
 java.lang.String getRelativeFieldName(java.lang.String fieldName, com.ebasetech.ufs.validation.Event event, com.ebasetech.ufs.validation.Node node)
           
 java.lang.String getRelativePageName(java.lang.String pageName, com.ebasetech.ufs.validation.Event event, com.ebasetech.ufs.validation.Node node)
           
 boolean isCheckForNull(java.util.Vector tokens, int posn)
          Method : isCheckForNull Description : returns true if the follwoing operator is == or != and the right hand operand is NULL or Null or nuLL ...
 boolean isFieldDateOrNumeric(java.lang.String fieldName, com.ebasetech.ufs.kernel.StandaloneUFSComponent form, com.ebasetech.ufs.validation.Event event, com.ebasetech.ufs.validation.Node node)
           
 boolean isFormField(java.lang.String fieldName, com.ebasetech.ufs.kernel.StandaloneUFSComponent form, com.ebasetech.ufs.validation.Event event, com.ebasetech.ufs.validation.Node node)
          Insert the method's description here.
 boolean isFunction(java.lang.String functionName, com.ebasetech.ufs.kernel.StandaloneUFSComponent form)
          Insert the method's description here.
 boolean isPage(java.lang.String pageName, com.ebasetech.ufs.kernel.StandaloneUFSComponent form, com.ebasetech.ufs.validation.Event event, com.ebasetech.ufs.validation.Node node)
          Insert the method's description here.
 boolean isStringaDate(java.lang.String s)
          Method : isStringaDate Description : returns true if the parameter looks like a date.
static void main(java.lang.String[] args)
           
 void parseExpression(java.lang.String expression, java.util.Vector tokens, java.util.Vector ttypes, java.lang.String actionScriptId)
          Method : parseExpression Description : Break the expression into a vector, for later analysis A StreamTokenizer is used to parse the expression; Vector tokens is populated by the tokens with no substitution except for single quotes ' are replaced by " Vector ttypes is populated (one-to-one for tokens).
 java.lang.String replaceString(java.lang.String inString, java.lang.String findString, java.lang.String replaceString)
          Insert the method's description here.
 java.lang.String replaceStringUnlessInQuotes(java.lang.String inString, java.lang.String findString, java.lang.String replaceString)
          Insert the method's description here.
static void setBooleanInSqlStmt(java.sql.PreparedStatement stmt, int position, boolean value)
          Sets Y/N in the string value of prepared statement at the specified position depending on the supplied boolean value
static java.util.HashMap UnflattenParamsMap(java.lang.String flattenedParams)
          unpacks the parameters map from the flattened form
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

UTIL_LITERAL

static final int UTIL_LITERAL
See Also:
Constant Field Values

SINGLE_QUOTE

private static final char SINGLE_QUOTE
See Also:
Constant Field Values

COMMA

private static final java.lang.String COMMA
See Also:
Constant Field Values

EMPTY

private static final java.lang.Object EMPTY
Constructor Detail

Utility

public Utility()
Utility constructor comment.

Method Detail

evalExpression

public java.lang.Object evalExpression(java.lang.String expression,
                                       com.ebasetech.ufs.kernel.Form form,
                                       java.lang.String actionScriptId,
                                       com.ebasetech.ufs.validation.Node node,
                                       com.ebasetech.ufs.validation.Event event)
                                throws com.ebasetech.ufs.kernel.FormException
Method : evalExpression Description : Evaluates an expression. Returns the result, as evaluated by Jeva. references to Fields are replaced by current values numeric Field values are returned undelimited character Field values are enclosed by "'s AND is replaced by && OR is replaced by || single quotes ' are replaced by " References to RFL functions are prefixed by "Function." to identify them to the dynamic class loader used within the Jeva expression evaluator The resulting string is passed to the Jeva Expression Evaluation algorithm for evaluation. A boolean or value is returned. Jeva will return a result (an object of type object) in response to any syntactically correct Java statement. We use it here to return a boolean response to evaluating a conditional expression. Parameters : a string expression the current form the script id Returns : Object Change log 14/08/2001 * Dave started 17/10/2001 * Dave added - as character for tokenizer to ignore 17/10/2001 * Dave added literal processing for DATE type fields i.e. literals in date expressions are assumed to contain dates with format dd/mm/yyyy and are converted to Julian days to enable date arithmetic. Dates are treated as numbers in terms of value replacement i.e. they are not double quoted as strings are. 19/11/2001 * Hovik removed parameter boolean dateExpression. this needs to be ascertained on a field by field basis 02/01/2002 * Hovik Check strings to see if they contain a date, using isStringaDate 29/01/2002 * Hovik This is now used by setFieldValue/setButtonText commands, as well as by IfNode. ie evalutes ANY expression. Keeps the logic in one place. 06/02/2002 * Hovik && and || no longer being treated as words 12/02/2002 * Hovik Function type being respected for String comparisons, Can say if [fn1(fn2(FIELD1)) = 'OK'] - = will change to .equals("OK") Can also put literal before comparison. if ['OK'= fn1(fn2(FIELD1))] 29/04/2002 * Hovik Add the word 'conditional' to exception message to help the user pinpoint the error command 05/07/2002 * Dave Removed use of Jeva, replaced with JEP thereby removing static expression evaluation. Comparison of strings in JEP works with == and !=, therefore processing to convert to .equals() required by Jeva removed. Under JEP functions do not need to be referenced as static calls i.e. Function.functionName, therefore processing to add Function. removed. Changed this method to be non-static, and all other methods in the Utility class. n.b. this method should now be re-written as use of the outer loop of a vector of tokens is not required. 19/07/2002 * Hovik Difficult to eliminate vector of tokens, due to the need to look ahead for NULL comparisons (see isCheckForNull) Improved runtime efficiency by performing parts of the code only when relevant. 15/08/2002 * Jon JEP initialisation and loading of functions removed from this method and placed in Form method initialiseJEPEnvironment(). This is now done just once when the form is initialised. 22/11/2002 * Hovik Jep fails if expression to be parsed contains newlines or "s or \"s Use class UfsJep to convert these to non-enterable characters, before calling jep - call jep, then convert them back 27/11/2002 * Hovik Use a non-enterable character to represent enclosing single quotes, so that those entered by the user remain as they are. 29/05/2003 * Jon Convert Doubles received from JEP to BigDecimal 09/07/2003 * Hovik Problem 377 - Use new method replaceStringUnlessInQuotes, so that quoted strings are not affected by the substitution. This is specifically to cope with new fprmat of goto commands

Throws:
com.ebasetech.ufs.kernel.FormException

extractParametersFromString

public java.util.HashMap extractParametersFromString(java.lang.String commandText,
                                                     com.ebasetech.ufs.kernel.StandaloneUFSComponent form,
                                                     boolean toUpperCase,
                                                     java.lang.String actionScriptId,
                                                     com.ebasetech.ufs.validation.Event event,
                                                     com.ebasetech.ufs.validation.Node node)
                                              throws com.ebasetech.ufs.kernel.FormException
Extracts key/value parameters from a command text string and constructs a HashMap consisting of entry with key = the key and value = the value for each key/value pair For example : input string of "GOTO FORM MYFORM abc=rt4, def=iuy" will result in HashMap with 2 entries : 1. key = abc, value = rt4 2. key = def, value = iuy In addition, the value field of each pair is checked to see whether it is a valid form field name. If it is, the value is replaced with the form field value. The toUpperCase boolean parameter controls whether the keys are transposed to upper case i.e. in the example above abc becomes ABC etc. Known calling classes : GotoFormCommand, GotoURLCommand 31/01/2002 * Jon * created 08/05/2002 * Hovik Use parseExpression instaed of tokeniser, to allow underscores 13/11/2002 * Hovik Simplified code. A parameter may be assigned simple values only(FPL rules) So there's no need to do any fancy stuff - if it's a form field get its presentation value, else the literal with "s removed. 27/11/2002 * Hovik In parseExpression(), we use a non-enterable character to represent enclosing single quotes, so that those entered by the user remain as they are. Now we need to get rid of them, before constructing url. 09/06/2004 * Jon Fix NullPointerException

Throws:
com.ebasetech.ufs.kernel.FormException

getFieldPresentationValue

public java.lang.String getFieldPresentationValue(java.lang.String fieldName,
                                                  com.ebasetech.ufs.kernel.StandaloneUFSComponent form,
                                                  com.ebasetech.ufs.validation.Event event,
                                                  com.ebasetech.ufs.validation.Node node)
                                           throws com.ebasetech.ufs.kernel.FormException
Method : getFieldPresentationValue Description : returns the script field value for the passed field name.

Throws:
com.ebasetech.ufs.kernel.FormException

getFieldValue

public java.lang.String getFieldValue(java.lang.String fieldName,
                                      com.ebasetech.ufs.kernel.StandaloneUFSComponent form,
                                      com.ebasetech.ufs.validation.Event event,
                                      com.ebasetech.ufs.validation.Node node)
                               throws com.ebasetech.ufs.kernel.FormException
Method : getFieldValue Description : returns the script field value for the passed field name.

Throws:
com.ebasetech.ufs.kernel.FormException

isCheckForNull

public boolean isCheckForNull(java.util.Vector tokens,
                              int posn)
Method : isCheckForNull Description : returns true if the follwoing operator is == or != and the right hand operand is NULL or Null or nuLL ... Creation date: (18/11/01 11:16:31)

Returns:
boolean

isFieldDateOrNumeric

public boolean isFieldDateOrNumeric(java.lang.String fieldName,
                                    com.ebasetech.ufs.kernel.StandaloneUFSComponent form,
                                    com.ebasetech.ufs.validation.Event event,
                                    com.ebasetech.ufs.validation.Node node)

isFormField

public boolean isFormField(java.lang.String fieldName,
                           com.ebasetech.ufs.kernel.StandaloneUFSComponent form,
                           com.ebasetech.ufs.validation.Event event,
                           com.ebasetech.ufs.validation.Node node)
Insert the method's description here. Creation date: (16/08/01 11:16:59) Change log 30/10/03 * Netta * Modified to take account of prefixed component field names

Returns:
boolean

getRelativeFieldName

public java.lang.String getRelativeFieldName(java.lang.String fieldName,
                                             com.ebasetech.ufs.validation.Event event,
                                             com.ebasetech.ufs.validation.Node node)

getRelativePageName

public java.lang.String getRelativePageName(java.lang.String pageName,
                                            com.ebasetech.ufs.validation.Event event,
                                            com.ebasetech.ufs.validation.Node node)

isFunction

public boolean isFunction(java.lang.String functionName,
                          com.ebasetech.ufs.kernel.StandaloneUFSComponent form)
                   throws com.ebasetech.ufs.kernel.FormException
Insert the method's description here. Creation date: (03/09/01 13:41:27)

Returns:
boolean 20/03/2002 * Jon * Changed functions to be case sensitive 09/07/2002 * Dave * Changed to use containsKey rather then instatiate a new object. Also, made function name lowercase on the lookup.
Throws:
com.ebasetech.ufs.kernel.FormException

isPage

public boolean isPage(java.lang.String pageName,
                      com.ebasetech.ufs.kernel.StandaloneUFSComponent form,
                      com.ebasetech.ufs.validation.Event event,
                      com.ebasetech.ufs.validation.Node node)
Insert the method's description here. Creation date: (16/08/01 11:16:59)

Returns:
boolean

isStringaDate

public boolean isStringaDate(java.lang.String s)
Method : isStringaDate Description : returns true if the parameter looks like a date. i.e. length 10 - 12 (including enclosing quotes) a / in posn 2 or 3 another / 2 or 3 chars later Creation date: (02/01/02 11:16:31)

Returns:
boolean

main

public static void main(java.lang.String[] args)

parseExpression

public void parseExpression(java.lang.String expression,
                            java.util.Vector tokens,
                            java.util.Vector ttypes,
                            java.lang.String actionScriptId)
                     throws com.ebasetech.ufs.kernel.FormException
Method : parseExpression Description : Break the expression into a vector, for later analysis A StreamTokenizer is used to parse the expression; Vector tokens is populated by the tokens with no substitution except for single quotes ' are replaced by " Vector ttypes is populated (one-to-one for tokens). This is used later, by evalIFExpression, for analysis, look ahead etc. Parameters : a string expression, Vector of tokens, Vector of token types Change log 14/11/2001 * Hovik started 29/11/2001 * Hovik Allow underscores in field names. 29/01/2002 * Hovik dots to be treated as delimters - passed to Jeva as is this method (previously called parseIf) is now used to parse both IF and value expresseions With intger constants, ensure an int (and not a double) is passed to Jeva 06/02/2002 * Hovik && and || no longer being treated as words 17/07/2002 * Hovik treat $ £ _ @ # ? as parts of words - remove redundant underscore logic 15/11/2002 * Hovik treat \ as a normal character - tokenizer changes \\ to \ 22/11/2002 * Hovik Introduced other escape characters 24/11/2002 * Hovik Within a literal, double quotes and enclosing single quotes are left as they are (until call to JEP) 27/11/2002 * Hovik Use a non-enterable character to represent enclosing single quote, so that those entered by the user remain as they are. 27/01/2003 * Hovik Comment out st.ordinaryChar('\t') to fix tabs within commands bug 24/02/2003 * Hovik Problem 366. Minus sign was being treated as part of field name 15/10/2003 * Jon Get special characters from Constants

Throws:
com.ebasetech.ufs.kernel.FormException

replaceString

public java.lang.String replaceString(java.lang.String inString,
                                      java.lang.String findString,
                                      java.lang.String replaceString)
Insert the method's description here. Creation date: (22/08/01 16:03:15)

Returns:
java.lang.String

replaceStringUnlessInQuotes

public java.lang.String replaceStringUnlessInQuotes(java.lang.String inString,
                                                    java.lang.String findString,
                                                    java.lang.String replaceString)
Insert the method's description here. Creation date: (09/07/03 14:01:15)

Returns:
java.lang.String

constructQMarkStringFor

public static java.lang.String constructQMarkStringFor(java.lang.String attrsString)
Builds a string like "?,?,?,?" to be used in a prepared statement.

Parameters:
attrsString - attribute string from the prepared statement, eg. "form_id, page_id"
Returns:
comma separated questionmark list, one questionmark for each attribute in the attrsString

setBooleanInSqlStmt

public static void setBooleanInSqlStmt(java.sql.PreparedStatement stmt,
                                       int position,
                                       boolean value)
                                throws java.sql.SQLException
Sets Y/N in the string value of prepared statement at the specified position depending on the supplied boolean value

Parameters:
stmt -
position -
value -
Throws:
java.sql.SQLException

getBooleanFromSqlStmt

public static boolean getBooleanFromSqlStmt(java.lang.String val)
Answers true/false depending on the char value of the supplied value


ExtractParametersFromResultSet

public static void ExtractParametersFromResultSet(java.sql.ResultSet rs,
                                                  java.lang.String columnName,
                                                  java.util.List target)
                                           throws java.sql.SQLException
Extract the comma separated parameters in the named column into the supplied target list

Throws:
java.sql.SQLException

ExtractParametersFromString

public static void ExtractParametersFromString(java.lang.String listString,
                                               java.util.List target)
Extract the comma separated parameters in the supplied string into the supplied target list


ExtractMapParametersFromResultSet

public static void ExtractMapParametersFromResultSet(java.sql.ResultSet rs,
                                                     java.lang.String columnName,
                                                     java.util.Map target)
                                              throws java.sql.SQLException
Extract the comma separated key-value pair parameters in the named column into the supplied target list

Throws:
java.sql.SQLException

ExtractMapParametersFromString

public static void ExtractMapParametersFromString(java.lang.String listString,
                                                  java.util.Map target)
Extract the comma separated key-value pair parameters in the supplied string into the supplied target list


BuildParameterString

public static java.lang.String BuildParameterString(java.util.Iterator parameters)
Given an iterator over a collection of strings, answer a single string containing those strings in a comma-separated list


BuildMapParameterString

public static java.lang.String BuildMapParameterString(java.util.Map params)
Given an iterator across a collection of key/value pairs, encode those pairs as a comma separated string value


FlattenParamsMap

public static java.lang.String FlattenParamsMap(java.util.Map paramsMap)
flatten the params map into a string of comma separated key-value pairs.


UnflattenParamsMap

public static java.util.HashMap UnflattenParamsMap(java.lang.String flattenedParams)
unpacks the parameters map from the flattened form


GetCharacterStreamFromResultSet

public static java.lang.String GetCharacterStreamFromResultSet(java.sql.ResultSet rs,
                                                               java.lang.String columnName)
                                                        throws java.io.IOException,
                                                               java.sql.SQLException
extracts a character stream from the result set for the given DB column name

Throws:
java.io.IOException
java.sql.SQLException