com.acsinet_solutions.cetia4.controller
Class RequestUtils

java.lang.Object
  extended by com.acsinet_solutions.cetia4.controller.RequestUtils

public class RequestUtils
extends java.lang.Object

This class provides useful utility methods for manually reading information from an HTTP request.

Methods in this class may throw validation exceptions. The texts in this class are normally generated using the bundles associated to the com.acsinet_solutions.util.text.GlobalMessages class. Currently spanish and english messages are provided, but new ones may be created under the com.acsinet_solutions.util.text.global_messages bundle. Messages are interpreted when written, for example in ForEachIssueTag, so the messages may be associated to alternative output strings if necessary.

More automatic mapping utilities are provided by the framework using the com.acsinet_solutions.cetia4.controller.map.RequestMapper API.

Author:
Santiago Arriaga
See Also:
GlobalMessages, ForEachIssueTag, RequestMapper

Constructor Summary
RequestUtils()
           
 
Method Summary
static java.lang.String filterBigDecimal(java.lang.String value)
          Filter undesired characters on BigDecimal input.
static java.math.BigDecimal getBigDecimal(ParameterAccessor request, java.lang.String parameterName, java.lang.String readableName)
          Return a valid BigDecimal value from the request.
static java.math.BigDecimal getBigDecimal(javax.servlet.ServletRequest request, java.lang.String parameterName, java.lang.String readableName)
          Return a valid BigDecimal value from the request.
static java.math.BigDecimal getBigDecimal(java.lang.String value, java.lang.String readableName)
          Return a valid BigDecimal value from the request.
static java.util.Calendar getCalendar(ParameterAccessor request, java.lang.String parameterName, java.lang.String readableName, java.text.DateFormat format)
          Return a valid Calendar value from the request
static java.util.Calendar getCalendar(ParameterAccessor request, java.lang.String dayParam, java.lang.String monthParam, java.lang.String yearParam)
          Obtain a calendar instance from a request
static java.util.Calendar getCalendar(javax.servlet.ServletRequest request, java.lang.String parameterName, java.lang.String readableName, java.text.DateFormat format)
          Return a valid Calendar value from the request
static java.util.Calendar getCalendar(javax.servlet.ServletRequest request, java.lang.String dayParam, java.lang.String monthParam, java.lang.String yearParam)
          Obtain a calendar instance from a request
static java.util.Date getDate(ParameterAccessor request, java.lang.String parameterName, java.lang.String readableName, java.text.DateFormat format)
          Return a valid Date value from the request.
static java.util.Date getDate(javax.servlet.ServletRequest request, java.lang.String parameterName, java.lang.String readableName, java.text.DateFormat format)
          Return a valid Date value from the request.
static int getInt(ParameterAccessor request, java.lang.String parameterName)
          Return a valid int value from the request
static int getInt(ParameterAccessor request, java.lang.String parameterName, java.lang.String readableName)
          Return a valid int value from the request
static int getInt(javax.servlet.ServletRequest request, java.lang.String parameterName)
          Return a valid int value from the request
static int getInt(javax.servlet.ServletRequest request, java.lang.String parameterName, java.lang.String readableName)
          Return a valid int value from the request
static int getInt(java.lang.String value, java.lang.String readableName)
          Return a valid int value from the given value
static java.lang.Integer getInteger(ParameterAccessor request, java.lang.String parameterName, java.lang.String readableName)
          Return a valid maybe-null Integer value from the request
static java.lang.Integer getInteger(javax.servlet.ServletRequest request, java.lang.String parameterName, java.lang.String readableName)
          Return a valid not-null Integer value from the request
static java.lang.Integer getInteger(java.lang.String value, java.lang.String readableName)
          Return a valid maybe-null Integer value from the request
static java.util.Calendar getNotNullCalendar(ParameterAccessor request, java.lang.String parameterName, java.lang.String readableName, java.text.DateFormat format)
          Return a valid Calendar value from the request
static java.util.Calendar getNotNullCalendar(javax.servlet.ServletRequest request, java.lang.String parameterName, java.lang.String readableName, java.text.DateFormat format)
          Return a valid not null Calendar value from the request
static java.lang.Integer getNotNullInteger(ParameterAccessor request, java.lang.String parameterName)
          Return a valid not-null Integer value from the request
static java.lang.Integer getNotNullInteger(ParameterAccessor request, java.lang.String parameterName, java.lang.String readableName)
          Return a valid not-null Integer value from the request
static java.lang.Integer getNotNullInteger(javax.servlet.ServletRequest request, java.lang.String parameterName)
          Return a valid not-null Integer value from the request
