|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object com.oreilly.servlet.CookieParser
public class CookieParser
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(); }
CookieNotFoundException
Constructor Summary | |
---|---|
CookieParser(HttpServletRequest req)
Constructs a new CookieParser to handle the cookies of the given request. |
Method Summary | |
---|---|
boolean |
getBooleanCookie(java.lang.String name)
Gets the named cookie value as a boolean |
boolean |
getBooleanCookie(java.lang.String name,
boolean def)
Gets the named cookie value as a boolean, with a default. |
byte |
getByteCookie(java.lang.String name)
Gets the named cookie value as a byte |
byte |
getByteCookie(java.lang.String name,
byte def)
Gets the named cookie value as a byte, with a default. |
char |
getCharCookie(java.lang.String name)
Gets the named cookie value as a char |
char |
getCharCookie(java.lang.String name,
char def)
Gets the named cookie value as a char, with a default. |
double |
getDoubleCookie(java.lang.String name)
Gets the named cookie value as a double |
double |
getDoubleCookie(java.lang.String name,
double def)
Gets the named cookie value as a double, with a default. |
float |
getFloatCookie(java.lang.String name)
Gets the named cookie value as a float |
float |
getFloatCookie(java.lang.String name,
float def)
Gets the named cookie value as a float, with a default. |
int |
getIntCookie(java.lang.String name)
Gets the named cookie value as a int |
int |
getIntCookie(java.lang.String name,
int def)
Gets the named cookie value as a int, with a default. |
long |
getLongCookie(java.lang.String name)
Gets the named cookie value as a long |
long |
getLongCookie(java.lang.String name,
long def)
Gets the named cookie value as a long, with a default. |
short |
getShortCookie(java.lang.String name)
Gets the named cookie value as a short |
short |
getShortCookie(java.lang.String name,
short def)
Gets the named cookie value as a short, with a default. |
java.lang.String |
getStringCookie(java.lang.String name)
Gets the named cookie value as a String |
java.lang.String |
getStringCookie(java.lang.String name,
java.lang.String def)
Gets the named cookie value as a String, with a default. |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public CookieParser(HttpServletRequest req)
req
- the servlet requestMethod Detail |
---|
public java.lang.String getStringCookie(java.lang.String name) throws CookieNotFoundException
name
- the cookie name
CookieNotFoundException
- if the cookie was not foundpublic java.lang.String getStringCookie(java.lang.String name, java.lang.String def)
name
- the cookie namedef
- the default cookie value
public boolean getBooleanCookie(java.lang.String name) throws CookieNotFoundException
name
- the cookie name
CookieNotFoundException
- if the cookie was not foundpublic boolean getBooleanCookie(java.lang.String name, boolean def)
name
- the cookie namedef
- the default cookie value
public byte getByteCookie(java.lang.String name) throws CookieNotFoundException, java.lang.NumberFormatException
name
- the cookie name
CookieNotFoundException
- if the cookie was not found
java.lang.NumberFormatException
- if the cookie value could not
be converted to a bytepublic byte getByteCookie(java.lang.String name, byte def)
name
- the cookie namedef
- the default cookie value
public char getCharCookie(java.lang.String name) throws CookieNotFoundException
name
- the cookie name
CookieNotFoundException
- if the cookie was not foundpublic char getCharCookie(java.lang.String name, char def)
name
- the cookie namedef
- the default cookie value
public double getDoubleCookie(java.lang.String name) throws CookieNotFoundException, java.lang.NumberFormatException
name
- the cookie name
CookieNotFoundException
- if the cookie was not found
java.lang.NumberFormatException
- if the cookie could not be converted
to a doublepublic double getDoubleCookie(java.lang.String name, double def)
name
- the cookie namedef
- the default cookie value
public float getFloatCookie(java.lang.String name) throws CookieNotFoundException, java.lang.NumberFormatException
name
- the cookie name
CookieNotFoundException
- if the cookie was not found
java.lang.NumberFormatException
- if the cookie could not be converted
to a floatpublic float getFloatCookie(java.lang.String name, float def)
name
- the cookie namedef
- the default cookie value
public int getIntCookie(java.lang.String name) throws CookieNotFoundException, java.lang.NumberFormatException
name
- the cookie name
CookieNotFoundException
- if the cookie was not found
java.lang.NumberFormatException
- if the cookie could not be converted
to a intpublic int getIntCookie(java.lang.String name, int def)
name
- the cookie namedef
- the default cookie value
public long getLongCookie(java.lang.String name) throws CookieNotFoundException, java.lang.NumberFormatException
name
- the cookie name
CookieNotFoundException
- if the cookie was not found
java.lang.NumberFormatException
- if the cookie could not be converted
to a longpublic long getLongCookie(java.lang.String name, long def)
name
- the cookie namedef
- the default cookie value
public short getShortCookie(java.lang.String name) throws CookieNotFoundException, java.lang.NumberFormatException
name
- the cookie name
CookieNotFoundException
- if the cookie was not found
java.lang.NumberFormatException
- if the cookie could not be converted
to a shortpublic short getShortCookie(java.lang.String name, short def)
name
- the cookie namedef
- the default cookie value
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |