|
WebObjects 5.2.3 | ||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object com.webobjects.appserver.WOCookie
WOCookie is used for the creation and setting of cookies in response objects. A cookie allows for the persistent storage of client state. Instead of using a WOSession object (which can potentially have a shorter life span), a cookie allows server-side applications to store state in client browsers for a specific or indeterminate amount of time. An advantage to cookies is that the data will be stored on the client and not on the server, allowing the server to maintain less state information. A specific advantage in WebObjects applications is that cookies allow the server to put state into the browser that is not bound to a session. Hence, the client can "leave" your application and return with its cookie's state intact.
A WOCookie object defines a cookie that can be added to the HTTP header for
the response. A cookie is created using the static method
cookieWithName
.
To add or remove cookies from the response, the WOMessage methods
addCookie
and removeCookie
are used. To retrieve cookie data,
WORequest methods cookieValues
, cookieValueForKey
, and
cookieValuesForKey
are
used. WORequest returns the data as name/value
pairs and not as WOCookie objects, since browsers don't return the
additional data WOCookies provide, such as path name and expiration date.
To create a cookie that expires when the browser window is closed, the cookie must be created with neither a "max-age" nor an "expires" attribute. WOCookie supports this behavior with the 2 argument constructor WOCookie(aName, aValue) and with the 6 argument constructor WOCookie(aName, aValue, aPath, aDomain, timeout, isSecure). If using the 6 argument constructor, you must pass a timeout value of -1
. In either case, ensure that you avoid calling setExpires on the WOCookie object you get back from the constructor, or make sure that you call "setExpires(null)" on the WOCookie object before using it. This will prevent the WOCookie object from generating either a "max-age" or an "expires" header, which will indicate the desired expiration behavior. For example:
WOCookie cookie = new WOCookie("cookieName", "cookieValue", "/", null, -1, false);
cookie.setExpires(null);
For more information about cookies and their implementation details, see Netscape's preliminary specification and RFC 2109 - HTTP State Management Mechanism.
If and when new details evolve in the implementation of cookies, you can
subclass WOCookie and implement new behaviors. Pay particular attention to
how you override headerString
, which WOResponse uses to generate
headers in the HTTP response.
headerString()
,
WOCookie(String aName, String aValue, String aPath, String aDomain, int timeout, boolean isSecure)
,
WORequest.cookieValues()
,
WOMessage
,
WOMessage.addCookie(WOCookie aCookie)
,
WOMessage.removeCookie(WOCookie aCookie)
,
WORequest.cookieValuesForKey(String aKey)
,
WORequest.cookieValuesForKey(String aKey)
Nested Class Summary |
Nested classes inherited from class com.webobjects.foundation.NSKeyValueCoding |
NSKeyValueCoding.DefaultImplementation, NSKeyValueCoding.ErrorHandling, NSKeyValueCoding.Null, NSKeyValueCoding.UnknownKeyException, NSKeyValueCoding.Utility, NSKeyValueCoding.ValueAccessor |
Nested classes inherited from class com.webobjects.foundation.NSKeyValueCodingAdditions |
NSKeyValueCodingAdditions.DefaultImplementation, NSKeyValueCodingAdditions.Utility |
Field Summary |
Fields inherited from interface com.webobjects.foundation.NSKeyValueCoding |
NullValue |
Fields inherited from interface com.webobjects.foundation.NSKeyValueCodingAdditions |
KeyPathSeparator |
Constructor Summary | |
WOCookie(String aName,
String aValue)
Constructor for a WOCookie with the specified name and value. |
|
WOCookie(String aName,
String aValue,
String aPath,
String aDomain,
int timeout,
boolean isSecure)
Constructor for a WOCookie with the specified attributes. |
|
WOCookie(String aName,
String aValue,
String aPath,
String aDomain,
NSTimestamp aDate,
boolean isSecure)
Constructor for a WOCookie with the specified attributes. |
Method Summary | |
static boolean |
canAccessFieldsDirectly()
WOCokie's implementation of this static method returns true, indicating that key/value coding is allowed to access fields in this object if an appropriate method isn't present. |
static WOCookie |
cookieWithName(String aName,
String aValue)
Deprecated. Use WOCookie(String aName, String aValue) instead |
static WOCookie |
cookieWithName(String aName,
String aValue,
String aPath,
String aDomain,
int timeout,
boolean isSecure)
Deprecated. Use WOCookie(String aName, String aValue, String aPath, String aDomain, int timeout, boolean isSecure) instead |
static WOCookie |
cookieWithName(String aName,
String aValue,
String aPath,
String aDomain,
NSTimestamp aDate,
boolean isSecure)
Deprecated. Use WOCookie(String aName, String aValue, String aPath, String aDomain, NSTimestamp aDate, boolean isSecure) instead |
String |
domain()
Cookies for a specific domain (such as apple.com) are sent only when accessing URLs in that domain. |
NSTimestamp |
expires()
Returns the value of the cookie's "expires" attribute as an NSTimestamp. |
Object |
handleQueryWithUnboundKey(String key)
Conformance to NSKeyValueCoding.ErrorHandling. |
void |
handleTakeValueForUnboundKey(Object value,
String key)
Conformance to NSKeyValueCoding.ErrorHandling. |
String |
headerString()
Create and return a string which can be used in a Set-Cookie header. |
boolean |
isSecure()
Return whether or not the cookie is secure. |
String |
name()
The name is similar to the key of a dictionary or hash table. |
String |
path()
Cookies for a specific path are sent only when accessing URLs within that path. |
void |
setDomain(String aDomain)
Sets the cookie's "domain" attribute to aDomain . |
void |
setExpires(NSTimestamp aDate)
Sets the cookie's "expires" attribute to expirationDate. |
void |
setIsSecure(boolean aBoolean)
Sets the cookie's "secure" attribute to aBoolean . |
void |
setName(String aName)
Sets the cookie's "name" attribute to aName . |
void |
setPath(String aPath)
Sets the cookie's "path" attribute to aPath . |
void |
setTimeOut(int timeout)
A negative value is used to indicate that there is no timeout, analogous to a NSTimestamp of null. |
void |
setValue(String aValue)
Sets the cookie's "value" attribute to aValue . |
void |
takeValueForKey(Object value,
String key)
Conformance to NSKeyValueCoding. |
void |
takeValueForKeyPath(Object value,
String keyPath)
Conformance to NSKeyValueCodingAdditions. |
int |
timeOut()
Returns the cookies timeout value in seconds. |
String |
toString()
Returns a string representation of the receiver. |
void |
unableToSetNullForKey(String key)
Conformance to NSKeyValueCoding.ErrorHandling. |
String |
value()
This value attribute is similar to the value of a dictionary or hash table. |
Object |
valueForKey(String key)
Conformance to NSKeyValueCoding. |
Object |
valueForKeyPath(String keyPath)
Conformance to NSKeyValueCodingAdditions. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
public WOCookie(String aName, String aValue, String aPath, String aDomain, NSTimestamp aDate, boolean isSecure)
aName
is
null
.
aName
- the cookie's "name" attributeaValue
- the cookie's "value" attributeaPath
- the cookie's "path" attributeaDomain
- the cookie's "domain" attributeaDate
- the time at which the cookie will expireisSecure
- the cookie's "secure" attributename()
,
value()
,
path()
,
domain()
,
expires()
,
isSecure()
public WOCookie(String aName, String aValue, String aPath, String aDomain, int timeout, boolean isSecure)
aName
is
null
.
A note on time out periods: time out periods are in seconds; a negative
time out period indicates no time out; a time out of zero indicates
expiration of all cookies with the given name.
aName
- the cookie's "name" attributeaValue
- the cookie's "value" attributeaPath
- the cookie's "path" attributeaDomain
- the cookie's "domain" attributetimeout
- the cookie's timeout period in secondsisSecure
- the cookie's "secure" attributename()
,
value()
,
path()
,
domain()
,
timeOut()
,
isSecure()
public WOCookie(String aName, String aValue)
aName
is null
.
aName
- the cookie's "name" attributeaValue
- the cookie's "value" attributename()
,
value()
Method Detail |
public static boolean canAccessFieldsDirectly()
public static WOCookie cookieWithName(String aName, String aValue, String aPath, String aDomain, NSTimestamp aDate, boolean isSecure)
WOCookie(aName, aValue, aPath, aDomain, aDate, isSecure)
.
WOCookie(String aName, String aValue, String aPath, String aDomain, NSTimestamp aDate, boolean isSecure)
public static WOCookie cookieWithName(String aName, String aValue, String aPath, String aDomain, int timeout, boolean isSecure)
WOCookie(aName, aValue, aPath, aDomain, timeout, isSecure)
.
WOCookie(String aName, String aValue, String aPath, String aDomain, int timeout, boolean isSecure)
public static WOCookie cookieWithName(String aName, String aValue)
WOCookie(aName, aValue)
.
WOCookie(String aName, String aValue)
public String domain()
setDomain(java.lang.String)
public NSTimestamp expires()
setExpires(NSTimestamp aDate)
public Object handleQueryWithUnboundKey(String key)
handleQueryWithUnboundKey
in interface NSKeyValueCoding.ErrorHandling
key
- identifies the property of an object
key
NSKeyValueCoding.valueForKey(java.lang.String)
,
NSKeyValueCoding.UnknownKeyException
,
NSKeyValueCoding.DefaultImplementation
public void handleTakeValueForUnboundKey(Object value, String key)
handleTakeValueForUnboundKey
in interface NSKeyValueCoding.ErrorHandling
key
- identifies the property to be setvalue
- the value to which the property specified by key
should be setNSKeyValueCoding.takeValueForKey(java.lang.Object, java.lang.String)
,
NSKeyValueCoding.UnknownKeyException
,
NSKeyValueCoding.DefaultImplementation
public String headerString()
name=value; version="1"; max-age=timeout; expires=date; path=path; domain=domain; secure;
The calendar format for the expiration date is:
where all times are converted relative to Greenwich Mean Time. The max-age attribute is not added if the timeout is "-1". Values are quoted if they have spaces and are not already quoted."%A,%d-%b-%Y %H:%M:%S GMT"
public boolean isSecure()
false
.
true
if the cookie should be transmitted only with secure
HTTP, false
otherwisesetIsSecure(boolean aBoolean)
public String name()
setName(java.lang.String)
public String path()
setPath(String aPath)
public void setDomain(String aDomain)
aDomain
.
aDomain
- the cookie's "domain" attributedomain()
public void setExpires(NSTimestamp aDate)
aDate
- an NSTimestamp indicating when the cookie should expiresetExpires(NSTimestamp aDate)
public void setIsSecure(boolean aBoolean)
aBoolean
.
aBoolean
- true
if the cookie should only be transmitted over
HTTPS, false
otherwiseisSecure()
public void setName(String aName)
aName
.
aName
- the cookie's name attributename()
public void setPath(String aPath)
aPath
.
aPath
- the cookie's path attributepath()
public void setTimeOut(int timeout)
timeout
- time after which the cookie expirestimeOut()
public void setValue(String aValue)
aValue
.
aValue
- the cookie's value attributevalue()
public void takeValueForKey(Object value, String key)
takeValueForKey
in interface NSKeyValueCoding
key
- identifies the property to be setvalue
- the value to which the property specified by key
should be setNSKeyValueCoding.NullValue
,
NSKeyValueCoding.valueForKey(java.lang.String)
,
NSKeyValueCoding.DefaultImplementation
,
NSKeyValueCoding.ErrorHandling
,
NSKeyValueCoding.ErrorHandling.handleTakeValueForUnboundKey(java.lang.Object, java.lang.String)
public void takeValueForKeyPath(Object value, String keyPath)
takeValueForKeyPath
in interface NSKeyValueCodingAdditions
keyPath
- identifies a derived property of the receivervalue
- value to which the derived property identified by
keyPath
will be setNSKeyValueCoding.takeValueForKey(java.lang.Object, java.lang.String)
,
NSKeyValueCodingAdditions.valueForKeyPath(java.lang.String)
,
NSKeyValueCodingAdditions.DefaultImplementation
public int timeOut()
setTimeOut(int timeout)
public String toString()
public void unableToSetNullForKey(String key)
unableToSetNullForKey
in interface NSKeyValueCoding.ErrorHandling
key
- identifies the property to be setNSKeyValueCoding.takeValueForKey(Object value, String key)
,
NSKeyValueCoding.DefaultImplementation
public String value()
setValue(String aValue)
public Object valueForKey(String key)
valueForKey
in interface NSKeyValueCoding
key
- identifies the property of an object
key
NSKeyValueCoding.NullValue
,
NSKeyValueCoding.takeValueForKey(java.lang.Object, java.lang.String)
,
NSKeyValueCoding.DefaultImplementation
,
NSKeyValueCoding.ErrorHandling
,
NSKeyValueCoding.ErrorHandling.handleQueryWithUnboundKey(java.lang.String)
public Object valueForKeyPath(String keyPath)
valueForKeyPath
in interface NSKeyValueCodingAdditions
keyPath
- identifies the derived property of an object
keyPath
NSKeyValueCoding.valueForKey(java.lang.String)
,
NSKeyValueCodingAdditions.takeValueForKeyPath(java.lang.Object, java.lang.String)
,
NSKeyValueCodingAdditions.DefaultImplementation
|
Last updated Thu Oct 21 15:04:16 PDT 2004. | ||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |