FileDocCategorySizeDatePackage
BasicClientCookie.javaAPI DocAndroid 1.5 API10329Wed May 06 22:41:10 BST 2009org.apache.http.impl.cookie

BasicClientCookie

public class BasicClientCookie extends Object implements SetCookie, Cloneable, ClientCookie
HTTP "magic-cookie" represents a piece of state information that the HTTP agent and the target server can exchange to maintain a session.
author
B.C. Holmes
author
Park, Sung-Gu
author
Doug Sale
author
Rod Waldhoff
author
dIon Gillard
author
Sean C. Sullivan
author
John Evans
author
Marc A. Saegesser
author
Oleg Kalnichevski
author
Mike Bowler
version
$Revision: 659191 $

Fields Summary
private final String
name
Cookie name
private Map
attribs
Cookie attributes as specified by the origin server
private String
value
Cookie value
private String
cookieComment
Comment attribute.
private String
cookieDomain
Domain attribute.
private Date
cookieExpiryDate
Expiration {@link Date}.
private String
cookiePath
Path attribute.
private boolean
isSecure
My secure flag.
private int
cookieVersion
The version of the cookie specification I was created from.
Constructors Summary
public BasicClientCookie(String name, String value)
Default Constructor taking a name and a value. The value may be null.

param
name The name.
param
value The value.

        super();
        if (name == null) {
            throw new IllegalArgumentException("Name may not be null");
        }
        this.name = name;
        this.attribs = new HashMap<String, String>();
        this.value = value;
    
Methods Summary
public java.lang.Objectclone()

        BasicClientCookie clone = (BasicClientCookie) super.clone();
        clone.attribs = new HashMap<String, String>(this.attribs);
        return clone;
    
public booleancontainsAttribute(java.lang.String name)

        return this.attribs.get(name) != null;
    
public java.lang.StringgetAttribute(java.lang.String name)

        return this.attribs.get(name);
    
public java.lang.StringgetComment()
Returns the comment describing the purpose of this cookie, or null if no such comment has been defined.

return
comment
see
#setComment(String)

        return cookieComment;
    
public java.lang.StringgetCommentURL()
Returns null. Cookies prior to RFC2965 do not set this attribute

        return null;
    
public java.lang.StringgetDomain()
Returns domain attribute of the cookie.

return
the value of the domain attribute
see
#setDomain(java.lang.String)

        return cookieDomain;
    
public java.util.DategetExpiryDate()
Returns the expiration {@link Date} of the cookie, or null if none exists.

Note: the object returned by this method is considered immutable. Changing it (e.g. using setTime()) could result in undefined behaviour. Do so at your peril.

return
Expiration {@link Date}, or null.
see
#setExpiryDate(java.util.Date)

        return cookieExpiryDate;
    
public java.lang.StringgetName()
Returns the name.

return
String name The name

        return this.name;
    
public java.lang.StringgetPath()
Returns the path attribute of the cookie

return
The value of the path attribute.
see
#setPath(java.lang.String)

        return cookiePath;
    
public int[]getPorts()
Returns null. Cookies prior to RFC2965 do not set this attribute

        return null;
    
public java.lang.StringgetValue()
Returns the value.

return
String value The current value.

        return this.value;
    
public intgetVersion()
Returns the version of the cookie specification to which this cookie conforms.

return
the version of the cookie.
see
#setVersion(int)

        return cookieVersion;
    
public booleanisExpired(java.util.Date date)
Returns true if this cookie has expired.

param
date Current time
return
true if the cookie has expired.

        if (date == null) {
            throw new IllegalArgumentException("Date may not be null");
        }
        return (cookieExpiryDate != null  
            && cookieExpiryDate.getTime() <= date.getTime());
    
public booleanisPersistent()
Returns false if the cookie should be discarded at the end of the "session"; true otherwise.

return
false if the cookie should be discarded at the end of the "session"; true otherwise

        return (null != cookieExpiryDate);
    
public booleanisSecure()

return
true if this cookie should only be sent over secure connections.
see
#setSecure(boolean)

        return isSecure;
    
public voidsetAttribute(java.lang.String name, java.lang.String value)

        this.attribs.put(name, value);
    
public voidsetComment(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.

param
comment
see
#getComment()

        cookieComment = comment;
    
public voidsetDomain(java.lang.String domain)
Sets the domain attribute.

param
domain The value of the domain attribute
see
#getDomain

        if (domain != null) {
            cookieDomain = domain.toLowerCase(Locale.ENGLISH);
        } else {
            cookieDomain = null;
        }
    
public voidsetExpiryDate(java.util.Date expiryDate)
Sets expiration date.

Note: the object returned by this method is considered immutable. Changing it (e.g. using setTime()) could result in undefined behaviour. Do so at your peril.

param
expiryDate the {@link Date} after which this cookie is no longer valid.
see
#getExpiryDate

        cookieExpiryDate = expiryDate;
    
public voidsetPath(java.lang.String path)
Sets the path attribute.

param
path The value of the path attribute
see
#getPath

        cookiePath = path;
    
public voidsetSecure(boolean secure)
Sets the secure attribute of the cookie.

When true 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.

param
secure The value of the secure attribute
see
#isSecure()

        isSecure = secure;
    
public voidsetValue(java.lang.String value)
Sets the value

param
value

        this.value = value;
    
public voidsetVersion(int version)
Sets the version of the cookie specification to which this cookie conforms.

param
version the version of the cookie.
see
#getVersion

        cookieVersion = version;
    
public java.lang.StringtoString()

        StringBuilder buffer = new StringBuilder();
        buffer.append("[version: ");
        buffer.append(Integer.toString(this.cookieVersion));
        buffer.append("]");
        buffer.append("[name: ");
        buffer.append(this.name);
        buffer.append("]");
        buffer.append("[value: ");
        buffer.append(this.value);
        buffer.append("]");
        buffer.append("[domain: ");
        buffer.append(this.cookieDomain);
        buffer.append("]");
        buffer.append("[path: ");
        buffer.append(this.cookiePath);
        buffer.append("]");
        buffer.append("[expiry: ");
        buffer.append(this.cookieExpiryDate);
        buffer.append("]");
        return buffer.toString();