Class DefaultCookieParser

  • All Implemented Interfaces:
    Iterable<String>, org.apache.avalon.framework.logger.LogEnabled, CookieParser, ParserServiceSupport, ValueParser

    public class DefaultCookieParser
    extends BaseValueParser
    implements CookieParser
    CookieParser is used to get and set values of Cookies on the Client Browser. You can use CookieParser to convert Cookie values to various types or to set Bean values with setParameters(). See the Servlet Spec for more information on Cookies.

    Use set() or unset() to Create or Destroy Cookies.

    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:

     CookieParser cp = data.getCookies();
     cp.add("ERROR",1);
     cp.add("eRrOr",2);
     int result = cp.getInt("ERROR");
     
    In the above example, result is 2.
    Version:
    $Id$
    Author:
    Ilkka Priha, Leon Messerschmidt, Thomas Vandahl
    • Method Detail

      • setData

        public void setData​(HttpServletRequest request,
                            HttpServletResponse response)
        Sets the servlet request and response to be parsed. All previous cookies will be cleared.
        Specified by:
        setData in interface CookieParser
        Parameters:
        request - the servlet request object.
        response - the servlet response object
      • set

        public void set​(String name,
                        String value)
        Set a cookie that will be stored on the client for the duration of the session.
        Specified by:
        set in interface CookieParser
        Parameters:
        name - The name of the cookie
        value - The value of the cooking
      • set

        public void set​(String name,
                        String value,
                        int secondsAge)
        Description copied from interface: CookieParser
        Set a persistent cookie on the client that will expire after a maximum age (given in seconds).
        Specified by:
        set in interface CookieParser
        Parameters:
        name - A String for the name
        value - A String for the value
        secondsAge - An int for the age in seconds
      • unset

        public void unset​(String name)
        Description copied from interface: CookieParser
        Remove a previously set cookie from the client machine.
        Specified by:
        unset in interface CookieParser
        Parameters:
        name - the name of the cooking to unset