All Packages Class Hierarchy This Package Previous Next Index
Class com.oreilly.servlet.CookieParser
java.lang.Object
|
+----com.oreilly.servlet.CookieParser
- public class CookieParser
- extends Object
A class to simplify cookie retrieval. It can retrieve cookie values by
name and return the value as any primitive type (no casting or parsing
required). It can also throw an exception when a cookie is not found
(simplifying error handling), and can accept default values (eliminating
error handling).
It is used like this:
CookieParser parser = new CookieParser(req);
float ratio = parser.getFloatCookie("ratio", 1.0);
int count = 0;
try {
count = parser.getIntCookie("count");
}
catch (NumberFormatException e) {
handleMalformedCount();
}
catch (CookieNotFoundException e) {
handleNoCount();
}
- Version:
- 1.0, 2000/03/19
- Author:
- Jason Hunter, Copyright © 2000
- See Also:
- CookieNotFoundException
-
CookieParser(HttpServletRequest)
- Constructs a new CookieParser to handle the cookies of the
given request.
-
getBooleanCookie(String)
- Gets the named cookie value as a boolean
-
getBooleanCookie(String, boolean)
- Gets the named cookie value as a boolean, with a default.
-
getByteCookie(String)
- Gets the named cookie value as a byte
-
getByteCookie(String, byte)
- Gets the named cookie value as a byte, with a default.
-
getCharCookie(String)
- Gets the named cookie value as a char
-
getCharCookie(String, char)
- Gets the named cookie value as a char, with a default.
-
getDoubleCookie(String)
- Gets the named cookie value as a double
-
getDoubleCookie(String, double)
- Gets the named cookie value as a double, with a default.
-
getFloatCookie(String)
- Gets the named cookie value as a float
-
getFloatCookie(String, float)
- Gets the named cookie value as a float, with a default.
-
getIntCookie(String)
- Gets the named cookie value as a int
-
getIntCookie(String, int)
- Gets the named cookie value as a int, with a default.
-
getLongCookie(String)
- Gets the named cookie value as a long
-
getLongCookie(String, long)
- Gets the named cookie value as a long, with a default.
-
getShortCookie(String)
- Gets the named cookie value as a short
-
getShortCookie(String, short)
- Gets the named cookie value as a short, with a default.
-
getStringCookie(String)
- Gets the named cookie value as a String
-
getStringCookie(String, String)
- Gets the named cookie value as a String, with a default.
CookieParser
public CookieParser(HttpServletRequest req)
- Constructs a new CookieParser to handle the cookies of the
given request.
- Parameters:
- req - the servlet request
getStringCookie
public String getStringCookie(String name) throws CookieNotFoundException
- Gets the named cookie value as a String
- Parameters:
- name - the cookie name
- Returns:
- the cookie value as a String
- Throws: CookieNotFoundException
- if the cookie was not found
getStringCookie
public String getStringCookie(String name,
String def)
- Gets the named cookie value as a String, with a default.
Returns the default value if the cookie is not found
- Parameters:
- name - the cookie name
- def - the default cookie value
- Returns:
- the cookie value as a String, or the default
getBooleanCookie
public boolean getBooleanCookie(String name) throws CookieNotFoundException
- Gets the named cookie value as a boolean
- Parameters:
- name - the cookie name
- Returns:
- the cookie value as a boolean
- Throws: CookieNotFoundException
- if the cookie was not found
getBooleanCookie
public boolean getBooleanCookie(String name,
boolean def)
- Gets the named cookie value as a boolean, with a default.
Returns the default value if the cookie is not found.
- Parameters:
- name - the cookie name
- def - the default cookie value
- Returns:
- the cookie value as a boolean, or the default
getByteCookie
public byte getByteCookie(String name) throws CookieNotFoundException, NumberFormatException
- Gets the named cookie value as a byte
- Parameters:
- name - the cookie name
- Returns:
- the cookie value as a byte
- Throws: CookieNotFoundException
- if the cookie was not found
- Throws: NumberFormatException
- if the cookie value could not
be converted to a byte
getByteCookie
public byte getByteCookie(String name,
byte def)
- Gets the named cookie value as a byte, with a default.
Returns the default value if the cookie is not found or cannot
be converted to a byte.
- Parameters:
- name - the cookie name
- def - the default cookie value
- Returns:
- the cookie value as a byte, or the default
getCharCookie
public char getCharCookie(String name) throws CookieNotFoundException
- Gets the named cookie value as a char
- Parameters:
- name - the cookie name
- Returns:
- the cookie value as a char
- Throws: CookieNotFoundException
- if the cookie was not found
getCharCookie
public char getCharCookie(String name,
char def)
- Gets the named cookie value as a char, with a default.
Returns the default value if the cookie is not found.
- Parameters:
- name - the cookie name
- def - the default cookie value
- Returns:
- the cookie value as a char, or the default
getDoubleCookie
public double getDoubleCookie(String name) throws CookieNotFoundException, NumberFormatException
- Gets the named cookie value as a double
- Parameters:
- name - the cookie name
- Returns:
- the cookie value as a double
- Throws: CookieNotFoundException
- if the cookie was not found
- Throws: NumberFormatException
- if the cookie could not be converted
to a double
getDoubleCookie
public double getDoubleCookie(String name,
double def)
- Gets the named cookie value as a double, with a default.
Returns the default value if the cookie is not found.
- Parameters:
- name - the cookie name
- def - the default cookie value
- Returns:
- the cookie value as a double, or the default
getFloatCookie
public float getFloatCookie(String name) throws CookieNotFoundException, NumberFormatException
- Gets the named cookie value as a float
- Parameters:
- name - the cookie name
- Returns:
- the cookie value as a float
- Throws: CookieNotFoundException
- if the cookie was not found
- Throws: NumberFormatException
- if the cookie could not be converted
to a float
getFloatCookie
public float getFloatCookie(String name,
float def)
- Gets the named cookie value as a float, with a default.
Returns the default value if the cookie is not found.
- Parameters:
- name - the cookie name
- def - the default cookie value
- Returns:
- the cookie value as a float, or the default
getIntCookie
public int getIntCookie(String name) throws CookieNotFoundException, NumberFormatException
- Gets the named cookie value as a int
- Parameters:
- name - the cookie name
- Returns:
- the cookie value as a int
- Throws: CookieNotFoundException
- if the cookie was not found
- Throws: NumberFormatException
- if the cookie could not be converted
to a int
getIntCookie
public int getIntCookie(String name,
int def)
- Gets the named cookie value as a int, with a default.
Returns the default value if the cookie is not found.
- Parameters:
- name - the cookie name
- def - the default cookie value
- Returns:
- the cookie value as a int, or the default
getLongCookie
public long getLongCookie(String name) throws CookieNotFoundException, NumberFormatException
- Gets the named cookie value as a long
- Parameters:
- name - the cookie name
- Returns:
- the cookie value as a long
- Throws: CookieNotFoundException
- if the cookie was not found
- Throws: NumberFormatException
- if the cookie could not be converted
to a long
getLongCookie
public long getLongCookie(String name,
long def)
- Gets the named cookie value as a long, with a default.
Returns the default value if the cookie is not found.
- Parameters:
- name - the cookie name
- def - the default cookie value
- Returns:
- the cookie value as a long, or the default
getShortCookie
public short getShortCookie(String name) throws CookieNotFoundException, NumberFormatException
- Gets the named cookie value as a short
- Parameters:
- name - the cookie name
- Returns:
- the cookie value as a short
- Throws: CookieNotFoundException
- if the cookie was not found
- Throws: NumberFormatException
- if the cookie could not be converted
to a short
getShortCookie
public short getShortCookie(String name,
short def)
- Gets the named cookie value as a short, with a default.
Returns the default value if the cookie is not found.
- Parameters:
- name - the cookie name
- def - the default cookie value
- Returns:
- the cookie value as a short, or the default
All Packages Class Hierarchy This Package Previous Next Index