static java.lang.Integer getNotNullInteger(javax.servlet.ServletRequest request, java.lang.String parameterName, java.lang.String readableName)
          Return a valid maybe-null Integer value from the request
static java.lang.Integer getNotNullInteger(java.lang.String value, java.lang.String readableName)
          Return a valid not-null Integer value from the request
static java.lang.String getNotNullString(ParameterAccessor request, java.lang.String parameterName, java.lang.String readableName)
          Return a not-null String value from the request
static java.lang.String getNotNullString(javax.servlet.ServletRequest request, java.lang.String parameterName, java.lang.String readableName)
          Return a not-null String value from the request
static java.lang.String getNotNullString(java.lang.String value, java.lang.String readableName)
          Return a not-null String value from a string.
static void setDefaultBigDecimalFilterCharacters(java.lang.String chars)
          Set the default filter characters for the big decimal mapping performed.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

RequestUtils

public RequestUtils()
Method Detail

setDefaultBigDecimalFilterCharacters

public static void setDefaultBigDecimalFilterCharacters(java.lang.String chars)
                                                 throws SyntaxException
Set the default filter characters for the big decimal mapping performed. This is commonly tried to be set during the locale configuration of the application in ControllerTools.initLocaleAndBundle() method.

Throws:
SyntaxException - Thrown if a regultar expression for the given characters could not be created.
See Also:
ControllerTools.initLocaleAndBundle(ServletContext)

filterBigDecimal

public static java.lang.String filterBigDecimal(java.lang.String value)
Filter undesired characters on BigDecimal input.


getNotNullString

public static java.lang.String getNotNullString(java.lang.String value,
                                                java.lang.String readableName)
                                         throws ValidationException
Return a not-null String value from a string. This only validates that the provided value is not null.

Parameters:
value - A maybe-null String value
Throws:
ValidationException

getNotNullString

public static java.lang.String getNotNullString(javax.servlet.ServletRequest request,
                                                java.lang.String parameterName,
                                                java.lang.String readableName)
                                         throws ValidationException
Return a not-null String value from the request

Throws:
ValidationException

getNotNullString

public static java.lang.String getNotNullString(ParameterAccessor request,
                                                java.lang.String parameterName,
                                                java.lang.String readableName)
                                         throws ValidationException
Return a not-null String value from the request

Throws:
ValidationException

getNotNullInteger

public static java.lang.Integer getNotNullInteger(java.lang.String value,
                                                  java.lang.String readableName)
                                           throws ValidationException
Return a valid not-null Integer value from the request

Throws:
ValidationException

getNotNullInteger

public static java.lang.Integer getNotNullInteger(javax.servlet.ServletRequest request,
                                                  java.lang.String parameterName)
                                           throws ValidationException
Return a valid not-null Integer value from the request

Throws:
ValidationException

getNotNullInteger

public static java.lang.Integer getNotNullInteger(ParameterAccessor request,
                                                  java.lang.String parameterName)
                                           throws ValidationException
Return a valid not-null Integer value from the request

Throws:
ValidationException

getInteger

public static java.lang.Integer getInteger(java.lang.String value,
                                           java.lang.String readableName)
                                    throws ValidationException
Return a valid maybe-null Integer value from the request

Throws:
ValidationException

getInteger

public static java.lang.Integer getInteger(javax.servlet.ServletRequest request,
                                           java.lang.String parameterName,
                                           java.lang.String readableName)
                                    throws ValidationException
Return a valid not-null Integer value from the request

Throws:
ValidationException

getInteger

public static java.lang.Integer getInteger(ParameterAccessor request,
                                           java.lang.String parameterName,
                                           java.lang.String readableName)
                                    throws ValidationException
Return a valid maybe-null Integer value from the request

Throws:
ValidationException

getNotNullInteger

public static java.lang.Integer getNotNullInteger(javax.servlet.ServletRequest request,
                                                  java.lang.String parameterName,
                                                  java.lang.String readableName)
                                           throws ValidationException
Return a valid maybe-null Integer value from the request

Throws:
ValidationException

getNotNullInteger

public static java.lang.Integer getNotNullInteger(ParameterAccessor request,
                                                  java.lang.String parameterName,
                                                  java.lang.String readableName)
                                           throws ValidationException
Return a valid not-null Integer value from the request

Throws:
ValidationException

getInt

public static int getInt(java.lang.String value,
                         java.lang.String readableName)
                  throws ValidationException
Return a valid int value from the given value

Throws:
ValidationException

getInt

public static int getInt(javax.servlet.ServletRequest request,
                         java.lang.String parameterName,
                         java.lang.String readableName)
                  throws ValidationException
