com.devsphere.mapping
Class ServletFormData

java.lang.Object
  |
  +--com.devsphere.mapping.FormData
        |
        +--com.devsphere.mapping.ServletFormData

public class ServletFormData
extends FormData

Wrapper of javax.servlet.http.HttpServletRequest that implements the methods of the FormData abstract class. This class constitutes the bridge between the mapping framework and the Servlet API. The framework's architecture allows you to plug-in your own implementations of FormData if necessary. Also this class adds optional support for "multipart/form-data".

The Servlet API does not support the "multipart/form-data" encoding type, which is necessary for file uploading. The ServletFormData class can parse the input stream of the wrapped javax.servlet.http.HttpServletRequest to get a parameter set that includes string, string arrays, FileBean objects and FileBean arrays.

The used "multipart/form-data" parser is provided by JavaMail and it wasn't designed for uploading large files. The uploaded files are decoded and their content is kept in memory. Therefore, the file-uploading feature should be used only when reasonable amounts of data need to be transferred for in-memory processing.

To enable the "multipart/form-data" parsing, you must use the constructor of ServletFormData that accepts two parameters, pass a HttpServletRequest object whose content-type starts with "multipart/form-data" and the second parameter (allowMultipart) must be true. If these conditions aren't met the multipart parser isn't enabled, the getParameter*() methods are delegated to the HttpServletRequest object and the getFileParameter*() methods return null (or an empty enumeration in the case of getFileParameterNames()).

See Also:
FormData

Constructor Summary
ServletFormData(javax.servlet.http.HttpServletRequest request)
          Creates the wrapper of a servlet request.
ServletFormData(javax.servlet.http.HttpServletRequest request, boolean allowMultipart)
          Creates the wrapper of a servlet request.
 
Method Summary
 FileBean getFileParameter(java.lang.String name)
          Gets the value of a file parameter as a FileBean, or null if the parameter is missing or is not an uploaded file.
 java.util.Enumeration getFileParameterNames()
          Gets an Enumeration of String objects, containing the names of the file parameters.
 FileBean[] getFileParameterValues(java.lang.String name)
          Gets the values of a file parameter as a FileBean[], or null if the parameter is missing or is not a list of uploaded files.
 java.lang.String getParameter(java.lang.String name)
          Gets the value of a request parameter as a String, or null if the parameter is missing or is an uploaded file.
 java.util.Enumeration getParameterNames()
          Gets an Enumeration of String objects, containing the names of the request parameters.
 java.lang.String[] getParameterValues(java.lang.String name)
          Gets the values of a request parameter as a String[], or null if the parameter is missing or is a list of uploaded file.
 javax.servlet.http.HttpServletRequest getRequest()
          Gets the servlet request wrapped by this object.
 boolean isMultipartFormData()
          Returns true if the encoding type is "multipart/form-data" and it is allowed.
 java.lang.String toString()
          Returns a string representation of this object containing the list of request parameters and the names of the uploaded files.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ServletFormData

public ServletFormData(javax.servlet.http.HttpServletRequest request)
Creates the wrapper of a servlet request. The multipart parser isn't enabled. The getParameterNames(), getParameter() and getParameterValues() methods are delegated to the HttpServletRequest object. The getFileParameterNames() method will return an empty enumeration. The getFileParameter() and getFileParameterValues() methods will return null.
Parameters:
request - the servlet request.
Throws:
NullPointerException - if request is null.

ServletFormData

public ServletFormData(javax.servlet.http.HttpServletRequest request,
                       boolean allowMultipart)
                throws java.io.IOException
Creates the wrapper of a servlet request. This constructor should be used only if the "multipart/form-data" encoding type must be supported in addition to "application/x-www-form-urlencoded". The multipart parser is enabled only if content-type starts with "multipart/form-data" and allowMultipart is true.
Parameters:
request - the servlet request.
allowMultipart - true enables the multipart parser.
Throws:
NullPointerException - if request is null.
java.io.IOException - if the request parameters were encoded using the multipart/form-data media type and an error occurs during the parsing of the input stream.
InternalError - if the multipart/form-data parser isn't found.
Method Detail

getRequest

public javax.servlet.http.HttpServletRequest getRequest()
Gets the servlet request wrapped by this object.
Returns:
the servlet request wrapped by this object.

isMultipartFormData

public boolean isMultipartFormData()
Returns true if the encoding type is "multipart/form-data" and it is allowed.

getParameterNames

public java.util.Enumeration getParameterNames()
Gets an Enumeration of String objects, containing the names of the request parameters. The parameter names of the uploaded files are not included. The enumeration is empty if the request has no parameters or it has only uploaded files.
Overrides:
getParameterNames in class FormData
Returns:
the enumeration of the names of the request parameters.

getParameter

public java.lang.String getParameter(java.lang.String name)
Gets the value of a request parameter as a String, or null if the parameter is missing or is an uploaded file.
Overrides:
getParameter in class FormData
Parameters:
name - the name of the request parameter.
Returns:
the first (maybe unique) string value of the parameter.
Throws:
NullPointerException - if name is null.

getParameterValues

public java.lang.String[] getParameterValues(java.lang.String name)
Gets the values of a request parameter as a String[], or null if the parameter is missing or is a list of uploaded file.
Overrides:
getParameterValues in class FormData
Parameters:
name - the name of the request parameter.
Returns:
a string array containing all of the values the parameter has.
Throws:
NullPointerException - if name is null.

getFileParameterNames

public java.util.Enumeration getFileParameterNames()
Gets an Enumeration of String objects, containing the names of the file parameters. The enumeration is empty if the request has no file parameters.
Overrides:
getFileParameterNames in class FormData
Returns:
the enumeration of the names of the file parameters.

getFileParameter

public FileBean getFileParameter(java.lang.String name)
Gets the value of a file parameter as a FileBean, or null if the parameter is missing or is not an uploaded file.
Overrides:
getFileParameter in class FormData
Parameters:
name - the name of the file parameter.
Returns:
the first (maybe unique) file value of the parameter.
Throws:
NullPointerException - if name is null.

getFileParameterValues

public FileBean[] getFileParameterValues(java.lang.String name)
Gets the values of a file parameter as a FileBean[], or null if the parameter is missing or is not a list of uploaded files.
Overrides:
getFileParameterValues in class FormData
Parameters:
name - the name of the file parameter.
Returns:
a FileBean array containing all of the values the parameter has.
Throws:
NullPointerException - if name is null.

toString

public java.lang.String toString()
Returns a string representation of this object containing the list of request parameters and the names of the uploaded files.
Overrides:
toString in class java.lang.Object
Returns:
a string representation of this object.