org.apache.webdav.lib
Class Cookie

java.lang.Object
  |
  +--org.apache.webdav.lib.NameValuePair
        |
        +--org.apache.webdav.lib.Cookie
All Implemented Interfaces:
java.io.Serializable

public class Cookie
extends NameValuePair
implements java.io.Serializable

This class represents an http cookie as specified in RFC 2109.

Author:
B.C. Holmes
See Also:
Serialized Form

Field Summary
protected  java.lang.String m_comment
           
protected  java.lang.String m_domain
           
protected  java.util.Date m_expiryDate
           
protected  java.lang.String m_path
           
protected  boolean m_secure
           
protected  int m_version
           
 
Fields inherited from class org.apache.webdav.lib.NameValuePair
name, value
 
Constructor Summary
Cookie(java.lang.String domain, java.lang.String name, java.lang.String value)
          Create a cookie.
 
Method Summary
static Header createCookieHeader(java.lang.String domain, java.lang.String path, java.util.Vector cookies)
           
 boolean equals(java.lang.Object obj)
          Two cookies match if the name, path and domain match.
 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 the domain of this cookie.
 java.util.Date getExpiryDate()
           
 java.lang.String getPath()
          Return the path this cookie is associated with.
 boolean getSecure()
          Return whether this cookie should only be sent over secure connections.
 int getVersion()
           
 int hashCode()
          Hash up name, path and domain into new hash.
 boolean isExpired()
           
 boolean isToBeDiscarded()
           
static Cookie[] parse(java.lang.String domain, Header setCookie)
          Parses the Set-Cookie header into an array of Cookies.
 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)
          This cookie should be presented only to hosts satisfying this domain name pattern.
 void setExpiryDate(java.util.Date expiryDate)
           
 void setPath(java.lang.String path)
          This cookie should be presented only with requests beginning with this URL.
 void setSecure(boolean secure)
          Indicates to the user agent that the cookie should only be sent using a secure protocol (https).
 void setVersion(int version)
           
 java.lang.String toExternalForm()
           
 java.lang.String toString()
          Get a String representation of the header.
 
Methods inherited from class org.apache.webdav.lib.NameValuePair
getName, getValue, setName, setValue
 
Methods inherited from class java.lang.Object
, clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

m_comment

protected java.lang.String m_comment

m_domain

protected java.lang.String m_domain

m_expiryDate

protected java.util.Date m_expiryDate

m_path

protected java.lang.String m_path

m_secure

protected boolean m_secure

m_version

protected int m_version
Constructor Detail

Cookie

public Cookie(java.lang.String domain,
              java.lang.String name,
              java.lang.String value)
Create a cookie.
Parameters:
name - the cookie name
value - the cookie value
domain - the host this cookie will be sent to
path - the path prefix for which this cookie will be sent
maxAge - the Date this cookie expires, null if the cookie expires at the end of the session
secure - if true this cookie will only be over secure connections
Throws:
NullPointerException - if name, value or domain is null
Since:
V0.3-1
Method Detail

getComment

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

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.
See Also:
getComment

getExpiryDate

public java.util.Date getExpiryDate()
Returns:
the expiry date of this cookie, or null if none set.

setExpiryDate

public void setExpiryDate(java.util.Date expiryDate)

isToBeDiscarded

public boolean isToBeDiscarded()
Returns:
true if the cookie should be discarded at the end of the session; false otherwise

getDomain

public java.lang.String getDomain()
Returns the domain of this cookie.
See Also:
setDomain

setDomain

public void setDomain(java.lang.String domain)
This cookie should be presented only to hosts satisfying this domain name pattern. Read RFC 2109 for specific details of the syntax. Briefly, a domain name name begins with a dot (".foo.com") and means that hosts in that DNS zone ("www.foo.com", but not "a.b.foo.com") should see the cookie. By default, cookies are only returned to the host which saved them.
See Also:
getDomain

getPath

public java.lang.String getPath()
Return the path this cookie is associated with.

setPath

public void setPath(java.lang.String path)
This cookie should be presented only with requests beginning with this URL. Read RFC 2109 for a specification of the default behaviour. Basically, URLs in the same "directory" as the one which set the cookie, and in subdirectories, can all see the cookie unless a different path is set.

getSecure

public boolean getSecure()
Return whether this cookie should only be sent over secure connections.

setSecure

public void setSecure(boolean secure)
Indicates to the user agent that 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.
See Also:
getSecure

getVersion

public int getVersion()

setVersion

public void setVersion(int version)

isExpired

public boolean isExpired()
Returns:
true if this cookie has expired

hashCode

public int hashCode()
Hash up name, path and domain into new hash.
Overrides:
hashCode in class java.lang.Object

equals

public boolean equals(java.lang.Object obj)
Two cookies match if the name, path and domain match.
Overrides:
equals in class NameValuePair

toExternalForm

public java.lang.String toExternalForm()
Returns:
a string suitable for sending in a Cookie header.

createCookieHeader

public static Header createCookieHeader(java.lang.String domain,
                                        java.lang.String path,
                                        java.util.Vector cookies)

toString

public java.lang.String toString()
Description copied from class: NameValuePair
Get a String representation of the header.
Overrides:
toString in class NameValuePair

parse

public static Cookie[] parse(java.lang.String domain,
                             Header setCookie)
                      throws WebdavException
Parses the Set-Cookie header into an array of Cookies.

The syntax for the Set-Cookie response header is:

 set-cookie      =    "Set-Cookie:" cookies
 cookies         =    1#cookie
 cookie          =    NAME "=" VALUE * (";" cookie-av)
 NAME            =    attr
 VALUE           =    value
 cookie-av       =    "Comment" "=" value
                 |    "Domain" "=" value
                 |    "Max-Age" "=" value
                 |    "Path" "=" value
                 |    "Secure"
                 |    "Version" "=" 1*DIGIT
 
Parameters:
domain - the domain
setCookie - the Set-Cookie header received from the server
Returns:
an array of Cookies as parsed from the Set-Cookie header
Throws:
WebdavException - if an error occurs during parsing