Version 4.10.0

hirondelle.web4j.request
Class RequestParameter

Object
  extended by hirondelle.web4j.request.RequestParameter

public final class RequestParameter
extends Object

Request parameter as a name and (usually) an associated regular expression.

This class does not directly provide access to the parameter value. For such services, please see RequestParser and ModelFromRequest.

This class separates request parameters into two kinds : file upload request parameters, and all others (here called "regular" request parameters).

Regular Request Parameters
Regular request parameters are associated with :

File Upload Request Parameters
Files are uploaded using forms having :

In addition, note that the Servlet API does not have extensive services for processing file upload parameters. It is likely best to use a third party tool for that task.

File upload request parameters, as represented by this class, have only a name associated with them, and no regular expression. This is because WEB4J cannot perform hard validation on the value of a file upload parameter - since the user may select any file whatsoever, validation of file contents can only be treated as a soft validation. If there is a problem, the response to the user must be polished, as part of the normal operation of the application.

As an example, an Action might perform soft validation on a file upload parameter for these items :

Naming Convention
Parameter names are usually not arbitrary in WEB4J. Instead, a simple convention is used which allows for automated mapping between request parameter names and corresponding getXXX methods of Model Objects (see Populate). For example, a parameter named 'Birth Date' (or 'birthDate') is mapped to a method named getBirthDate() when prepopulating a form with the contents of a Model Object. (The 'Birth Date' naming style is recommended, since it has this advantage : when messages regarding form input are presented to the user, the control name may be used directly, without trivial mapping of a 'coder-friendly' parameter name into more user-friendly text.)

Some parameters - notably those passed to Template.jsp - are not processed at all by the Controller, but are used directly in JSPs instead. Such parameters do not undergo hard validation by the ApplicationFirewall, and are not represented by this class.

See Pattern for more information on regular expressions.


Method Summary
 boolean equals(Object aThat)
           
static RequestParameter forFileUpload(String aName)
          Constructor for a file upload request parameter.
 String getName()
          Return the request parameter name.
 Pattern getRegex()
          Return the regular expression associated with this RequestParameter.
 int hashCode()
           
 boolean isFileUploadParameter()
          Return true only if forFileUpload(java.lang.String) was used to build this object.
 boolean isValidParamValue(String aRawParamValue)
          Return true only if aRawParamValue satisfies the regular expression getRegex(), or if this is a file upload request parameter.
 String toString()
          Intended for debugging only.
static RequestParameter withLengthCheck(String aName)
          Return a regular parameter hard-validated only for name and size.
static RequestParameter withRegexCheck(String aName, Pattern aValueRegex)
          Return a regular parameter hard-validated for name and for value matching a regular expression.
static RequestParameter withRegexCheck(String aName, String aValueRegex)
          Return a regular parameter hard-validated for name and for value matching a regular expression.
 
Methods inherited from class Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Method Detail

withLengthCheck

public static RequestParameter withLengthCheck(String aName)
Return a regular parameter hard-validated only for name and size.

The size is taken from the MaxRequestParamValueSize setting in web.xml.

Parameters:
aName - name of the underlying HTTP request parameter. See naming convention.

withRegexCheck

public static RequestParameter withRegexCheck(String aName,
                                              Pattern aValueRegex)
Return a regular parameter hard-validated for name and for value matching a regular expression.

Parameters:
aName - name of the underlying HTTP request parameter. See naming convention.
aValueRegex - regular expression for doing hard validation of the request parameter value(s).

withRegexCheck

public static RequestParameter withRegexCheck(String aName,
                                              String aValueRegex)
Return a regular parameter hard-validated for name and for value matching a regular expression.

Parameters:
aName - name of the underlying HTTP request parameter. See naming convention.
aValueRegex - regular expression for doing hard validation of the request parameter value(s).

forFileUpload

public static RequestParameter forFileUpload(String aName)
Constructor for a file upload request parameter.

Parameters:
aName - name of the underlying HTTP request parameter. See naming convention.

getName

public String getName()
Return the request parameter name.


getRegex

public Pattern getRegex()
Return the regular expression associated with this RequestParameter.

This regular expression is used to perform hard validation of this parameter's value(s).

This method will return null only for file upload parameters.


isFileUploadParameter

public boolean isFileUploadParameter()
Return true only if forFileUpload(java.lang.String) was used to build this object.


isValidParamValue

public boolean isValidParamValue(String aRawParamValue)
Return true only if aRawParamValue satisfies the regular expression getRegex(), or if this is a file upload request parameter.

Always represents a hard validation, not a soft validation.


equals

public boolean equals(Object aThat)
Overrides:
equals in class Object

hashCode

public int hashCode()
Overrides:
hashCode in class Object

toString

public String toString()
Intended for debugging only.

Overrides:
toString in class Object

Version 4.10.0

Copyright Hirondelle Systems. Published October 19, 2013 - User Guide - All Docs.