|
WebObjects 5.4.2 | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object com.webobjects.appserver.WOCookie
public class 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.
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.
WOCookie.headerString()
,
WOCookie.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)
,
Serialized FormNested Class Summary |
---|
Nested classes/interfaces inherited from interface com.webobjects.foundation.NSKeyValueCodingAdditions |
---|
NSKeyValueCodingAdditions.DefaultImplementation, NSKeyValueCodingAdditions.Utility |
Field Summary |
---|
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 |
readObject(ObjectInputStream in)
Conformance to Serializable. |
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. |
void |
writeObject(ObjectOutputStream out)
Conformance to Serializable. |
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" attributeWOCookie.name()
,
WOCookie.value()
,
WOCookie.path()
,
WOCookie.domain()
,
WOCookie.expires()
,
WOCookie.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" attributeWOCookie.name()
,
WOCookie.value()
,
WOCookie.path()
,
WOCookie.domain()
,
WOCookie.timeOut()
,
WOCookie.isSecure()
public WOCookie(String aName, String aValue)
aName
is null
.
aName
- the cookie's "name" attributeaValue
- the cookie's "value" attributeWOCookie.name()
,
WOCookie.value()
Method Detail |
---|
@Deprecated public static WOCookie cookieWithName(String aName, String aValue, String aPath, String aDomain, NSTimestamp aDate, boolean isSecure)
WOCookie(aName, aValue, aPath, aDomain, aDate, isSecure)
.
WOCookie.WOCookie(String aName, String aValue, String aPath, String aDomain, NSTimestamp aDate, boolean isSecure)
@Deprecated public static WOCookie cookieWithName(String aName, String aValue, String aPath, String aDomain, int timeout, boolean isSecure)
WOCookie(aName, aValue, aPath, aDomain, timeout, isSecure)
.
WOCookie.WOCookie(String aName, String aValue, String aPath, String aDomain, int timeout, boolean isSecure)
@Deprecated public static WOCookie cookieWithName(String aName, String aValue)
WOCookie(aName, aValue)
.
WOCookie.WOCookie(String aName, String aValue)
public String toString()
toString
in class Object
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 String name()
WOCookie.setName(java.lang.String)
public void setName(String aName)
aName
.
aName
- the cookie's name attributeWOCookie.name()
public String value()
WOCookie.setValue(String aValue)
public void setValue(String aValue)
aValue
.
aValue
- the cookie's value attributeWOCookie.value()
public String domain()
WOCookie.setDomain(java.lang.String)
public void setDomain(String aDomain)
aDomain
.
aDomain
- the cookie's "domain" attributeWOCookie.domain()
public String path()
WOCookie.setPath(String aPath)
public void setPath(String aPath)
aPath
.
aPath
- the cookie's path attributeWOCookie.path()
public NSTimestamp expires()
WOCookie.setExpires(NSTimestamp aDate)
public void setExpires(NSTimestamp aDate)
aDate
- an NSTimestamp indicating when the cookie should expireWOCookie.setExpires(NSTimestamp aDate)
public void setTimeOut(int timeout)
timeout
- time after which the cookie expiresWOCookie.timeOut()
public int timeOut()
WOCookie.setTimeOut(int timeout)
public boolean isSecure()
false
.
true
if the cookie should be transmitted only with secure HTTP, false
otherwiseWOCookie.setIsSecure(boolean aBoolean)
public void setIsSecure(boolean aBoolean)
aBoolean
.
aBoolean
- true
if the cookie should only be transmitted over HTTPS, false
otherwiseWOCookie.isSecure()
public static boolean canAccessFieldsDirectly()
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 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
,
NSKeyValueCoding.DefaultImplementation
,
NSKeyValueCoding.ErrorHandling
,
NSKeyValueCoding.ErrorHandling.handleTakeValueForUnboundKey(java.lang.Object, java.lang.String)
public Object handleQueryWithUnboundKey(String key)
handleQueryWithUnboundKey
in interface NSKeyValueCoding.ErrorHandling
key
- identifies the property of an object
key
NSKeyValueCoding.valueForKey
,
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
,
NSKeyValueCoding.UnknownKeyException
,
NSKeyValueCoding.DefaultImplementation
public void unableToSetNullForKey(String key)
unableToSetNullForKey
in interface NSKeyValueCoding.ErrorHandling
key
- identifies the property to be setNSKeyValueCoding.takeValueForKey
,
NSKeyValueCoding.DefaultImplementation
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
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 void writeObject(ObjectOutputStream out) throws IOException
writeObject()
method is responsible for writing the state of the object for its particular class so that the corresponding readObject()
method can restore it.
out
- ObjectOutputStream written to
IOException
- when unable to write to the ObjectOutputStream specifiedpublic void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException
readObject()
method is responsible for reading from the stream and restoring the classes fields.
in
- ObjectInputStream written to
IOException
- when unable to read from the ObjectInputStream specified
ClassNotFoundException
|
Last updated June 2008 | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |