com.acciente.commons.htmlform
Class Parser

java.lang.Object
  extended by com.acciente.commons.htmlform.Parser

public class Parser
extends Object

This class implements a parser that parses the parameters (and data) submitted in an HTML form and populates a Map with the form data.

Author:
Adinath Raveendra Raj

Constructor Summary
Parser()
           
 
Method Summary
static void addParameter2Form(Map oForm, ParameterSpec oParameterSpec, org.apache.commons.fileupload.FileItem oFileItem)
          This method is not a typical entry point into the parser.
static void addParameter2Form(Map oForm, ParameterSpec oParameterSpec, String sData, boolean bURLEncoded)
          This method is not a typical entry point into the parser.
static Map parseForm(javax.servlet.http.HttpServletRequest oRequest, int iStoreFileOnDiskThresholdInBytes, File oUploadedFileStorageDir)
          This method parses all the parameters contained in the http servlet request, in particular it parses and merges parameters from the sources listed below.
static Map parseForm(Reader oInput, boolean bURLEncoded)
          This method parses a character stream containing an HTML form encoded using the application/x-www-form-urlencoded scheme.
static ParameterSpec parseParameterSpec(Reader oReader)
          This method is not typicaly used by applications.
static ParameterSpec parseParameterSpec(Reader oReader, String sDefaultType)
          This method is not typicaly used by applications.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Parser

public Parser()
Method Detail

parseForm

public static Map parseForm(javax.servlet.http.HttpServletRequest oRequest,
                            int iStoreFileOnDiskThresholdInBytes,
                            File oUploadedFileStorageDir)
                     throws ParserException,
                            IOException,
                            org.apache.commons.fileupload.FileUploadException
This method parses all the parameters contained in the http servlet request, in particular it parses and merges parameters from the sources listed below. If a parameter is defined in more than on source the higher numbered source below prevails. 1 - parameters in the URL's query query string (GET params) 2 - parameters submitted using POST including multi-part parameters such as fileuploads

Parameters:
oRequest - a http servlet request object
iStoreFileOnDiskThresholdInBytes - a file size in bytes above which the uploaded file will be stored on disk
oUploadedFileStorageDir - a File object representing a path to which the uploaded files should be saved, if null is specified a temporary directory is created in the java system temp directory path
Returns:
a map containing the paramater names and values, the paramter names are keys in the map
Throws:
ParserException - thrown if there is an error parsing the parameter data
IOException - thrown if there is an I/O error
org.apache.commons.fileupload.FileUploadException - thrown if there is an error processing the multi-part data

parseForm

public static Map parseForm(Reader oInput,
                            boolean bURLEncoded)
                     throws ParserException,
                            IOException
This method parses a character stream containing an HTML form encoded using the application/x-www-form-urlencoded scheme. This parser does not handle multi-part data streams

Parameters:
oInput - the character stream containg the encoded HTML form
bURLEncoded - if true the data value in the form are assumed to be URL encoded and the parser will decoded the values
Returns:
a map with a key for each form parameter with respective map value containing the data value of the parameter
Throws:
ParserException - if there was an error parsing the HTML form
IOException - if there was an error reading the input character stream

parseParameterSpec

public static ParameterSpec parseParameterSpec(Reader oReader)
                                        throws ParserException,
                                               IOException
This method is not typicaly used by applications. It is used to parse out the structure of the parameter name according to the supported syntax. One use of this method is to process the parameter names in a multi-part stream to enable the full parameter syntax supported by this parser for multi-part datastream that is being processed using a separate multi-part parser such as the Apache's FileUpload mutli-part parser.

Parameters:
oReader - a character stream containing the parameter, this stream will read until either the end of the stream is reached or until a TOKEN_EQUALS is encountered
Returns:
a ParameterSpec structure describing the structure of the parameter
Throws:
ParserException - if there was an error parsing the HTML form
IOException - if there was an error reading the input character stream

parseParameterSpec

public static ParameterSpec parseParameterSpec(Reader oReader,
                                               String sDefaultType)
                                        throws ParserException,
                                               IOException
This method is not typicaly used by applications. It is used to parse out the structure of the parameter name according to the supported syntax. One use of this method is to process the parameter names in a multi-part stream to enable the full parameter syntax supported by this parser for multi-part datastream that is being processed using a separate multi-part parser such as the Apache's FileUpload mutli-part parser.

Parameters:
oReader - a character stream containing the parameter, this stream will read until either the end of the stream is reached or until a TOKEN_EQUALS is encountered
sDefaultType - specifies the parameter type that the parser should assume in the absence of a explicit parameter type in the paramater spec's string definition (read via the passed in oReader), the value must be null or one of the following values: string, int, float, boolean, file (the most current set is defined in com.acciente.commons.htmlform.Symbols). If null is specified the string type is assumed
Returns:
a ParameterSpec structure describing the structure of the parameter
Throws:
ParserException - if there was an error parsing the HTML form
IOException - if there was an error reading the input character stream

addParameter2Form

public static void addParameter2Form(Map oForm,
                                     ParameterSpec oParameterSpec,
                                     String sData,
                                     boolean bURLEncoded)
                              throws ParserException,
                                     UnsupportedEncodingException
This method is not a typical entry point into the parser. It is provided for use in conjunction with parseParameterSpec() to store a data value into a java map based on the structure in a ParameterSpec object

Parameters:
oForm - a Map into which the data should be stored
oParameterSpec - the parameter spec according to which the data value will be stored in the map
sData - the data value to be stored in the map
bURLEncoded - true if the data value is in URL encoded form and needs to be decoded before storing into the map
Throws:
ParserException - thrown if the parameter spec will cause an overwrite of an existing value or if the parameter spec is in an unexpected format
UnsupportedEncodingException - if there was an exception thrown during any URL decoding that was attempted

addParameter2Form

public static void addParameter2Form(Map oForm,
                                     ParameterSpec oParameterSpec,
                                     org.apache.commons.fileupload.FileItem oFileItem)
                              throws ParserException,
                                     UnsupportedEncodingException
This method is not a typical entry point into the parser. It is provided for use in conjunction with parseParameterSpec() to store a data value into a java map based on the structure in a ParameterSpec object

Parameters:
oForm - a Map into which the data should be stored
oParameterSpec - the parameter spec according to which the data value will be stored in the map
oFileItem - an uploaded file containing the data to be stored in the map
Throws:
ParserException - thrown if the parameter spec will cause an overwrite of an existing value or if the parameter spec is in an unexpected format
UnsupportedEncodingException - if there was an exception thrown during any URL decoding that was attempted


Copyright © 2008-2013 Acciente, LLC. All Rights Reserved.