Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

com.sonalb.net.http.cookie
Class Cookie  view Cookie download Cookie.java

java.lang.Object
  extended bycom.sonalb.net.http.cookie.Cookie
All Implemented Interfaces:
java.lang.Cloneable, java.lang.Comparable, java.io.Serializable

public class Cookie
extends java.lang.Object
implements java.lang.Cloneable, java.io.Serializable, java.lang.Comparable

The data structure representing a cookie. Supports both Netscape (Version 0) and RFC2965 (Version 1) cookies. The fields common to both these versions are listed below:


Field Summary
private  boolean bExplicitDomain
           
private  boolean bExplicitExpires
           
private  boolean bExplicitMaxage
           
private  boolean bExplicitPath
           
private  boolean bExplicitPort
           
private  boolean bPortListSpecified
           
private  java.lang.String comment
           
private  java.net.URL commentURL
           
static java.lang.String CVSID
           
private  boolean discard
           
private  java.lang.String domain
           
private  java.util.Date expires
           
private  java.lang.Object lockDiscard
           
private  java.lang.Object lockMaxage
           
private  java.lang.Object lockSecure
           
private  int maxage
           
private  java.lang.String name
           
private  java.lang.String path
           
private  java.lang.String portList
           
private  boolean secure
           
private  java.lang.String value
           
private  java.lang.String version
           
 
Constructor Summary
(package private) Cookie()
           
  Cookie(java.lang.String name, java.lang.String value, java.lang.String domain, java.lang.String path)
          Creates cookie instance.
protected Cookie(java.lang.String name, java.lang.String value, java.lang.String domain, java.lang.String path, java.net.URL requestURL)
           
  Cookie(java.lang.String name, java.lang.String value, java.net.URL requestURL)
          Creates cookie instance.
 
Method Summary
 java.lang.Object clone()
          This method may be called to create a new copy of the Object.
 int compareTo(java.lang.Object o)
          Compares one Cookie with another.
 boolean equals(java.lang.Object obj)
          Checks whether two cookies are equal.
protected  boolean explicitDomain()
           
protected  boolean explicitExpires()
           
protected  boolean explicitMaxage()
           
protected  boolean explicitPath()
           
protected  boolean explicitPort()
           
 java.lang.String getComment()
          Gets the comment for this cookie.
 java.net.URL getCommentURL()
          Gets the comment URL for this cookie.
 java.lang.String getDomain()
          Gets the domain in which this cookie is valid.
 java.util.Date getExpires()
          Gets the date-time when this cookie expires.
 int getMaxAge()
          Gets the amount of time this Cookie is valid, measured in seconds from the time the value was set.
 java.lang.String getName()
          Gets the name of this cookie.
 java.lang.String getPath()
          Gets the path for this cookie.
 java.lang.String getPortList()
          Gets the list of ports to which this cookie can be sent.
 java.lang.String getValue()
          Gets the value of this cookie.
 java.lang.String getVersion()
          Gets the version of this Cookie.
 boolean hasExpired()
          Checks whether this cookie's lifetime has expired or not.
 boolean hasExpired(java.util.Date d)
          Checks whether this cookie's lifetime has expired or not.
private  void initializeFields()
           
 boolean isDiscardable()
          Checks whether this cookie can be discarded once the session is over.
 boolean isSecure()
          Checks whether this cookie will be sent over secure channels only.
protected  boolean isValid()
           
protected  boolean portListSpecified()
           
 void setComment(java.lang.String comment)
          Sets the comment for this cookie.
 void setCommentURL(java.net.URL url)
          Sets the comment URL for this cookie.
 void setDiscard(boolean bDiscard)
          Sets the discard status of this cookie.
 void setDomain(java.lang.String domain)
          Sets the domain for this Cookie.
protected  void setDomain(java.lang.String domain, java.net.URL requestURL)
           
 void setDomain(java.net.URL requestURL)
          Sets the domain for this Cookie.
 void setExpires(java.util.Date expires)
          Sets the date-time when this cookie expires.
 void setMaxAge(int maxage)
          Sets the lifetime of this Cookie.
 void setMaxAge(int maxage, java.util.Date base)
          Sets the lifetime of this Cookie.
protected  void setMaxAge(int maxage, java.util.Date base, boolean bInsider)
           
 void setName(java.lang.String name)
          Sets the Cookie name.
 void setPath(java.lang.String path)
          Sets the path for this Cookie.
protected  void setPath(java.lang.String path, java.net.URL requestURL)
           
 void setPath(java.net.URL requestURL)
          Sets the path for this Cookie.
 void setPort(int p)
          Sets the port to which this cookie can be sent.
