HDIV API 2.0.4

org.hdiv.util
Class HDIVUtil

java.lang.Object
  extended by org.hdiv.util.HDIVUtil

public class HDIVUtil
extends java.lang.Object

Class containing utility methods for access HDIV components: IDataComposer, IDataValidator, IApplication, ISession.

This class is initialized from a Listener and a Filter.

Author:
Roberto Velasco, Gorka Vicente

Constructor Summary
HDIVUtil()
           
 
Method Summary
static java.lang.String actionName(javax.servlet.http.HttpServletRequest request)
          Return the URL representing the current request.
static java.lang.String composeAction(java.lang.String url, int questionIndex, java.lang.String charEncoding)
           It generates a new encoded values for the url parameters.
static java.lang.String createRandomToken(int n)
          Generates a random number between 0 (inclusive) and n (exclusive).
static java.lang.String getActionMappingName(java.lang.String url)
          Return the form action converted into an action mapping path.
static IApplication getApplication()
           
static IDataComposer getDataComposer()
           
static IDataComposer getDataComposer(javax.servlet.http.HttpServletRequest request)
          Returns data composer object from request.
static java.lang.String getDataComposerName()
           
static IDataValidator getDataValidator()
           
static javax.servlet.http.HttpSession getHttpSession()
           
static java.lang.String getMessage(java.lang.String key)
          Try to resolve the message.
static java.lang.String getMessage(java.lang.String key, java.lang.String o)
          Try to resolve the message.
static java.lang.String getMessage(java.lang.String key, java.lang.String o, java.util.Locale userLocale)
          Try to resolve the message.
static UidGenerator getRandomTokenGenerator()
           
static javax.servlet.ServletContext getServletContext()
           
static ISession getSession()
           
static void initFactory()
          Find the root WebApplicationContext for this web app, which is typically loaded via ContextLoaderListener or ContextLoaderServlet.
static java.lang.String protectCharacters(java.lang.String par)
          Function to protect meaningful characters of regular expressions (+,*,...)
static java.net.URL requestURL(javax.servlet.http.HttpServletRequest request)
          Return the URL representing the current request.
static void resetLocalData()
          ThreadLocales is always guaranteed to be cleaned up when returning the thread to the server's pool.
static void setHttpSession(javax.servlet.http.HttpSession httpSession2)
           
static void setServletContext(javax.servlet.ServletContext servletContext)
           
static void setSession(ISession sessionHDIV)
          Only for testing.
static java.lang.String stripSession(java.lang.String url)
          Strips a servlet session ID from url.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

HDIVUtil

public HDIVUtil()
Method Detail

resetLocalData

public static void resetLocalData()
ThreadLocales is always guaranteed to be cleaned up when returning the thread to the server's pool.


getDataComposer

public static IDataComposer getDataComposer(javax.servlet.http.HttpServletRequest request)
Returns data composer object from request. If it is null, it returns data composer from thread local.

Parameters:
request - HTTP servlet request
Returns:
Returns data composer object
Since:
HDIV 2.0.3

getDataComposer

public static IDataComposer getDataComposer()
Returns:
Returns data composer object

getDataValidator

public static IDataValidator getDataValidator()
Returns:
Returns data validator object

getSession

public static ISession getSession()
Returns:
Returns http session wrapper object

setSession

public static void setSession(ISession sessionHDIV)
Only for testing.

Parameters:
sessionHDIV - The session to set.

getServletContext

public static javax.servlet.ServletContext getServletContext()
Returns:
Returns the servlet context that the request runs in.

setServletContext

public static void setServletContext(javax.servlet.ServletContext servletContext)
Parameters:
servletContext - the ServletContext that the request runs in.

initFactory

public static void initFactory()
Find the root WebApplicationContext for this web app, which is typically loaded via ContextLoaderListener or ContextLoaderServlet.

See Also:
WebApplicationContextUtils.getRequiredWebApplicationContext(javax.servlet.ServletContext)

getApplication

