com.cinecolombia.common.utilcomponents
Class CommonUtil

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

public class CommonUtil
extends java.lang.Object

Various general algorithms implemented as static methods.

Author:
CincoSOFT
Created:
Junio 2003

Field Summary
private static Debug debug
           
static int OK
          A verification is OK.
 
Constructor Summary
CommonUtil()
           
 
Method Summary
static boolean allNull(java.lang.Object[] arr)
          Decide si un arreglo de Objetos solamente contiene valores nulos.
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 fixedLengthString(java.lang.String cadena, int longitudDisplay)
          obtiene una cadena para HTML restringida a una longitud maxima, truncadola o ampliandola con blancos.
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: NOTE: another similar method is request.getRemoteUser();
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 oracle.xml.parser.v2.XMLDocument parseInfo(java.lang.String xmlData)
          Auxiliary method for building a XMLDocument from a XML string
static java.util.List 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.util.Date rightNow()
          Method for getting the current time
static java.util.Set setOfZipEntryNames(java.util.zip.ZipInputStream zin)
          Calcula el conjunto de nombres de las entradas (archivos o directorios) de un ZipInputStream
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[] stringToArray(java.lang.String s, java.lang.String separador)
          Convierte una cadena de caracteres, con tokens separados por un separador, en un arreglo de tokens en el mismo orden en el que aparecen en la cadena.
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
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

OK

public static final int OK
A verification is OK.

See Also:
Constant Field Values

debug

private static Debug debug
Constructor Detail

CommonUtil

public CommonUtil()
Method Detail

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 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 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: NOTE: another similar method is request.getRemoteUser();

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

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.List parseKeywords(java.lang.String keywordString,
                                           java.util.Locale locale)
parsing of a string composed of words

Parameters:
keywordString - string with words
locale - language
Returns:
List 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.

rightNow

public static java.util.Date rightNow()
Method for getting the current time

Returns:
a Date with the current time.

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

stringToArray

public static java.lang.String[] stringToArray(java.lang.String s,
                                               java.lang.String separador)
Convierte una cadena de caracteres, con tokens separados por un separador, en un arreglo de tokens en el mismo orden en el que aparecen en la cadena.

Parameters:
s - Description of the Parameter
separador - Description of the Parameter
Returns:
Description of the Return Value

allNull

public static boolean allNull(java.lang.Object[] arr)
Decide si un arreglo de Objetos solamente contiene valores nulos.

Parameters:
arr - Description of the Parameter
Returns:
Description of the Return Value

setOfZipEntryNames

public static java.util.Set setOfZipEntryNames(java.util.zip.ZipInputStream zin)
                                        throws java.io.IOException
Calcula el conjunto de nombres de las entradas (archivos o directorios) de un ZipInputStream

Parameters:
zin - The new ofZipEntryNames value
Returns:
Description of the Return Value
Throws:
java.io.IOException - Description of the Exception

fixedLengthString

public static java.lang.String fixedLengthString(java.lang.String cadena,
                                                 int longitudDisplay)
obtiene una cadena para HTML restringida a una longitud maxima, truncadola o ampliandola con blancos.

Parameters:
cadena - cadena a restringir
longitudDisplay - que debe tener la cadena restringida
Returns:
la cadena restringida