com.gargoylesoftware.htmlunit
Class CookieManager

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

public class CookieManager
extends Object
implements Serializable

Manages cookies for a WebClient. This class is thread-safe.

Version:
$Revision: 9066 $
Author:
Daniel Gredler, Ahmed Ashour, Nicolas Belisle
See Also:
Serialized Form

Field Summary
static String HTMLUNIT_COOKIE_POLICY
          HtmlUnit's cookie policy is to be browser-compatible.
 
Constructor Summary
CookieManager()
          Creates a new instance.
 
Method Summary
 void addCookie(Cookie cookie)
          Adds the specified cookie.
 void clearCookies()
          Removes all cookies.
 boolean clearExpired(Date date)
          Clears all cookies that have expired before supplied date.
 Cookie getCookie(String name)
          Returns the currently configured cookie with the specified name, or null if one does not exist.
 Set<Cookie> getCookies()
          Returns the currently configured cookies, in an unmodifiable set.
 Set<Cookie> getCookies(URL url)
          Returns the currently configured cookies applicable to the specified URL, in an unmodifiable set.
protected  int getPort(URL url)
          Gets the port of the URL.
 boolean isCookiesEnabled()
          Returns true if cookies are enabled.
 void removeCookie(Cookie cookie)
          Removes the specified cookie.
 void setCookiesEnabled(boolean enabled)
          Enables/disables cookie support.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

HTMLUNIT_COOKIE_POLICY

public static final String HTMLUNIT_COOKIE_POLICY
HtmlUnit's cookie policy is to be browser-compatible. Code which requires access to HtmlUnit's cookie policy should use this constant, rather than making assumptions and using one of the HttpClient CookieSpecs constants directly.

See Also:
Constant Field Values
Constructor Detail

CookieManager

public CookieManager()
Creates a new instance.

Method Detail

setCookiesEnabled

public void setCookiesEnabled(boolean enabled)
Enables/disables cookie support. Cookies are enabled by default.

Parameters:
enabled - true to enable cookie support, false otherwise

isCookiesEnabled

public boolean isCookiesEnabled()
Returns true if cookies are enabled. Cookies are enabled by default.

Returns:
true if cookies are enabled, false otherwise

getCookies

public Set<Cookie> getCookies()
Returns the currently configured cookies, in an unmodifiable set.

Returns:
the currently configured cookies, in an unmodifiable set

getCookies

public Set<Cookie> getCookies(URL url)
Returns the currently configured cookies applicable to the specified URL, in an unmodifiable set.

Parameters:
url - the URL on which to filter the returned cookies
Returns:
the currently configured cookies applicable to the specified URL, in an unmodifiable set

clearExpired

public boolean clearExpired(Date date)
Clears all cookies that have expired before supplied date.

Parameters:
date - the date to use for comparison when clearing expired cookies
Returns:
whether any cookies were found expired, and were cleared

getPort

protected int getPort(URL url)
Gets the port of the URL. This functionality is implemented here as protected method to allow subclass to change it as workaround to

getCookie

public Cookie getCookie(String name)
Returns the currently configured cookie with the specified name, or null if one does not exist.

Parameters:
name - the name of the cookie to return
Returns:
the currently configured cookie with the specified name, or null if one does not exist

addCookie

public void addCookie(Cookie cookie)
Adds the specified cookie.

Parameters:
cookie - the cookie to add

removeCookie

public void removeCookie(Cookie cookie)
Removes the specified cookie.

Parameters:
cookie - the cookie to remove

clearCookies

public void clearCookies()
Removes all cookies.



Copyright © 2002–2014 Gargoyle Software Inc.. All rights reserved.