org.apache.turbine.util.parser
Class DefaultCookieParser

java.lang.Object
  extended byorg.apache.turbine.util.pool.RecyclableSupport
      extended byorg.apache.turbine.util.parser.BaseValueParser
          extended byorg.apache.turbine.util.parser.DefaultCookieParser
All Implemented Interfaces:
CookieParser, Recyclable, ValueParser

public class DefaultCookieParser
extends BaseValueParser
implements CookieParser, Recyclable

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: DefaultCookieParser.java 534527 2007-05-02 16:10:59Z tv $
Author:
Ilkka Priha, Leon Messerschmidt, Henning P. Schmiedehausen

Field Summary
 
Fields inherited from interface org.apache.turbine.util.parser.CookieParser
AGE_DELETE, AGE_SESSION
 
Fields inherited from interface org.apache.turbine.util.parser.ValueParser
URL_CASE_FOLDING, URL_CASE_FOLDING_LOWER, URL_CASE_FOLDING_NONE, URL_CASE_FOLDING_UPPER
 
Constructor Summary
DefaultCookieParser()
          Constructs a new CookieParser.
 
Method Summary
 void dispose()
          Disposes the parser.
 URI getCookiePath()
          Get the Path where cookies will be stored
 javax.servlet.http.HttpServletRequest getRequest()
          Gets the Request Object for this parser.
 RunData getRunData()
          Deprecated. Don't use the Run Data object. use getRequest().
 void set(java.lang.String name, java.lang.String value)
          Set a cookie that will be stored on the client for the duration of the session.
 void set(java.lang.String name, java.lang.String value, int seconds_age)
          Set a persisten cookie on the client that will expire after a maximum age (given in seconds).
 void setCookiePath(URI cookiePath)
          Set the path for cookie storage
 void setData(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
          Sets Request and Response to be parsed.
 void setRunData(RunData data)
          Sets the RunData to be parsed.
 void unset(java.lang.String name)
          Remove a previously set cookie from the client machine.
 
Methods inherited from class org.apache.turbine.util.parser.BaseValueParser
add, add, add, add, add, add, append, clear, containsDateSelectorKeys, containsKey, containsTimeSelectorKeys, convert, convertAndTrim, get, getBigDecimal, getBigDecimal, getBigDecimals, getBool, getBool, getBoolean, getBoolean, getBooleanObject, getBooleanObject, getBooleanObjects, getBooleans, getByte, getByte, getByteObject, getByteObject, getBytes, getCharacterEncoding, getDate, getDate, getDate, getDateFormat, getDouble, getDouble, getDoubleObject, getDoubleObject, getDoubleObjects, getDoubles, getFloat, getFloat, getFloatObject, getFloatObject, getFloatObjects, getFloats, getInt, getInt, getInteger, getInteger, getInteger, getIntegers, getIntObject, getIntObject, getIntObjects, getInts, getKeys, getLocale, getLong, getLong, getLongObject, getLongObject, getLongObjects, getLongs, getNumberFormat, getNumberKey, getObject, getObjects, getParam, getString, getString, getStringKey, getStrings, getStrings, getToStringParam, keys, keySet, putParam, recycle, remove, setCharacterEncoding, setDateFormat, setLocale, setNumberFormat, setProperties, setProperty, setString, setStrings, toString
 
Methods inherited from class org.apache.turbine.util.pool.RecyclableSupport
doDispose, isDisposed, Recyclable, recycle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.apache.turbine.util.parser.ValueParser
add, add, add, add, add, add, append, clear, containsDateSelectorKeys, containsKey, convert, get, getBigDecimal, getBigDecimal, getBigDecimals, getBool, getBool, getBoolean, getBoolean, getBooleanObject, getBooleanObject, getBooleanObjects, getBooleans, getByte, getByte, getByteObject, getByteObject, getBytes, getCharacterEncoding, getDate, getDate, getDate, getDateFormat, getDouble, getDouble, getDoubleObject, getDoubleObject, getDoubleObjects, getDoubles, getFloat, getFloat, getFloatObject, getFloatObject, getFloatObjects, getFloats, getInt, getInt, getInteger, getInteger, getInteger, getIntegers, getIntObject, getIntObject, getIntObjects, getInts, getKeys, getLocale, getLong, getLong, getLongObject, getLongObject, getLongObjects, getLongs, getNumberFormat, getNumberKey, getObject, getObjects, getString, getString, getStringKey, getStrings, getStrings, keys, keySet, remove, setCharacterEncoding, setDateFormat, setLocale, setNumberFormat, setProperties, setString, setStrings, toString
 
Methods inherited from interface org.apache.turbine.util.pool.Recyclable
isDisposed, recycle
 

Constructor Detail

DefaultCookieParser

public DefaultCookieParser()
Constructs a new CookieParser.

Method Detail

dispose

public void dispose()
Disposes the parser.

Specified by:
dispose in interface Recyclable
Overrides:
dispose in class BaseValueParser

getRunData

public RunData getRunData()
Deprecated. Don't use the Run Data object. use getRequest().

Gets the parsed RunData.

Specified by:
getRunData in interface CookieParser
Returns:
the parsed RunData object or null.

getRequest

public javax.servlet.http.HttpServletRequest getRequest()
Gets the Request Object for this parser.

Specified by:
getRequest in interface CookieParser
Returns:
the HttpServletRequest or null.

setRunData

public void setRunData(RunData data)
Sets the RunData to be parsed. This is a convenience method to set the request and response from the RunData object. It is equivalent to
  setData(data.getRequest(), data.getResponse());
 
All previous cookies will be cleared.

Specified by:
setRunData in interface CookieParser
Parameters:
data - the RunData object.

setData

public void setData(javax.servlet.http.HttpServletRequest request,
                    javax.servlet.http.HttpServletResponse response)
Sets Request and Response to be parsed.

All previous cookies will be cleared.

Specified by:
setData in interface CookieParser
Parameters:
request - The http request from the servlet
response - The http reponse from the servlet

getCookiePath

public URI getCookiePath()
Get the Path where cookies will be stored

Specified by:
getCookiePath in interface CookieParser
Returns:
path for cookie storage

setCookiePath

public void setCookiePath(URI cookiePath)
Set the path for cookie storage

Specified by:
setCookiePath in interface CookieParser
Parameters:
cookiePath - path for cookie storage

set

public void set(java.lang.String name,
                java.lang.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 - name of the cookie
value - value of the cookie

set

public void set(java.lang.String name,
                java.lang.String value,
                int seconds_age)
Set a persisten cookie on the client that will expire after a maximum age (given in seconds).

Specified by:
set in interface CookieParser
Parameters:
name - name of the cookie
value - value of the cookie
seconds_age - max age of the cookie in seconds

unset

public void unset(java.lang.String name)
Remove a previously set cookie from the client machine.

Specified by:
unset in interface CookieParser
Parameters:
name - name of the cookie


Copyright © 2000-2008 Apache Software Foundation. All Rights Reserved.