org.apache.chemistry.opencmis.client.bindings.spi.cookies
Class CmisHttpCookie

java.lang.Object
  extended by org.apache.chemistry.opencmis.client.bindings.spi.cookies.CmisHttpCookie
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable

public final class CmisHttpCookie
extends java.lang.Object
implements java.lang.Cloneable, java.io.Serializable

This class represents a http cookie, which indicates the status information between the client agent side and the server side. According to RFC, there are 3 http cookie specifications. This class is compatible with all the three forms. HttpCookie class can accept all these 3 forms of syntax.

See Also:
Serialized Form

Constructor Summary
CmisHttpCookie(java.lang.String name, java.lang.String value)
          Initializes a cookie with the specified name and value.
 
Method Summary
 java.lang.Object clone()
          Answers a copy of this object.
static boolean domainMatches(java.lang.String domain, java.lang.String host)
          A utility method used to check whether the host name is in a domain or not.
 boolean equals(java.lang.Object obj)
          Answers whether two cookies are equal.
 java.lang.String getComment()
          Answers the value of comment attribute(specified in RFC 2965) of this cookie.
 java.lang.String getCommentURL()
          Answers the value of commentURL attribute(specified in RFC 2965) of this cookie.
 boolean getDiscard()
          Answers the value of discard attribute(specified in RFC 2965) of this cookie.
 java.lang.String getDomain()
          Answers the domain name for this cookie in the format specified in RFC 2965
 long getMaxAge()
          Returns the Max-Age value as specified in RFC 2965 of this cookie.
 java.lang.String getName()
          Answers the name for this cookie.
 java.lang.String getPath()
          Answers the path part of a request URL to which this cookie is returned.
 java.lang.String getPortlist()
          Answers the value of port attribute(specified in RFC 2965) of this cookie.
 boolean getSecure()
          Answers true if the browser only sends cookies over a secure protocol.
 java.lang.String getValue()
          Answers the value of this cookie.
 int getVersion()
          Get the version of this cookie
 boolean hasExpired()
          Answers whether the cookie has expired.
 int hashCode()
          Answers hash code of this http cookie.
static java.util.List<CmisHttpCookie> parse(java.lang.String header)
          Constructs a cookie from a string.
 void setComment(java.lang.String purpose)
          Set the value of comment attribute(specified in RFC 2965) of this cookie.
 void setCommentURL(java.lang.String purpose)
          Set the value of commentURL attribute(specified in RFC 2965) of this cookie.
 void setDiscard(boolean discard)
          Set the value of discard attribute(specified in RFC 2965) of this cookie.
 void setDomain(java.lang.String pattern)
          Set the domain value for this cookie.
 void setMaxAge(long expiry)
          Sets the Max-Age value as specified in RFC 2965 of this cookie to expire.
 void setPath(java.lang.String path)
          Set the path to which this cookie is returned.
 void setPortlist(java.lang.String ports)
          Set the value of port attribute(specified in RFC 2965) of this cookie.
 void setSecure(boolean flag)
          Tells the browser whether the cookies should be sent to server through secure protocols.
 void setValue(java.lang.String newValue)
          Sets the value for this cookie after it has been instantiated.
 void setVersion(int v)
          Sets the version of the cookie.
 java.lang.String toString()
          Returns a string to represent the cookie.
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

CmisHttpCookie

public CmisHttpCookie(java.lang.String name,
                      java.lang.String value)
Initializes a cookie with the specified name and value. The name attribute can just contain ASCII characters, which is immutable after creation. Commas, white space and semicolons are not allowed. The $ character is also not allowed to be the beginning of the name. The value attribute depends on what the server side is interested. The setValue method can be used to change it. RFC 2965 is the default cookie specification of this class. If one wants to change the version of the cookie, the setVersion method is available.

Parameters:
name - - the specific name of the cookie
value - - the specific value of the cookie
Throws:
java.lang.IllegalArgumentException - - if the name contains not-allowed or reserved characters
java.lang.NullPointerException - if the value of name is null
Method Detail

domainMatches

public static boolean domainMatches(java.lang.String domain,
                                    java.lang.String host)
A utility method used to check whether the host name is in a domain or not.

Parameters:
domain - the domain to be checked against
host - the host to be checked
Returns:
true if the host is in the domain, false otherwise

parse

public static java.util.List<CmisHttpCookie> parse(java.lang.String header)
Constructs a cookie from a string. The string should comply with set-cookie or set-cookie2 header format as specified in RFC 2965. Since set-cookies2 syntax allows more than one cookie definitions in one header, the returned object is a list.

Parameters:
header - a set-cookie or set-cookie2 header.
Returns:
a list of constructed cookies
Throws:
java.lang.IllegalArgumentException - if the string does not comply with cookie specification, or the cookie name contains illegal characters, or reserved tokens of cookie specification appears
java.lang.NullPointerException - if header is null

clone

public java.lang.Object clone()
Answers a copy of this object.