protected  void setPort(int p, java.net.URL url)
           
 void setPort(java.net.URL url)
          Sets the port to which this cookie can be sent.
 void setPortList(int[] ports)
          Sets the list of ports to which this Cookie can be sent.
 void setSecure(boolean bSecure)
          Sets whether this cookie should be sent only over secure channels.
 void setValue(java.lang.String value)
          Sets the Cookie value.
 void setVersion(java.lang.String version)
          Sets the Cookie version.
 java.lang.String toString()
          Convert this Object to a human-readable String.
 
Methods inherited from class java.lang.Object
finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

CVSID

public static final java.lang.String CVSID
See Also:
Constant Field Values

name

private java.lang.String name

value

private java.lang.String value

comment

private java.lang.String comment

commentURL

private java.net.URL commentURL

discard

private boolean discard

domain

private java.lang.String domain

maxage

private int maxage

path

private java.lang.String path

portList

private java.lang.String portList

secure

private boolean secure

version

private java.lang.String version

expires

private java.util.Date expires

lockSecure

private java.lang.Object lockSecure

lockDiscard

private java.lang.Object lockDiscard

lockMaxage

private java.lang.Object lockMaxage

bExplicitDomain

private boolean bExplicitDomain

bExplicitExpires

private boolean bExplicitExpires

bExplicitMaxage

private boolean bExplicitMaxage

bExplicitPath

private boolean bExplicitPath

bExplicitPort

private boolean bExplicitPort

bPortListSpecified

private boolean bPortListSpecified
Constructor Detail

Cookie

public Cookie(java.lang.String name,
              java.lang.String value,
              java.lang.String domain,
              java.lang.String path)
Creates cookie instance.


Cookie

public Cookie(java.lang.String name,
              java.lang.String value,
              java.net.URL requestURL)
Creates cookie instance. The path and domain are picked up from the request URL.


Cookie

protected Cookie(java.lang.String name,
                 java.lang.String value,
                 java.lang.String domain,
                 java.lang.String path,
                 java.net.URL requestURL)

Cookie

Cookie()
Method Detail

initializeFields

private void initializeFields()

clone

public java.lang.Object clone()
                       throws java.lang.CloneNotSupportedException
Description copied from class: java.lang.Object
This method may be called to create a new copy of the Object. The typical behavior is as follows:
  • o == o.clone() is false
  • o.getClass() == o.clone().getClass() is true
  • o.equals(o) is true

However, these are not strict requirements, and may be violated if necessary. Of the three requirements, the last is the most commonly violated, particularly if the subclass does not override Object.equals(Object)>Object.equals(Object) 55 .

If the Object you call clone() on does not implement java.lang.Cloneable (which is a placeholder interface), then a CloneNotSupportedException is thrown. Notice that Object does not implement Cloneable; this method exists as a convenience for subclasses that do.

Object's implementation of clone allocates space for the new Object using the correct class, without calling any constructors, and then fills in all of the new field values with the old field values. Thus, it is a shallow copy. However, subclasses are permitted to make a deep copy.

All array types implement Cloneable, and override this method as follows (it should never fail):

 public Object clone()
 {
   try
     {
       super.clone();
     }
   catch (CloneNotSupportedException e)
     {
       throw new InternalError(e.getMessage());
     }
 }
 


compareTo

public int compareTo(java.lang.Object o)
Compares one Cookie with another. The natural ordering is such that it follows the path specificity rule laid down in RFC2695. Thus more specific path ("/acme/corp") comes before ("is less than") less specific path ("/acme").

Specified by:
compareTo in interface java.lang.Comparable

isValid

protected boolean isValid()

setName

public void setName(java.lang.String name)
Sets the Cookie name.


setValue

public void setValue(java.lang.String value)
Sets the Cookie value.


setMaxAge

protected void setMaxAge(int maxage,
                         java.util.Date base,
                         boolean bInsider)

setMaxAge

public void setMaxAge(int maxage)
Sets the lifetime of this Cookie. Applicable only to Version 1 cookies.


setMaxAge

public void setMaxAge(int maxage,
                      java.util.Date base)
Sets the lifetime of this Cookie. Applicable only to Version 1 cookies.


explicitDomain

protected boolean explicitDomain()

explicitPath

protected boolean explicitPath()

explicitPort

protected boolean explicitPort()

explicitExpires

protected boolean explicitExpires()

explicitMaxage

protected boolean explicitMaxage()

portListSpecified

protected boolean portListSpecified()

getMaxAge

public int getMaxAge()
Gets the amount of time this Cookie is valid, measured in seconds from the time the value was set. Applicable only to Version 0 cookies.


setExpires

public void setExpires(java.util.Date expires)
Sets the date-time when this cookie expires. Applicable only to Version 0 cookies.


