com.instantbank.common.utilcomponents
Class CommonUtil

java.lang.Object
  |
  +--com.instantbank.common.utilcomponents.CommonUtil

public class CommonUtil
extends java.lang.Object

Various general algorithms implemented as static methods.

Author:
InstantBank (Consuelo Franky, Rodrigo Lopez)

Field Summary
private static Debug debug
           
static int OK
          A verification is OK.
 
Constructor Summary
CommonUtil()
           
 
Method Summary
(package private) static void ()
           
static void cleanTemporaldirectory(java.io.File dirPath)
          Delete files from a temporal directory and all its subdirectories, excepting those with extensions ".log" or ".war".
static void cleanTemporaldirectory(java.lang.String pathName)
          Delete files from a temporal directory and its subdirectories, excepting those with extensions ".log" or ".war".
static boolean controlTimeout(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, javax.servlet.ServletContext context)
          control time out in a servlet when it is invoked several times without MVC participation, and in a separate window
static java.lang.String getApplicationProperty(java.lang.String nameJNDI)
          gets the value of an application property (of String type)
static java.lang.String getUserId(javax.servlet.http.HttpServletRequest req)
          find the current user from the HttpServletRequest:
static java.util.Hashtable getWebContextVariable(javax.servlet.ServletContext context, java.lang.String variableName)
          method for instantiating and returning a context variable that is a Hashtable with an entry for each company
static boolean isUserInRole(javax.servlet.http.HttpServletRequest req, java.lang.String rol)
          determine if the current user belongs to a role
static boolean isWorkableDay(java.util.Date selectedDate, java.lang.String companyCalendar)
          Determine if a selected Date is a workable day or not in a company calendar
static oracle.xml.parser.v2.XMLDocument parseInfo(java.lang.String xmlData)
          Auxiliary method for building a XMLDocument from a XML string method for building a XMLDocument from a XML string
static java.util.Vector parseKeywords(java.lang.String keywordString, java.util.Locale locale)
          parsing of a string composed of words
static void putVariableInContext(javax.servlet.ServletContext context, java.lang.String companyId, java.lang.String tableName, java.lang.Object variableValue)
          method for putting the value of a company variable in a Hashtable context variable (with an entry for each company)
static void putVariableInRequest(javax.servlet.http.HttpServletRequest request, javax.servlet.ServletContext context, java.lang.String companyId, java.lang.String tableName, java.lang.String variableName)
          method for putting in the current request, a company variable obtained from a Hashtable context variable (with an entry for each company)
static java.lang.String stackTraceToString(java.lang.Throwable thw)
          Produces --as a String-- the "stacktrace" corresponding to a Throwable object (exceptions, errors).
static java.lang.String toSafeJavaString(java.lang.String in)
          Method for transforming a String with special characters in a Java String.
static java.lang.String toSafeOracleString(java.lang.String in)
          Method for transforming in a String the ' character in '' characters in order to be understood by Oracle
static java.util.Date workableOffset(java.util.Date selectedDate, int offset, java.util.Hashtable companyCalendars)
          Add a workable offset (positive or negative) to a selected date, accordingly to the calendars of a company.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

OK

public static final int OK
A verification is OK.

debug

private static Debug debug
Constructor Detail

CommonUtil

public CommonUtil()
Method Detail

static void ()

getWebContextVariable

public static java.util.Hashtable getWebContextVariable(javax.servlet.ServletContext context,
                                                        java.lang.String variableName)
method for instantiating and returning a context variable that is a Hashtable with an entry for each company
Parameters:
context - web context
variableName - name of context variable (according to WebKeys enumeration)
Returns:
Hashtable of the context variable

putVariableInContext

public static void putVariableInContext(javax.servlet.ServletContext context,
                                        java.lang.String companyId,
                                        java.lang.String tableName,
                                        java.lang.Object variableValue)
method for putting the value of a company variable in a Hashtable context variable (with an entry for each company)
Parameters:
context - web context
companyId - current company id
tableName - name of Hashtable context variable (according to WebKeys enumeration)
variableValue - value of the company variable

putVariableInRequest

public static void putVariableInRequest(javax.servlet.http.HttpServletRequest request,
                                        javax.servlet.ServletContext context,
                                        java.lang.String companyId,
                                        java.lang.String tableName,
                                        java.lang.String variableName)
method for putting in the current request, a company variable obtained from a Hashtable context variable (with an entry for each company)
Parameters:
request - current request
context - web context
companyId - current company number
tableName - name of Hahtable context variable (according to WebKeys enumeration)
variableName - name of the company variable (according to WebKeys enumeration)