Overrides:
clone in class java.lang.Object
Returns:
a copy of this cookie

equals

public boolean equals(java.lang.Object obj)
Answers whether two cookies are equal. Two cookies are equal if they have the same domain and name in a case-insensitive mode and path in a case-sensitive mode.

Overrides:
equals in class java.lang.Object
Parameters:
obj - the object to be compared.
Returns:
true if two cookies equals, false otherwise

getComment

public java.lang.String getComment()
Answers the value of comment attribute(specified in RFC 2965) of this cookie.

Returns:
the value of comment attribute

getCommentURL

public java.lang.String getCommentURL()
Answers the value of commentURL attribute(specified in RFC 2965) of this cookie.

Returns:
the value of commentURL attribute

getDiscard

public boolean getDiscard()
Answers the value of discard attribute(specified in RFC 2965) of this cookie.

Returns:
discard value of this cookie

getDomain

public java.lang.String getDomain()
Answers the domain name for this cookie in the format specified in RFC 2965

Returns:
the domain value of this cookie

getMaxAge

public long getMaxAge()
Returns the Max-Age value as specified in RFC 2965 of this cookie.

Returns:
the Max-Age value

getName

public java.lang.String getName()
Answers the name for this cookie.

Returns:
the name for this cookie

getPath

public java.lang.String getPath()
Answers the path part of a request URL to which this cookie is returned. This cookie is visible to all subpaths.

Returns:
the path used to return the cookie

getPortlist

public java.lang.String getPortlist()
Answers the value of port attribute(specified in RFC 2965) of this cookie.

Returns:
port list of this cookie

getSecure

public boolean getSecure()
Answers true if the browser only sends cookies over a secure protocol. False if can send cookies through any protocols.

Returns:
true if sends cookies only through secure protocol, false otherwise

getValue

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

Returns:
the value of this cookie

getVersion

public int getVersion()
Get the version of this cookie

Returns:
0 indicates the original Netscape cookie specification, while 1 indicates RFC 2965/2109 specification.

hasExpired

public boolean hasExpired()
Answers whether the cookie has expired.

Returns:
true is the cookie has expired, false otherwise

hashCode

public int hashCode()
Answers hash code of this http cookie. The result is calculated as below: getName().toLowerCase().hashCode() + getDomain().toLowerCase().hashCode() + getPath().hashCode()

Overrides:
hashCode in class java.lang.Object
Returns:
the hash code of this cookie

setComment

public void setComment(java.lang.String purpose)
Set the value of comment attribute(specified in RFC 2965) of this cookie.

Parameters:
purpose - the comment value to be set

setCommentURL

public void setCommentURL(java.lang.String purpose)
Set the value of commentURL attribute(specified in RFC 2965) of this cookie.

Parameters:
purpose - the value of commentURL attribute to be set

setDiscard

public void setDiscard(boolean discard)
Set the value of discard attribute(specified in RFC 2965) of this cookie.

Parameters:
discard - the value for discard attribute

setDomain

public void setDomain(java.lang.String pattern)
Set the domain value for this cookie. Browsers send the cookie to the domain specified by this value. The form of the domain is specified in RFC 2965.

Parameters:
pattern - the domain pattern

setMaxAge

public void setMaxAge(long expiry)
Sets the Max-Age value as specified in RFC 2965 of this cookie to expire.

Parameters:
expiry - the value used to set the Max-Age value of this cookie

setPath

public void setPath(java.lang.String path)
Set the path to which this cookie is returned. This cookie is visible to all the pages under the path and all subpaths.

Parameters:
path - the path to which this cookie is returned

setPortlist

public void setPortlist(java.lang.String ports)
Set the value of port attribute(specified in RFC 2965) of this cookie.

Parameters:
ports - the value for port attribute

setSecure

public void setSecure(boolean flag)
Tells the browser whether the cookies should be sent to server through secure protocols.

Parameters:
flag - tells browser to send cookie to server only through secure protocol if flag is true

setValue

public void setValue(java.lang.String newValue)
Sets the value for this cookie after it has been instantiated. String newValue can be in BASE64 form. If the version of the cookie is 0, special value as: white space, brackets, parentheses, equals signs, commas, double quotes, slashes, question marks, at signs, colons, and semicolons are not recommended. Empty values may lead to different behavior on different browsers.

Parameters:
newValue - the value for this cookie

setVersion

public void setVersion(int v)
Sets the version of the cookie. 0 indicates the original Netscape cookie specification, while 1 indicates RFC 2965/2109 specification.

Parameters:
v - 0 or 1 as stated above
Throws:
java.lang.IllegalArgumentException - if v is neither 0 nor 1

toString

public java.lang.String toString()
Returns a string to represent the cookie. The format of string follows the cookie specification. The leading token "Cookie" is not included

Overrides:
toString in class java.lang.Object
Returns:
the string format of the cookie object


Copyright © 2009-2011 The Apache Software Foundation. All Rights Reserved.