|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Object
|
+--com.ibm.wbi.util.HeaderField
|
+--com.ibm.wbi.protocol.http.HttpSetCookie
This class is used to represent a HTTP set-cookie via the Netscape specification (http://home.netscape.com/newsref/std/cookie_spec.html). Example usage in an Editor
// ...
int WEEK = 7 * 24 * 60 * 60 * 1000;
HttpSetCookie scookie = new HttpSetCookie("mycookie", "foo");
scookie.setExpiresDate(new Date(new Date().getTime() + WEEK));
DocumentInfo di = (DocumentInfo)e.getRequestInfo();
HttpResponseHeader hrh = di.getHttpResponseHeader();
addSetCookie(hrh, scookie);
// ...
Or in a Generator
// ...
int WEEK = 7 * 24 * 60 * 60 * 1000;
HttpSetCookie scookie = new HttpSetCookie("mycookie", "foo");
scookie.setExpiresDate(new Date(new Date().getTime() + WEEK));
HttpResponseHeader hrh = new HttpResponseHeader();
addSetCookie(hrh, scookie);
DocumentInfo di = (DocumentInfo)e.getRequestInfo();
di.setResponseHeader(hrh);
// ...
You might also want to modify the set-cookie you get from a server.
For example, you might say "I don't want any cookies to last more
than one week".
// ...
int WEEK = 7 * 24 * 60 * 60 * 1000;
DocumentInfo di = (DocumentInfo)e.getRequestInfo();
HttpResponseHeader hrh = di.getHttpResponseHeader();
Vector scookies0 = getSetCookies(hrh);
Vector modified_cookies0 = new Vector();
Enumeration scookies = scookies0.elements();
while(scookies.hasMoreElements()) {
HttpSetCookie scookie = (HttpSetCookie)scookies.nextElement();
Date exp = scookie.getExpiresDate();
long now = new Date().getTime();
if (exp != null && exp.getTime() > now + WEEK)
scookie.setExpiresDate(new Date(now + WEEK));
modified_cookies0.addElement(scookie);
}
hrh.remove("set-cookie");
Enumeration modified_cookies = modified_cookies0.elements();
while(modified_cookies.hasMoreElements())
addSetCookie(hrh, (HttpSetCookie)modified_cookies.nextElement());
// ...
HttpCookie,
HttpResponseHeader| Field Summary | |
static java.lang.String |
COMMENT
|
static java.lang.String |
DOMAIN
|
static java.lang.String |
EXPIRES
|
protected java.lang.String |
name
|
static java.lang.String |
PATH
|
static java.lang.String |
SECURE
|
protected java.lang.String |
value
|
| Fields inherited from class com.ibm.wbi.util.HeaderField |
params, val |
| Constructor Summary | |
HttpSetCookie(java.lang.String unparsed)
Creates a new HttpSetCookie instance by parsing. |
|
HttpSetCookie(java.lang.String name,
java.lang.String value)
Construct a new HttpSetCookie with the specified name and value. |
|
| Method Summary | |
static void |
addSetCookie(HttpResponseHeader h,
HttpSetCookie scookie)
Adds a Set-Cookie header line to an HTTP header. |
java.lang.String |
getComment()
Tell the comment attribute for this cookie |
java.lang.String |
getDomain()
Tell the domain attribute for this cookie |
java.lang.String |
getExpires()
Get the value of the expires attribute as a java.lang.String. |
java.util.Date |
getExpiresDate()
Get the value of the expires attribute of the cookie as a java.util.Date object. |
java.lang.String |
getName()
Tell the name field for the cookie |
java.lang.String |
getPath()
Get the path attribute of this cookie |
boolean |
getSecure()
Tell whether the secure attribute is set. |
static HttpSetCookie |
getSetCookie(HttpResponseHeader h)
Get the first "Set-Cookie" line in an HTTP header. |
static HttpSetCookie |
getSetCookie(HttpResponseHeader h,
java.lang.String name)
Get the first "Set-Cookie" line in an HTTP header. |
static java.util.Vector |
getSetCookies(HttpResponseHeader h)
Get all Set-Cookie lines in an HTTP header. |
java.lang.String |
getValue()
Tell the value field for the cookie |
java.lang.String |
removeComment()
Remove the comment attribute from this cookie |
java.lang.String |
removeDomain()
Remove the domain attribute for this cookie |
java.lang.String |
removeExpires()
Remove the expires attribute from this cookie |
java.lang.String |
removePath()
Remove the path attribute from this cookie |
void |
setComment(java.lang.String v)
Set the comment attribute for this cookie |
void |
setDomain(java.lang.String v)
Set the domain attribute for this cookie |
void |
setExpires(java.lang.String v)
Set the value of the expires attribute as a java.lang.String. |
void |
setExpiresDate(java.util.Date v)
Set the value of the expires attribute of the cookie using a java.util.Date object. |
void |
setName(java.lang.String v)
Modify the name field for this cookie. |
void |
setPath(java.lang.String v)
Set the path attribute for this cookie |
void |
setSecure(boolean v)
Set the secure attribute of the secure attribute. |
static void |
setSetCookie(HttpResponseHeader h,
HttpSetCookie scookie)
Sets a value for the Set-Cookie header line in an HTTP header, eliminating all previous values for the Set-Cookie header. |
void |
setValue(java.lang.String v)
Modify the value field for this cookie. |
protected void |
updateNameValue()
|
protected void |
updateVal()
val is a member variable of the baseclass,
HeaderField. |
| Methods inherited from class com.ibm.wbi.util.HeaderField |
clone, getParam, getParameters, main, removeParam, removeParameters, setParam, toString |
| Methods inherited from class java.lang.Object |
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Field Detail |
public static final java.lang.String COMMENT
public static final java.lang.String DOMAIN
public static final java.lang.String EXPIRES
public static final java.lang.String PATH
public static final java.lang.String SECURE
protected java.lang.String name
protected java.lang.String value
| Constructor Detail |
public HttpSetCookie(java.lang.String name,
java.lang.String value)
Editor or
Generator Meg to send a set-cookie
header to the browser. In other words, to request the browser
to store the cookie.name - The name of the cookievalue - The value assigned to the cookiepublic HttpSetCookie(java.lang.String unparsed)
HttpSetCookie instance by parsing.
If the parse fails, then part or all of the unparsed string is
ignored.unparsed - a String value| Method Detail |
protected void updateVal()
val is a member variable of the baseclass,
HeaderField. HttpSetCookie separates the val into a name and
value, "="-delimited. This code takes care of making sure the
val is correct after name or value have been changed.protected void updateNameValue()
public java.lang.String getName()
public void setName(java.lang.String v)
v - The new namesetValue(java.lang.String)public java.lang.String getValue()
getValue in class HeaderFieldpublic void setValue(java.lang.String v)
setValue in class HeaderFieldv - The new valuesetName(java.lang.String)public java.util.Date getExpiresDate()
Date value or null if not presentpublic void setExpiresDate(java.util.Date v)
v - a Date valuepublic java.lang.String getExpires()
String valuegetExpiresDate()public void setExpires(java.lang.String v)
v - a String valuesetExpiresDate(java.util.Date)public java.lang.String removeExpires()
String value, the old value or nullpublic boolean getSecure()
true if the secure attribute is setpublic void setSecure(boolean v)
true will add the secure attribute,
false will remove it. There is no removeSecure()
method.v - a boolean valuepublic java.lang.String getComment()
String valuepublic void setComment(java.lang.String v)
v - a String valuepublic java.lang.String removeComment()
String valuepublic java.lang.String getDomain()
String valuepublic void setDomain(java.lang.String v)
v - a String valuepublic java.lang.String removeDomain()
String valuepublic java.lang.String getPath()
String valuepublic void setPath(java.lang.String v)
v - a String valuepublic java.lang.String removePath()
String valuepublic static HttpSetCookie getSetCookie(HttpResponseHeader h)
h - The HttpResponseHeader.HttpSetCookie, or null if there are
no Set-Cookie lines.
public static HttpSetCookie getSetCookie(HttpResponseHeader h,
java.lang.String name)
h - The HttpResponseHeader.HttpSetCookie, or null if there are
no Set-Cookie lines.public static java.util.Vector getSetCookies(HttpResponseHeader h)
h - The HttpResponseHeader.Vector containing each Set-Cookie line
as an HttpSetCookie; the Vector is
empty if there are none.
public static void setSetCookie(HttpResponseHeader h,
HttpSetCookie scookie)
h - The HttpResponseHeader.scookie - The value to set.
public static void addSetCookie(HttpResponseHeader h,
HttpSetCookie scookie)
h - The HttpResponseHeader.scookie - The value to add.
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||