Note: the object returned by this method is michael@0: * considered immutable. Changing it (e.g. using setTime()) could result michael@0: * in undefined behaviour. Do so at your peril.
michael@0: * @return Expiration {@link Date}, or null. michael@0: * michael@0: * @see #setExpiryDate(java.util.Date) michael@0: * michael@0: */ michael@0: public Date getExpiryDate() { michael@0: return cookieExpiryDate; michael@0: } michael@0: michael@0: /** michael@0: * Sets expiration date. michael@0: *Note: the object returned by this method is considered michael@0: * immutable. Changing it (e.g. using setTime()) could result in undefined michael@0: * behaviour. Do so at your peril.
michael@0: * michael@0: * @param expiryDate the {@link Date} after which this cookie is no longer valid. michael@0: * michael@0: * @see #getExpiryDate michael@0: * michael@0: */ michael@0: public void setExpiryDate (Date expiryDate) { michael@0: cookieExpiryDate = expiryDate; michael@0: } michael@0: michael@0: michael@0: /** michael@0: * Returns false if the cookie should be discarded at the end michael@0: * of the "session"; true otherwise. michael@0: * michael@0: * @return false if the cookie should be discarded at the end michael@0: * of the "session"; true otherwise michael@0: */ michael@0: public boolean isPersistent() { michael@0: return (null != cookieExpiryDate); michael@0: } michael@0: michael@0: michael@0: /** michael@0: * Returns domain attribute of the cookie. michael@0: * michael@0: * @return the value of the domain attribute michael@0: * michael@0: * @see #setDomain(java.lang.String) michael@0: */ michael@0: public String getDomain() { michael@0: return cookieDomain; michael@0: } michael@0: michael@0: /** michael@0: * Sets the domain attribute. michael@0: * michael@0: * @param domain The value of the domain attribute michael@0: * michael@0: * @see #getDomain michael@0: */ michael@0: public void setDomain(String domain) { michael@0: if (domain != null) { michael@0: cookieDomain = domain.toLowerCase(Locale.ENGLISH); michael@0: } else { michael@0: cookieDomain = null; michael@0: } michael@0: } michael@0: michael@0: michael@0: /** michael@0: * Returns the path attribute of the cookie michael@0: * michael@0: * @return The value of the path attribute. michael@0: * michael@0: * @see #setPath(java.lang.String) michael@0: */ michael@0: public String getPath() { michael@0: return cookiePath; michael@0: } michael@0: michael@0: /** michael@0: * Sets the path attribute. michael@0: * michael@0: * @param path The value of the path attribute michael@0: * michael@0: * @see #getPath michael@0: * michael@0: */ michael@0: public void setPath(String path) { michael@0: cookiePath = path; michael@0: } michael@0: michael@0: /** michael@0: * @returntrue
if this cookie should only be sent over secure connections.
michael@0: * @see #setSecure(boolean)
michael@0: */
michael@0: public boolean isSecure() {
michael@0: return isSecure;
michael@0: }
michael@0:
michael@0: /**
michael@0: * Sets the secure attribute of the cookie.
michael@0: *
michael@0: * When true the cookie should only be sent
michael@0: * using a secure protocol (https). This should only be set when
michael@0: * the cookie's originating server used a secure protocol to set the
michael@0: * cookie's value.
michael@0: *
michael@0: * @param secure The value of the secure attribute
michael@0: *
michael@0: * @see #isSecure()
michael@0: */
michael@0: public void setSecure (boolean secure) {
michael@0: isSecure = secure;
michael@0: }
michael@0:
michael@0:
michael@0: /**
michael@0: * Returns null. Cookies prior to RFC2965 do not set this attribute
michael@0: */
michael@0: public int[] getPorts() {
michael@0: return null;
michael@0: }
michael@0:
michael@0:
michael@0: /**
michael@0: * Returns the version of the cookie specification to which this
michael@0: * cookie conforms.
michael@0: *
michael@0: * @return the version of the cookie.
michael@0: *
michael@0: * @see #setVersion(int)
michael@0: *
michael@0: */
michael@0: public int getVersion() {
michael@0: return cookieVersion;
michael@0: }
michael@0:
michael@0: /**
michael@0: * Sets the version of the cookie specification to which this
michael@0: * cookie conforms.
michael@0: *
michael@0: * @param version the version of the cookie.
michael@0: *
michael@0: * @see #getVersion
michael@0: */
michael@0: public void setVersion(int version) {
michael@0: cookieVersion = version;
michael@0: }
michael@0:
michael@0: /**
michael@0: * Returns true if this cookie has expired.
michael@0: * @param date Current time
michael@0: *
michael@0: * @return true if the cookie has expired.
michael@0: */
michael@0: public boolean isExpired(final Date date) {
michael@0: if (date == null) {
michael@0: throw new IllegalArgumentException("Date may not be null");
michael@0: }
michael@0: return (cookieExpiryDate != null
michael@0: && cookieExpiryDate.getTime() <= date.getTime());
michael@0: }
michael@0:
michael@0: public void setAttribute(final String name, final String value) {
michael@0: this.attribs.put(name, value);
michael@0: }
michael@0:
michael@0: public String getAttribute(final String name) {
michael@0: return this.attribs.get(name);
michael@0: }
michael@0:
michael@0: public boolean containsAttribute(final String name) {
michael@0: return this.attribs.get(name) != null;
michael@0: }
michael@0:
michael@0: @Override
michael@0: public Object clone() throws CloneNotSupportedException {
michael@0: BasicClientCookie clone = (BasicClientCookie) super.clone();
michael@0: clone.attribs = new HashMap