Package lazyj

Class RequestWrapper

java.lang.Object
lazyj.RequestWrapper

public final class RequestWrapper
extends java.lang.Object
This utility class is adapted for JSP use, offering easy access to the parameters and file uploading.
Since:
Oct 16, 2007 (1.0.2)
Author:
costing
  • Constructor Summary

    Constructors 
    Constructor Description
    RequestWrapper​(javax.servlet.http.HttpServletRequest request)
    Initialize the class with a HttpServletRequest
  • Method Summary

    Modifier and Type Method Description
    java.lang.String esc​(java.lang.String sName)
    Get the SQL-safe value of this parameter
    boolean getb​(java.lang.String sName, boolean bDefault)
    Get the boolean value
    java.lang.String getCookie​(java.lang.String sName)
    Get the value of a specific cookie
    double getd​(java.lang.String sParam)
    Get the value of a parameter as a double value.
    double getd​(java.lang.String sParam, double defaultVal)
    Get the value of a parameter as a double value.
    float getf​(java.lang.String sParam)
    Get the value of a parameter as a float value.
    float getf​(java.lang.String sParam, float defaultVal)
    Get the value of a parameter as a float value.
    static java.lang.String getHTTPDate​(java.util.Date d)
    get the http-style formatted date
    int geti​(java.lang.String sParam)
    Get the value of a parameter as an integer value.
    int geti​(java.lang.String sParam, int defaultVal)
    Get the value of a parameter as an integer value.
    long getl​(java.lang.String sParam)
    Get the value of a parameter as a long value.
    long getl​(java.lang.String sParam, long defaultVal)
    Get the value of a parameter as a long value.
    java.lang.String gets​(java.lang.String sParam)
    Get the value of a parameter as a string.
    java.lang.String gets​(java.lang.String sParam, java.lang.String sDefault)
    Get the value of a parameter as a string
    java.lang.String[] getValues​(java.lang.String sParam)
    Get all the values of a parameter.
    com.oreilly.servlet.MultipartRequest initMultipartRequest​(java.lang.String sTempDir, int iFileSizeLimit)
    This method should be called when the servlet expects a file upload from the client.
    static void setCacheTimeout​(javax.servlet.http.HttpServletResponse response, int seconds)
    Set the caching timeout for some generated content.
    static void setNotCache​(javax.servlet.http.HttpServletResponse response)
    Make this response uncacheable by the browser / proxies on the way

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • RequestWrapper

      public RequestWrapper​(javax.servlet.http.HttpServletRequest request)
      Initialize the class with a HttpServletRequest
      Parameters:
      request -
  • Method Details

    • initMultipartRequest

      public com.oreilly.servlet.MultipartRequest initMultipartRequest​(java.lang.String sTempDir, int iFileSizeLimit)
      This method should be called when the servlet expects a file upload from the client. It will initialize the internal mlRequest object. If the file is too big or there is another problem uploading the file then the method will return false, if everything is ok then it will return true.
      Parameters:
      sTempDir - temporary folder for the files that are uploaded
      iFileSizeLimit - maximum size of a file
      Returns:
      true if the request is indeed a file upload, the file size is <= iFileSizeLimit and the weather outside is fine
    • getValues

      public java.lang.String[] getValues​(java.lang.String sParam)
      Get all the values of a parameter.
      Parameters:
      sParam -
      Returns:
      values array, possibly empty but never null
    • gets

      public java.lang.String gets​(java.lang.String sParam)
      Get the value of a parameter as a string.
      Parameters:
      sParam - the parameter name
      Returns:
      the string value of this parameter, never null ("" is returned in the worst case)
    • gets

      public java.lang.String gets​(java.lang.String sParam, java.lang.String sDefault)
      Get the value of a parameter as a string
      Parameters:
      sParam - parameter name
      sDefault - default value to return in case the parameter is not defined or has no value ("")
      Returns:
      value
    • geti

      public int geti​(java.lang.String sParam, int defaultVal)
      Get the value of a parameter as an integer value. If there is a parsing error then return the given default value.
      Parameters:
      sParam - the name of the parameter
      defaultVal - default value to return in case of an error
      Returns:
      parsed value of the parameter, or the defaultValue if parameter is missing or is not an integer value representation
    • geti

      public int geti​(java.lang.String sParam)
      Get the value of a parameter as an integer value. If there is a parsing error then the value 0 will be returned.
      Parameters:
      sParam - name of the parameter
      Returns:
      parsed value of the request parameter, or 0 if there is any error in parsing, parameter not existing etc
    • getl

      public long getl​(java.lang.String sParam, long defaultVal)
      Get the value of a parameter as a long value. If there is a parsing error then return the given default value.
      Parameters:
      sParam - the name of the parameter
      defaultVal - default value to return in case of an error
      Returns:
      parsed value of the parameter, or the defaultValue if parameter is missing or is not a long value representation
    • getl

      public long getl​(java.lang.String sParam)
      Get the value of a parameter as a long value. If there is a parsing error then the value 0 will be returned.
      Parameters:
      sParam - name of the parameter
      Returns:
      parsed value of the request parameter, or 0 if there is any error in parsing, parameter not existing etc
    • getf

      public float getf​(java.lang.String sParam, float defaultVal)
      Get the value of a parameter as a float value. If there is a parsing error then return the given default value.
      Parameters:
      sParam - the name of the parameter
      defaultVal - default value to return in case of an error
      Returns:
      parsed value of the parameter, or the defaultValue if parameter is missing or is not a float value representation
    • getf

      public float getf​(java.lang.String sParam)
      Get the value of a parameter as a float value. If there is a parsing error then the value 0 will be returned.
      Parameters:
      sParam - name of the parameter
      Returns:
      parsed value of the request parameter, or 0 if there is any error in parsing, parameter not existing etc
    • getd

      public double getd​(java.lang.String sParam, double defaultVal)
      Get the value of a parameter as a double value. If there is a parsing error then return the given default value.
      Parameters:
      sParam - the name of the parameter
      defaultVal - default value to return in case of an error
      Returns:
      parsed value of the parameter, or the defaultValue if parameter is missing or is not a double value representation
    • getd

      public double getd​(java.lang.String sParam)
      Get the value of a parameter as a double value. If there is a parsing error then the value 0 will be returned.
      Parameters:
      sParam - name of the parameter
      Returns:
      parsed value of the request parameter, or 0 if there is any error in parsing, parameter not existing etc
    • getCookie

      public java.lang.String getCookie​(java.lang.String sName)
      Get the value of a specific cookie
      Parameters:
      sName - the name of the cookie
      Returns:
      the value of the cookie, or "" if there was an error (cookie not existing ...)
    • getb

      public boolean getb​(java.lang.String sName, boolean bDefault)
      Get the boolean value
      Parameters:
      sName - parameter name
      bDefault - default value
      Returns:
      true/false, obviously :)
    • esc

      public java.lang.String esc​(java.lang.String sName)
      Get the SQL-safe value of this parameter
      Parameters:
      sName - URL parameter name
      Returns:
      SQL-safe value of the given URL parameter
    • setNotCache

      public static void setNotCache​(javax.servlet.http.HttpServletResponse response)
      Make this response uncacheable by the browser / proxies on the way
      Parameters:
      response -
    • setCacheTimeout

      public static void setCacheTimeout​(javax.servlet.http.HttpServletResponse response, int seconds)
      Set the caching timeout for some generated content.
      Parameters:
      response - the response object
      seconds - expiration time, in seconds relative to "now". A strict positive value would enable the caching while a zero or negative one would disable the caching.
    • getHTTPDate

      public static java.lang.String getHTTPDate​(java.util.Date d)
      get the http-style formatted date
      Parameters:
      d -
      Returns:
      http-style formatted date