setVersion

public void setVersion(java.lang.String version)
Sets the Cookie version. The version determines what fields and methods are valid for a Cookie instance. It also determines the format in which the Cookie is sent with a request.


getVersion

public java.lang.String getVersion()
Gets the version of this Cookie.


setPath

protected void setPath(java.lang.String path,
                       java.net.URL requestURL)

setPath

public void setPath(java.lang.String path)
Sets the path for this Cookie.


setPath

public void setPath(java.net.URL requestURL)
Sets the path for this Cookie. Path is extracted from the URL.


setDomain

protected void setDomain(java.lang.String domain,
                         java.net.URL requestURL)

setDomain

public void setDomain(java.lang.String domain)
Sets the domain for this Cookie. The domain determines which hosts can receive this Cookie.


setDomain

public void setDomain(java.net.URL requestURL)
Sets the domain for this Cookie. The domain determines which hosts can receive this Cookie.


setPortList

public void setPortList(int[] ports)
Sets the list of ports to which this Cookie can be sent. Applicable only to Version 1 cookies.


setPort

public void setPort(int p)
Sets the port to which this cookie can be sent. Applicable only to Version 1 cookies.


setPort

public void setPort(java.net.URL url)
Sets the port to which this cookie can be sent. Port is extracted from URL. Applicable only to Version 1 cookies.


setPort

protected void setPort(int p,
                       java.net.URL url)

getPortList

public java.lang.String getPortList()
Gets the list of ports to which this cookie can be sent. Applicable only to Version 1 cookies.


setSecure

public void setSecure(boolean bSecure)
Sets whether this cookie should be sent only over secure channels.


getName

public java.lang.String getName()
Gets the name of this cookie.


getValue

public java.lang.String getValue()
Gets the value of this cookie.


getComment

public java.lang.String getComment()
Gets the comment for this cookie.


setComment

public void setComment(java.lang.String comment)
Sets the comment for this cookie. Comment has no functional value.


setCommentURL

public void setCommentURL(java.net.URL url)
Sets the comment URL for this cookie. URL has no functional value.


getCommentURL

public java.net.URL getCommentURL()
Gets the comment URL for this cookie.


getExpires

public java.util.Date getExpires()
Gets the date-time when this cookie expires. Note that this can be called on both Version 0 AND Version 1 cookies.


isDiscardable

public boolean isDiscardable()
Checks whether this cookie can be discarded once the session is over. This is different from the lifetime of the cookie.


setDiscard

public void setDiscard(boolean bDiscard)
Sets the discard status of this cookie. This determines whether the cookie is valid after the session is over. It is different from lifetime. Applicable only to Version 1 cookies.


getDomain

public java.lang.String getDomain()
Gets the domain in which this cookie is valid.


getPath

public java.lang.String getPath()
Gets the path for this cookie.


isSecure

public boolean isSecure()
Checks whether this cookie will be sent over secure channels only.


hasExpired

public boolean hasExpired()
Checks whether this cookie's lifetime has expired or not. The lifetime has expired if:
  • The Max-Age (for Version 1 cookie) was explicitly set to 0
  • The delta-t seconds set by Max-Age have passed
  • The date-time now is greater than what was set to be the expiry date-time
The current system time is used for lifetime calculation.
If none of these conditions are satisfied, or if no explicit lifetime information was set the cookie is deemed to not have expired.


hasExpired

public boolean hasExpired(java.util.Date d)
Checks whether this cookie's lifetime has expired or not. The lifetime has expired if:
  • The Max-Age (for Version 1 cookie) was explicitly set to 0
  • The delta-t seconds set by Max-Age have passed
  • The date-time as specified by the input is greater than what was set to be the expiry date-time
The input date-time is used for lifetime calculation.
If none of these conditions are satisfied, or if no explicit lifetime information was set the cookie is deemed to not have expired.


equals

public boolean equals(java.lang.Object obj)
Checks whether two cookies are equal. Two cookies are deemed to be equal, when all of the following conditions are satisfied:
  • They have the same name
  • They have the same domain
  • They have the same path
Note that the cookie value is NOT used for equality determination.


toString

public java.lang.String toString()
Description copied from class: java.lang.Object
Convert this Object to a human-readable String. There are no limits placed on how long this String should be or what it should contain. We suggest you make it as intuitive as possible to be able to place it into System.out.println() 55 and such.

It is typical, but not required, to ensure that this method never completes abruptly with a java.lang.RuntimeException.

This method will be called when performing string concatenation with this object. If the result is null, string concatenation will instead use "null".

The default implementation returns getClass().getName() + "@" + Integer.toHexString(hashCode()).