Return a valid int value from the request

Throws:
ValidationException

getInt

public static int getInt(ParameterAccessor request,
                         java.lang.String parameterName,
                         java.lang.String readableName)
                  throws ValidationException
Return a valid int value from the request

Throws:
ValidationException

getInt

public static int getInt(javax.servlet.ServletRequest request,
                         java.lang.String parameterName)
                  throws ValidationException
Return a valid int value from the request

Throws:
ValidationException

getInt

public static int getInt(ParameterAccessor request,
                         java.lang.String parameterName)
                  throws ValidationException
Return a valid int value from the request

Throws:
ValidationException

getNotNullCalendar

public static java.util.Calendar getNotNullCalendar(javax.servlet.ServletRequest request,
                                                    java.lang.String parameterName,
                                                    java.lang.String readableName,
                                                    java.text.DateFormat format)
                                             throws ValidationException
Return a valid not null Calendar value from the request

Throws:
ValidationException

getNotNullCalendar

public static java.util.Calendar getNotNullCalendar(ParameterAccessor request,
                                                    java.lang.String parameterName,
                                                    java.lang.String readableName,
                                                    java.text.DateFormat format)
                                             throws ValidationException
Return a valid Calendar value from the request

Throws:
ValidationException

getCalendar

public static java.util.Calendar getCalendar(javax.servlet.ServletRequest request,
                                             java.lang.String parameterName,
                                             java.lang.String readableName,
                                             java.text.DateFormat format)
                                      throws ValidationException
Return a valid Calendar value from the request

Throws:
ValidationException

getCalendar

public static java.util.Calendar getCalendar(ParameterAccessor request,
                                             java.lang.String parameterName,
                                             java.lang.String readableName,
                                             java.text.DateFormat format)
                                      throws ValidationException
Return a valid Calendar value from the request

Throws:
ValidationException

getCalendar

public static final java.util.Calendar getCalendar(javax.servlet.ServletRequest request,
                                                   java.lang.String dayParam,
                                                   java.lang.String monthParam,
                                                   java.lang.String yearParam)
                                            throws ValidationException
Obtain a calendar instance from a request

Parameters:
request - A not-null HttpServletRequest instance
dayParam - A not-null not-empty String representing the day parameter
monthParam - A not-null not-empty String representing the month parameter
yearParam - A not-null not-empty String representing the year parameter
Returns:
A Calendar instance if it could be obtained; null otherwise
Throws:
ValidationException

getCalendar

public static final java.util.Calendar getCalendar(ParameterAccessor request,
                                                   java.lang.String dayParam,
                                                   java.lang.String monthParam,
                                                   java.lang.String yearParam)
                                            throws ValidationException
Obtain a calendar instance from a request

Parameters:
request - A not-null HttpServletRequest instance
dayParam - A not-null not-empty String representing the day parameter
monthParam - A not-null not-empty String representing the month parameter
yearParam - A not-null not-empty String representing the year parameter
Returns:
A Calendar instance if it could be obtained; null otherwise
Throws:
ValidationException

getDate

public static java.util.Date getDate(javax.servlet.ServletRequest request,
                                     java.lang.String parameterName,
                                     java.lang.String readableName,
                                     java.text.DateFormat format)
                              throws ValidationException
Return a valid Date value from the request. This method synchronizes over the format object

Returns:
A Date object according to the given input; null if the input parameter is null, empty or space-filled.
Throws:
ValidationException

getDate

public static java.util.Date getDate(ParameterAccessor request,
                                     java.lang.String parameterName,
                                     java.lang.String readableName,
                                     java.text.DateFormat format)
                              throws ValidationException
Return a valid Date value from the request. This method synchronizes over the format object

Returns:
A Date object according to the given input; null if the input parameter is null, empty or space-filled.
Throws:
ValidationException

getBigDecimal

public static java.math.BigDecimal getBigDecimal(javax.servlet.ServletRequest request,
                                                 java.lang.String parameterName,
                                                 java.lang.String readableName)
                                          throws ValidationException
Return a valid BigDecimal value from the request.

Throws:
ValidationException

getBigDecimal

public static java.math.BigDecimal getBigDecimal(ParameterAccessor request,
                                                 java.lang.String parameterName,
                                                 java.lang.String readableName)
                                          throws ValidationException
Return a valid BigDecimal value from the request.

Throws:
ValidationException

getBigDecimal

public static java.math.BigDecimal getBigDecimal(java.lang.String value,
                                                 java.lang.String readableName)
                                          throws ValidationException
Return a valid BigDecimal value from the request.

Throws:
ValidationException