public static IApplication getApplication()
Returns:
Returns the servlet context wrapper object.

getHttpSession

public static javax.servlet.http.HttpSession getHttpSession()

setHttpSession

public static void setHttpSession(javax.servlet.http.HttpSession httpSession2)

getMessage

public static java.lang.String getMessage(java.lang.String key)
Try to resolve the message. Treat as an error if the message can't be found.

Parameters:
key - the code to lookup up, such as 'calculator.noRateSet'
Returns:
The resolved message

getMessage

public static java.lang.String getMessage(java.lang.String key,
                                          java.lang.String o)
Try to resolve the message. Treat as an error if the message can't be found.

Parameters:
key - the code to lookup up, such as 'calculator.noRateSet'
o - Array of arguments that will be filled in for params within the message (params look like "{0}", "{1,date}", "{2,time}" within a message), or null if none.
Returns:
The resolved message

getMessage

public static java.lang.String getMessage(java.lang.String key,
                                          java.lang.String o,
                                          java.util.Locale userLocale)
Try to resolve the message. Treat as an error if the message can't be found.

Parameters:
key - the code to lookup up, such as 'calculator.noRateSet'
o - Array of arguments that will be filled in for params within the message (params look like "{0}", "{1,date}", "{2,time}" within a message), or null if none.
userLocale - locale
Returns:
The resolved message

getActionMappingName

public static java.lang.String getActionMappingName(java.lang.String url)
Return the form action converted into an action mapping path. The value of the action property is manipulated as follows in computing the name of the requested mapping:

Parameters:
url - URL representing the current request
Returns:
the form action converted into an action mapping path.

stripSession

public static java.lang.String stripSession(java.lang.String url)
Strips a servlet session ID from url. The session ID is encoded as a URL "path parameter" beginning with "jsessionid=". We thus remove anything we find between ";jsessionid=" (inclusive) and either EOS or a subsequent ';' (exclusive).


actionName

public static java.lang.String actionName(javax.servlet.http.HttpServletRequest request)
                                   throws java.lang.Exception
Return the URL representing the current request.

Parameters:
request - The servlet request we are processing
Returns:
URL representing the current request
Throws:
java.lang.Exception - if a URL cannot be created

requestURL

public static java.net.URL requestURL(javax.servlet.http.HttpServletRequest request)
                               throws java.net.MalformedURLException
Return the URL representing the current request. This is equivalent to HttpServletRequest.getRequestURL() in Servlet 2.3.

Parameters:
request - The servlet request we are processing
Returns:
URL representing the current request
Throws:
java.net.MalformedURLException - if a URL cannot be created

protectCharacters

public static java.lang.String protectCharacters(java.lang.String par)
Function to protect meaningful characters of regular expressions (+,*,...)

Parameters:
par - Parameter to encode
Returns:
Returns par with protected characters

composeAction

public static java.lang.String composeAction(java.lang.String url,
                                             int questionIndex,
                                             java.lang.String charEncoding)

It generates a new encoded values for the url parameters.

The returned values guarantees the confidentiality in the encoded and memory strategies if confidentiality indicator defined by user is true.

Parameters:
url - request url
questionIndex - index of the first question occurrence in url string
charEncoding - character encoding
Returns:
url with encoded values

createRandomToken

public static java.lang.String createRandomToken(int n)
Generates a random number between 0 (inclusive) and n (exclusive).

Parameters:
n - the bound on the random number to be returned. Must be positive.
Returns:
Returns a pseudorandom, uniformly distributed int value between 0 (inclusive) and n (exclusive).
Since:
HDIV 1.1

getDataComposerName

public static java.lang.String getDataComposerName()
Returns:
Returns the dataComposerName.
Since:
HDIV 2.0

getRandomTokenGenerator

public static UidGenerator getRandomTokenGenerator()
Returns:
Returns random token generator.
Since:
HDIV 2.0.4

HDIV 2.0.4

Copyright © 2008 hdiv.org. All Rights Reserved.