Cookie2 (HttpClient Library (Version 3.1))
Date: 2016-03-09

org.apache.commons.httpclient.cookie

## Class Cookie2

- java.lang.Object
- - org.apache.commons.httpclient.NameValuePair
  - - org.apache.commons.httpclient.Cookie
    - - org.apache.commons.httpclient.cookie.Cookie2

- All Implemented Interfaces:
    java.io.Serializable, java.util.Comparator

      public class Cookie2
      extends Cookie

  Cookie class for `RFC2965Spec` cookie specification. It extends `Cookie` class and adds newer cookie attributes and functions required for this specification.

  Since:
    3.1
  Author:
    Samit Jain (jain.samit@gmail.com)
  See Also:
    Serialized Form

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static java.lang.String` | `COMMENT`
    `static java.lang.String` | `COMMENTURL`
    `static java.lang.String` | `DISCARD`
    `static java.lang.String` | `DOMAIN`
    `static java.lang.String` | `MAXAGE`
    `static java.lang.String` | `PATH`
    `static java.lang.String` | `PORT`
    `static java.lang.String` | `SECURE`
    `static java.lang.String` | `VERSION`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `Cookie2()` Default constructor.
    `Cookie2(java.lang.String domain, java.lang.String name, java.lang.String value)` Creates a cookie with the given name, value and domain attribute.
    `Cookie2(java.lang.String domain, java.lang.String name, java.lang.String value, java.lang.String path, java.util.Date expires, boolean secure)` Creates a cookie with the given name, value, domain attribute, path attribute, expiration attribute, and secure attribute
    `Cookie2(java.lang.String domain, java.lang.String name, java.lang.String value, java.lang.String path, java.util.Date expires, boolean secure, int[] ports)` Creates a cookie with the given name, value, domain attribute, path attribute, expiration attribute, secure attribute, and ports attribute.

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `java.lang.String` | `getCommentURL()` If a user agent (web browser) presents this cookie to a user, the cookie's purpose will be described by the information at this URL.
    `int[]` | `getPorts()` Get the Port attribute.
    `boolean` | `isPersistent()` Returns `false` if the cookie should be discarded at the end of the "session"; `true` otherwise.
    `boolean` | `isPortAttributeBlank()`
    `boolean` | `isPortAttributeSpecified()`
    `boolean` | `isVersionAttributeSpecified()`
    `void` | `setCommentURL(java.lang.String commentURL)` If a user agent (web browser) presents this cookie to a user, the cookie's purpose will be described by the information at this URL.
    `void` | `setDiscard(boolean toDiscard)` Set the Discard attribute.
    `void` | `setPortAttributeBlank(boolean value)` Indicates whether the Port attribute in `Set-Cookie2` header contains no value (is of the form Port="").
    `void` | `setPortAttributeSpecified(boolean value)` Indicates whether the cookie had a port attribute specified in the `Set-Cookie2` response header.
    `void` | `setPorts(int[] ports)` Set the Port attribute.
    `void` | `setVersionAttributeSpecified(boolean value)` Indicates whether the cookie had a version attribute specified in the `Set-Cookie2` response header.
    `java.lang.String` | `toExternalForm()` Return a textual representation of the cookie.

    - ### Methods inherited from class org.apache.commons.httpclient.Cookie

      `compare, equals, getComment, getDomain, getExpiryDate, getPath, getSecure, getVersion, hashCode, isDomainAttributeSpecified, isExpired, isExpired, isPathAttributeSpecified, setComment, setDomain, setDomainAttributeSpecified, setExpiryDate, setPath, setPathAttributeSpecified, setSecure, setVersion, toString`

    - ### Methods inherited from class org.apache.commons.httpclient.NameValuePair

      `getName, getValue, setName, setValue`

    - ### Methods inherited from class java.lang.Object

      `clone, finalize, getClass, notify, notifyAll, wait, wait, wait`

- - ### Field Detail

    - #### DOMAIN

          public static final java.lang.String DOMAIN

      See Also:
        Constant Field Values

    - #### PATH

          public static final java.lang.String PATH

      See Also:
        Constant Field Values

    - #### PORT

          public static final java.lang.String PORT

      See Also:
        Constant Field Values

    - #### VERSION

          public static final java.lang.String VERSION

      See Also:
        Constant Field Values

    - #### SECURE

          public static final java.lang.String SECURE

      See Also:
        Constant Field Values

    - #### MAXAGE

          public static final java.lang.String MAXAGE

      See Also:
        Constant Field Values

    - #### COMMENT

          public static final java.lang.String COMMENT

      See Also:
        Constant Field Values

    - #### COMMENTURL

          public static final java.lang.String COMMENTURL

      See Also:
        Constant Field Values

    - #### DISCARD

          public static final java.lang.String DISCARD

      See Also:
        Constant Field Values

  - ### Constructor Detail

    - #### Cookie2

          public Cookie2()

      Default constructor. Creates a blank cookie

    - #### Cookie2

          public Cookie2(java.lang.String domain,
                 java.lang.String name,
                 java.lang.String value)

      Creates a cookie with the given name, value and domain attribute.
      Parameters:
        `name` - the cookie name
        `value` - the cookie value
        `domain` - the domain this cookie can be sent to

    - #### Cookie2

          public Cookie2(java.lang.String domain,
                 java.lang.String name,
                 java.lang.String value,
                 java.lang.String path,
                 java.util.Date expires,
                 boolean secure)

      Creates a cookie with the given name, value, domain attribute, path attribute, expiration attribute, and secure attribute
      Parameters:
        `name` - the cookie name
        `value` - the cookie value
        `domain` - the domain this cookie can be sent to
        `path` - the path prefix for which this cookie can be sent
        `expires` - the `Date` at which this cookie expires, or `null` if the cookie expires at the end of the session
        `secure` - if true this cookie can only be sent over secure connections
      Throws:
        `java.lang.IllegalArgumentException` - If cookie name is null or blank, cookie name contains a blank, or cookie name starts with character $

    - #### Cookie2

          public Cookie2(java.lang.String domain,
                 java.lang.String name,
                 java.lang.String value,
                 java.lang.String path,
                 java.util.Date expires,
                 boolean secure,
                 int[] ports)

      Creates a cookie with the given name, value, domain attribute, path attribute, expiration attribute, secure attribute, and ports attribute.
      Parameters:
        `name` - the cookie name
        `value` - the cookie value
        `domain` - the domain this cookie can be sent to
        `path` - the path prefix for which this cookie can be sent
        `expires` - the `Date` at which this cookie expires, or `null` if the cookie expires at the end of the session
        `secure` - if true this cookie can only be sent over secure connections
        `ports` - the ports for which this cookie can be sent
      Throws:
        `java.lang.IllegalArgumentException` - If cookie name is null or blank, cookie name contains a blank, or cookie name starts with character $

  - ### Method Detail

    - #### getCommentURL

          public java.lang.String getCommentURL()

      If a user agent (web browser) presents this cookie to a user, the cookie's purpose will be described by the information at this URL.
      See Also:
        `setCommentURL(String)`

    - #### setCommentURL

          public void setCommentURL(java.lang.String commentURL)

      If a user agent (web browser) presents this cookie to a user, the cookie's purpose will be described by the information at this URL.
      Parameters:
        `commentURL` -
      See Also:
        `getCommentURL()`

    - #### getPorts

          public int[] getPorts()

      Get the Port attribute. It restricts the ports to which a cookie may be returned in a Cookie request header.
      See Also:
        `setPorts(int[])`

    - #### setPorts

          public void setPorts(int[] ports)

      Set the Port attribute. It restricts the ports to which a cookie may be returned in a Cookie request header.
      Parameters:
        `ports` -
      See Also:
        `getPorts()`

    - #### setDiscard

          public void setDiscard(boolean toDiscard)

      Set the Discard attribute. Note: `Discard` attribute overrides `Max-age`.
      See Also:
        `isPersistent()`

    - #### isPersistent

          public boolean isPersistent()

      Returns `false` if the cookie should be discarded at the end of the "session"; `true` otherwise.
      Overrides:
        `isPersistent` in class `Cookie`
      Returns:
        `false` if the cookie should be discarded at the end of the "session"; `true` otherwise

    - #### setPortAttributeSpecified

          public void setPortAttributeSpecified(boolean value)

      Indicates whether the cookie had a port attribute specified in the `Set-Cookie2` response header.
      Parameters:
        `value` - `true` if port attribute is specified in response header.
      See Also:
        `isPortAttributeSpecified()`

    - #### isPortAttributeSpecified

          public boolean isPortAttributeSpecified()

      Returns:
        `true` if cookie port attribute was specified in the `Set-Cookie2` header.
      See Also:
        `setPortAttributeSpecified(boolean)`

    - #### setPortAttributeBlank

          public void setPortAttributeBlank(boolean value)

      Indicates whether the Port attribute in `Set-Cookie2` header contains no value (is of the form Port="").

      This value is required for generating the `Cookie` request header because the specification requires that if `Set-Cookie2` header contains a blank value for port attribute, the `Cookie` header should also contain a port attribute with no value.

      Parameters:
        `value` - `true` if port attribute is specified as blank in response header.
      See Also:
        `isPortAttributeBlank`

    - #### isPortAttributeBlank

          public boolean isPortAttributeBlank()

      Returns:
        `true` if the port attribute in `Set-Cookie2` header had no value (was of the form Port="").
      See Also:
        `setPortAttributeBlank(boolean)`

    - #### setVersionAttributeSpecified

          public void setVersionAttributeSpecified(boolean value)

      Indicates whether the cookie had a version attribute specified in the `Set-Cookie2` response header.
      Parameters:
        `value` - `true` if version attribute is specified in response header.
      See Also:
        `isVersionAttributeSpecified()`

    - #### isVersionAttributeSpecified

          public boolean isVersionAttributeSpecified()

      Returns:
        `true` if cookie version attribute was specified in the `Set-Cookie2` header.
      See Also:
        `setVersionAttributeSpecified(boolean)`

    - #### toExternalForm

          public java.lang.String toExternalForm()

      Return a textual representation of the cookie.
      Overrides:
        `toExternalForm` in class `Cookie`
      Returns:
        string.

Copyright (c) 1999-2005 - Apache Software Foundation