com.gargoylesoftware.htmlunit.util
Class Cookie

java.lang.Object
  extended by com.gargoylesoftware.htmlunit.util.Cookie
All Implemented Interfaces:
Serializable

public class Cookie
extends Object
implements Serializable

A cookie. This class is immutable.

Version:
$Revision: 5724 $
Author:
Daniel Gredler, Nicolas Belisle
See Also:
Serialized Form

Constructor Summary
Cookie(String name, String value)
          Creates a new cookie with the specified name and value.
Cookie(String domain, String name, String value)
          Creates a new cookie with the specified name and value which applies to the specified domain.
Cookie(String domain, String name, String value, String path, Date expires, boolean secure)
          Creates a new cookie with the specified name and value which applies to the specified domain, the specified path, and expires on the specified date.
Cookie(String domain, String name, String value, String path, int maxAge, boolean secure)
          Creates a new cookie with the specified name and value which applies to the specified domain, the specified path, and expires after the specified amount of time.
 
Method Summary
 boolean equals(Object o)
          
static List<Cookie> fromHttpClient(List<Cookie> cookies)
          Converts the specified array of HttpClient cookies into a list of cookies.
 String getDomain()
          Returns the domain to which this cookie applies (null for all domains).
 Date getExpires()
          Returns the date on which this cookie expires (null if it never expires).
 String getName()
          Returns the cookie name.
 String getPath()
          Returns the path to which this cookie applies (null for all paths).
 String getValue()
          Returns the cookie value.
 int hashCode()
          
 boolean isSecure()
          Returns whether or not this cookie is secure (i.e.
 Cookie toHttpClient()
          Converts this cookie to an HttpClient cookie.
static Cookie[] toHttpClient(Collection<Cookie> cookies)
          Converts the specified collection of cookies into an array of HttpClient cookies.
 String toString()
          
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Cookie

public Cookie(String name,
              String value)
Creates a new cookie with the specified name and value. The new cookie applies to all domains and all paths, never expires and is not secure.

Parameters:
name - the cookie name
value - the cookie name

Cookie

public Cookie(String domain,
              String name,
              String value)
Creates a new cookie with the specified name and value which applies to the specified domain. The new cookie applies to all paths, never expires and is not secure.

Parameters:
domain - the domain to which this cookie applies
name - the cookie name
value - the cookie name

Cookie

public Cookie(String domain,
              String name,
              String value,
              String path,
              Date expires,
              boolean secure)
Creates a new cookie with the specified name and value which applies to the specified domain, the specified path, and expires on the specified date.

Parameters:
domain - the domain to which this cookie applies
name - the cookie name
value - the cookie name
path - the path to which this cookie applies
expires - the date on which this cookie expires
secure - whether or not this cookie is secure (i.e. HTTPS vs HTTP)

Cookie

public Cookie(String domain,
              String name,
              String value,
              String path,
              int maxAge,
              boolean secure)
Creates a new cookie with the specified name and value which applies to the specified domain, the specified path, and expires after the specified amount of time.

Parameters:
domain - the domain to which this cookie applies
name - the cookie name
value - the cookie name
path - the path to which this cookie applies
maxAge - the number of seconds for which this cookie is valid; -1 indicates that the cookie should never expire; other negative numbers are not allowed
secure - whether or not this cookie is secure (i.e. HTTPS vs HTTP)
Method Detail

getName

public String getName()
Returns the cookie name.

Returns:
the cookie name

getValue

public String getValue()
Returns the cookie value.

Returns:
the cookie value

getDomain

public String getDomain()
Returns the domain to which this cookie applies (null for all domains).

Returns:
the domain to which this cookie applies (null for all domains)

getPath

public String getPath()
Returns the path to which this cookie applies (null for all paths).

Returns:
the path to which this cookie applies (null for all paths)

getExpires

public Date getExpires()
Returns the date on which this cookie expires (null if it never expires).

Returns:
the date on which this cookie expires (null if it never expires)

isSecure

public boolean isSecure()
Returns whether or not this cookie is secure (i.e. HTTPS vs HTTP).

Returns:
whether or not this cookie is secure (i.e. HTTPS vs HTTP)

toString

public String toString()

Overrides:
toString in class Object

equals

public boolean equals(Object o)

Overrides:
equals in class Object

hashCode

public int hashCode()

Overrides:
hashCode in class Object

toHttpClient

public Cookie toHttpClient()
Converts this cookie to an HttpClient cookie.

Returns:
an HttpClient version of this cookie

toHttpClient

public static Cookie[] toHttpClient(Collection<Cookie> cookies)
Converts the specified collection of cookies into an array of HttpClient cookies.

Parameters:
cookies - the cookies to be converted
Returns:
the specified cookies, as HttpClient cookies

fromHttpClient

public static List<Cookie> fromHttpClient(List<Cookie> cookies)
Converts the specified array of HttpClient cookies into a list of cookies.

Parameters:
cookies - the cookies to be converted
Returns:
the specified HttpClient cookies, as cookies


Copyright © 2002-2010 Gargoyle Software Inc.. All Rights Reserved.