Class DefaultParameterParser

java.lang.Object
org.apache.fulcrum.parser.BaseValueParser
org.apache.fulcrum.parser.DefaultParameterParser
All Implemented Interfaces:
Iterable<String>, org.apache.avalon.framework.logger.LogEnabled, ParameterParser, ParserServiceSupport, ValueParser

public class DefaultParameterParser extends BaseValueParser implements ParameterParser
DefaultParameterParser is a utility object to handle parsing and retrieving the data passed via the GET/POST/PATH_INFO arguments.

NOTE: The name= portion of a name=value pair may be converted to lowercase or uppercase when the object is initialized and when new data is added. This behaviour is determined by the url.case.folding property in TurbineResources.properties. Adding a name/value pair may overwrite existing name=value pairs if the names match:

 ParameterParser pp = data.getParameters();
 pp.add("ERROR",1);
 pp.add("eRrOr",2);
 int result = pp.getInt("ERROR");
 
In the above example, result is 2.
Version:
$Id$
Author:
Ilkka Priha, Jon S. Stevens, Sean Legassick, Jürgen Hoffmann
  • Constructor Details

    • DefaultParameterParser

      public DefaultParameterParser()
      Create a new empty instance of ParameterParser. Uses the default character encoding (US-ASCII).

      To add name/value pairs to this set of parameters, use the add() methods.

    • DefaultParameterParser

      public DefaultParameterParser(String characterEncoding)
      Create a new empty instance of ParameterParser. Takes a character encoding name to use when converting strings to bytes.

      To add name/value pairs to this set of parameters, use the add() methods.

      Parameters:
      characterEncoding - The character encoding of strings.
  • Method Details

    • dispose

      public void dispose()
      Disposes the parser.
      Specified by:
      dispose in interface ValueParser
      Overrides:
      dispose in class BaseValueParser
    • getRequest

      public jakarta.servlet.http.HttpServletRequest getRequest()
      Gets the parsed servlet request.
      Specified by:
      getRequest in interface ParameterParser
      Returns:
      the parsed servlet request or null.
    • setRequest

      public void setRequest(jakarta.servlet.http.HttpServletRequest request)
      Sets the servlet request to the parser. This requires a valid HttpServletRequest object. It will attempt to parse out the GET/POST/PATH_INFO data and store the data into a Map. There are convenience methods for retrieving the data as a number of different datatypes. The PATH_INFO data must be a URLEncoded() string.

      Sets the request character encoding to the parser.

      Sets the request encoding, if it is not set and ParserService.getParameterEncoding() is set to a non-default value ParserService.PARAMETER_ENCODING_DEFAULT (if ServletRequest.getCharacterEncoding() returns null, it has the default set to ISO-8859-1, cft. Servlet 2.4, 2.5, 3.0, 3.1 Specs). This will only succeed, if no data was read yet, cft. spec.

      To add name/value pairs to this set of parameters, use the add() methods.

      Specified by:
      setRequest in interface ParameterParser
      Parameters:
      request - An HttpServletRequest.
    • handleEncoding

      protected void handleEncoding(jakarta.servlet.http.HttpServletRequest request)
    • setUploadData

      public void setUploadData(byte[] uploadData)
      Sets the uploadData byte[]
      Specified by:
      setUploadData in interface ParameterParser
      Parameters:
      uploadData - A byte[] with data.
    • getUploadData

      public byte[] getUploadData()
      Gets the uploadData byte[]
      Specified by:
      getUploadData in interface ParameterParser
      Returns:
      uploadData A byte[] with data.
    • add

      public void add(String name, jakarta.servlet.http.Part value)
      Add a Part object as a parameters. If there are any Parts already associated with the name, append to the array. The reason for this is that RFC 1867 allows multiple files to be associated with single HTML input element.
      Specified by:
      add in interface ParameterParser
      Parameters:
      name - A String with the name.
      value - A Part with the value.
    • getPart

      public jakarta.servlet.http.Part getPart(String name)
      Description copied from interface: ParameterParser
      Return a Part object for the given name. If the name does not exist or the object stored is not a Part, return null.
      Specified by:
      getPart in interface ParameterParser
      Parameters:
      name - A String with the name.
      Returns:
      A Part.
      See Also:
    • getParts

      public jakarta.servlet.http.Part[] getParts(String name)
      Description copied from interface: ParameterParser
      Return an array of Part objects for the given name. If the name does not exist or the object stored is not a Part array, return null.
      Specified by:
      getParts in interface ParameterParser
      Parameters:
      name - A String with the name.
      Returns:
      A Part[]
      See Also:
    • getParts

      public Collection<jakarta.servlet.http.Part> getParts()
      Description copied from interface: ParameterParser
      Return an array of all Part objects. If no parts exist or the object stored is not a Part array, return an empty list.
      Specified by:
      getParts in interface ParameterParser
      Returns:
      Collection Collection of parts
    • getFileName

      public String getFileName(jakarta.servlet.http.Part part)
      Description copied from interface: ParameterParser
      Convenience fileName utility, which extracts the filename from header
      Specified by:
      getFileName in interface ParameterParser
      Parameters:
      part - The part which represents the uploaded file
      Returns:
      the fileName String object.