stackTraceToString

public static java.lang.String stackTraceToString(java.lang.Throwable thw)
Produces --as a String-- the "stacktrace" corresponding to a Throwable object (exceptions, errors).
Parameters:
thw - The throwed object.
Returns:
string corrsponding to stacktrace

cleanTemporaldirectory

public static void cleanTemporaldirectory(java.lang.String pathName)
Delete files from a temporal directory and its subdirectories, excepting those with extensions ".log" or ".war".
Parameters:
pathName - Full path of the directory.

cleanTemporaldirectory

public static void cleanTemporaldirectory(java.io.File dirPath)
Delete files from a temporal directory and all its subdirectories, excepting those with extensions ".log" or ".war".
Parameters:
dirPath - Directory "abstract" path.

getUserId

public static java.lang.String getUserId(javax.servlet.http.HttpServletRequest req)
                                  throws java.lang.Exception
find the current user from the HttpServletRequest:
Parameters:
req - request
Returns:
The userId value
Throws:
java.lang.Exception -  

isUserInRole

public static boolean isUserInRole(javax.servlet.http.HttpServletRequest req,
                                   java.lang.String rol)
                            throws java.lang.Exception
determine if the current user belongs to a role
Parameters:
req - HTTP request
rol - J2EE role
Returns:
The userInRole value
Throws:
java.lang.Exception -  

parseInfo

public static oracle.xml.parser.v2.XMLDocument parseInfo(java.lang.String xmlData)
                                                  throws oracle.xml.parser.v2.XMLParseException,
                                                         oracle.xml.parser.v2.XSLException,
                                                         org.xml.sax.SAXException,
                                                         java.io.IOException
Auxiliary method for building a XMLDocument from a XML string method for building a XMLDocument from a XML string
Parameters:
xmlData - xml string
Returns:
XMLDocument corresponding to xmlData
Throws:
oracle.xml.parser.v2.XMLParseException -  
oracle.xml.parser.v2.XSLException -  
org.xml.sax.SAXException -  
java.io.IOException -  

parseKeywords

public static java.util.Vector parseKeywords(java.lang.String keywordString,
                                             java.util.Locale locale)
parsing of a string composed of words
Parameters:
keywordString - string with words
locale - language
Returns:
Vector with words

toSafeJavaString

public static java.lang.String toSafeJavaString(java.lang.String in)
Method for transforming a String with special characters in a Java String.
Parameters:
in - is the string with special characters.
Returns:
another String with the special characters transformed.

toSafeOracleString

public static java.lang.String toSafeOracleString(java.lang.String in)
Method for transforming in a String the ' character in '' characters in order to be understood by Oracle
Parameters:
in - is the string with special characters.
Returns:
another String with the special characters transformed.

controlTimeout

public static boolean controlTimeout(javax.servlet.http.HttpServletRequest request,
                                     javax.servlet.http.HttpServletResponse response,
                                     javax.servlet.ServletContext context)
                              throws java.io.IOException,
                                     javax.servlet.ServletException
control time out in a servlet when it is invoked several times without MVC participation, and in a separate window
Parameters:
request - HTTP request
response - HTTP response
context - Description of the Parameter
Returns:
true if timeout; false otherwise
Throws:
java.io.IOException -  
javax.servlet.ServletException -  

getApplicationProperty

public static java.lang.String getApplicationProperty(java.lang.String nameJNDI)
gets the value of an application property (of String type)
Parameters:
nameJNDI - JNDI name of the property
Returns:
corresponding String

isWorkableDay

public static boolean isWorkableDay(java.util.Date selectedDate,
                                    java.lang.String companyCalendar)
Determine if a selected Date is a workable day or not in a company calendar
Parameters:
selectedDate - selected Date to determine if it is workable day or not
companyCalendar - company calendar corresponding to year of selectedDate; each day of year is a character : 'P' is it is workable(processing) day, 'N' otherwise
Returns:
true is selectedDate is workable day, false otherwise

workableOffset

public static java.util.Date workableOffset(java.util.Date selectedDate,
                                            int offset,
                                            java.util.Hashtable companyCalendars)
Add a workable offset (positive or negative) to a selected date, accordingly to the calendars of a company.
Parameters:
selectedDate - selected Date
companyCalendars - hash table of company calendars: key: year (Integer), value: String representing the year calendar (each day of year is a character : 'P' is it is workable(processing) day, 'N' otherwise)
offset - Description of the Parameter
Returns:
Date corresponding to selectedDate + offset in workable days (null if it can not be calculated because companyCalendars are incomplete)