org.apache.http.cookie
Class Cookie

java.lang.Object
  extended by org.apache.http.cookie.Cookie

public class Cookie
extends java.lang.Object

HTTP "magic-cookie" represents a piece of state information that the HTTP agent and the target server can exchange to maintain a session.

Version:
$Revision: 535132 $
Author:
B.C. Holmes, Park, Sung-Gu, Doug Sale, Rod Waldhoff, dIon Gillard, Sean C. Sullivan, John Evans, Marc A. Saegesser, Oleg Kalnichevski, Mike Bowler

Constructor Summary
Cookie(java.lang.String name, java.lang.String value)
          Default Constructor taking a name and a value.
 
Method Summary
 java.lang.String getComment()
          Returns the comment describing the purpose of this cookie, or null if no such comment has been defined.
 java.lang.String getDomain()
          Returns domain attribute of the cookie.
 java.util.Date getExpiryDate()
          Returns the expiration Date of the cookie, or null if none exists.
 java.lang.String getName()
          Returns the name.
 java.lang.String getPath()
          Returns the path attribute of the cookie
 java.lang.String getValue()
          Returns the value.
 int getVersion()
          Returns the version of the cookie specification to which this cookie conforms.
 boolean isDomainAttributeSpecified()
          Returns true if cookie's domain was set via a domain attribute in the Set-Cookie header.
 boolean isExpired(java.util.Date date)
          Returns true if this cookie has expired.
 boolean isPathAttributeSpecified()
          Returns true if cookie's path was set via a path attribute in the Set-Cookie header.
 boolean isPersistent()
          Returns false if the cookie should be discarded at the end of the "session"; true otherwise.
 boolean isSecure()
           
 void setComment(java.lang.String comment)
          If a user agent (web browser) presents this cookie to a user, the cookie's purpose will be described using this comment.
 void setDomain(java.lang.String domain)
          Sets the domain attribute.
 void setDomainAttributeSpecified(boolean value)
          Indicates whether the cookie had a domain specified in a domain attribute of the Set-Cookie header.
 void setExpiryDate(java.util.Date expiryDate)
          Sets expiration date.
 void setPath(java.lang.String path)
          Sets the path attribute.
 void setPathAttributeSpecified(boolean value)
          Indicates whether the cookie had a path specified in a path attribute of the Set-Cookie header.
 void setSecure(boolean secure)
          Sets the secure attribute of the cookie.
 void setVersion(int version)
          Sets the version of the cookie specification to which this cookie conforms.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Cookie

public Cookie(java.lang.String name,
              java.lang.String value)
Default Constructor taking a name and a value. The value may be null.

Parameters:
name - The name.
value - The value.
Method Detail

getName

public java.lang.String getName()
Returns the name.

Returns:
String name The name

getValue

public java.lang.String getValue()
Returns the value.

Returns:
String value The current value.

getComment

public java.lang.String getComment()
Returns the comment describing the purpose of this cookie, or null if no such comment has been defined.

Returns:
comment
See Also:
setComment(String)

setComment

public void setComment(java.lang.String comment)
If a user agent (web browser) presents this cookie to a user, the cookie's purpose will be described using this comment.

Parameters:
comment -
See Also:
getComment()

getExpiryDate

public java.util.Date getExpiryDate()
Returns the expiration Date of the cookie, or null if none exists.

Note: the object returned by this method is considered immutable. Changing it (e.g. using setTime()) could result in undefined behaviour. Do so at your peril.

Returns:
Expiration Date, or null.
See Also:
setExpiryDate(java.util.Date)

setExpiryDate

public void setExpiryDate(java.util.Date expiryDate)
Sets expiration date.

Note: the object returned by this method is considered immutable. Changing it (e.g. using setTime()) could result in undefined behaviour. Do so at your peril.

Parameters:
expiryDate - the Date after which this cookie is no longer valid.
See Also:
getExpiryDate()

isPersistent

public boolean isPersistent()
Returns false if the cookie should be discarded at the end of the "session"; true otherwise.

Returns:
false if the cookie should be discarded at the end of the "session"; true otherwise

getDomain

public java.lang.String getDomain()
Returns domain attribute of the cookie.

Returns:
the value of the domain attribute
See Also:
setDomain(java.lang.String)

setDomain

public void setDomain(java.lang.String domain)
Sets the domain attribute.

Parameters:
domain - The value of the domain attribute
See Also:
getDomain()

getPath

public java.lang.String getPath()
Returns the path attribute of the cookie

Returns:
The value of the path attribute.
See Also:
setPath(java.lang.String)

setPath

public void setPath(java.lang.String path)
Sets the path attribute.

Parameters:
path - The value of the path attribute
See Also:
getPath()

isSecure

public boolean isSecure()
Returns:
true if this cookie should only be sent over secure connections.
See Also:
setSecure(boolean)

setSecure

public void setSecure(boolean secure)
Sets the secure attribute of the cookie.

When true the cookie should only be sent using a secure protocol (https). This should only be set when the cookie's originating server used a secure protocol to set the cookie's value.

Parameters:
secure - The value of the secure attribute
See Also:
isSecure()

getVersion

public int getVersion()
Returns the version of the cookie specification to which this cookie conforms.

Returns:
the version of the cookie.
See Also:
setVersion(int)

setVersion

public void setVersion(int version)
Sets the version of the cookie specification to which this cookie conforms.

Parameters:
version - the version of the cookie.
See Also:
getVersion()

isExpired

public boolean isExpired(java.util.Date date)
Returns true if this cookie has expired.

Parameters:
date - Current time
Returns:
true if the cookie has expired.

setPathAttributeSpecified

public void setPathAttributeSpecified(boolean value)
Indicates whether the cookie had a path specified in a path attribute of the Set-Cookie header. This value is important for generating the Cookie header because some cookie specifications require that the Cookie header should only include a path attribute if the cookie's path was specified in the Set-Cookie header.

Parameters:
value - true if the cookie's path was explicitly set, false otherwise.
See Also:
isPathAttributeSpecified()

isPathAttributeSpecified

public boolean isPathAttributeSpecified()
Returns true if cookie's path was set via a path attribute in the Set-Cookie header.

Returns:
value true if the cookie's path was explicitly set, false otherwise.
See Also:
setPathAttributeSpecified(boolean)

setDomainAttributeSpecified

public void setDomainAttributeSpecified(boolean value)
Indicates whether the cookie had a domain specified in a domain attribute of the Set-Cookie header. This value is important for generating the Cookie header because some cookie specifications require that the Cookie header should only include a domain attribute if the cookie's domain was specified in the Set-Cookie header.

Parameters:
value - true if the cookie's domain was explicitly set, false otherwise.
See Also:
isDomainAttributeSpecified()

isDomainAttributeSpecified

public boolean isDomainAttributeSpecified()
Returns true if cookie's domain was set via a domain attribute in the Set-Cookie header.

Returns:
value true if the cookie's domain was explicitly set, false otherwise.
See Also:
setDomainAttributeSpecified(boolean)

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object


Copyright © 2000-2007 Apache Software Foundation. All Rights Reserved.