httpclient-4.1.1

16:36:33.642 INFO  jd.cli.Main - Decompiling httpclient-4.1.1.jar
package org.apache.http.impl.cookie;

import org.apache.http.annotation.Immutable;
import org.apache.http.cookie.MalformedCookieException;
import org.apache.http.cookie.SetCookie;

@Immutable
public class BasicExpiresHandler
  extends AbstractCookieAttributeHandler
{
  private final String[] datepatterns;
  
  public BasicExpiresHandler(String[] datepatterns)
  {
    if (datepatterns == null) {
      throw new IllegalArgumentException("Array of date patterns may not be null");
    }
    this.datepatterns = datepatterns;
  }
  
  public void parse(SetCookie cookie, String value)
    throws MalformedCookieException
  {
    if (cookie == null) {
      throw new IllegalArgumentException("Cookie may not be null");
    }
    if (value == null) {
      throw new MalformedCookieException("Missing value for expires attribute");
    }
    try
    {
      cookie.setExpiryDate(DateUtils.parseDate(value, datepatterns));
    }
    catch (DateParseException dpe)
    {
      throw new MalformedCookieException("Unable to parse expires attribute: " + value);
    }
  }
}

/* Location:
 * Qualified Name:     org.apache.http.impl.cookie.BasicExpiresHandler
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.http.impl.cookie;

import org.apache.http.annotation.Immutable;

@Immutable
public class DateParseException
  extends Exception
{
  private static final long serialVersionUID = 4417696455000643370L;
  
  public DateParseException() {}
  
  public DateParseException(String message)
  {
    super(message);
  }
}

/* Location:
 * Qualified Name:     org.apache.http.impl.cookie.DateParseException
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.http.impl.cookie;

import org.apache.http.annotation.Immutable;
import org.apache.http.cookie.CookieSpec;
import org.apache.http.cookie.CookieSpecFactory;
import org.apache.http.params.HttpParams;

@Immutable
public class IgnoreSpecFactory
  implements CookieSpecFactory
{
  public CookieSpec newInstance(HttpParams params)
  {
    return new IgnoreSpec();
  }
}

/* Location:
 * Qualified Name:     org.apache.http.impl.cookie.IgnoreSpecFactory
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.http.impl.cookie;

import java.util.Collection;
import org.apache.http.annotation.Immutable;
import org.apache.http.cookie.CookieSpec;
import org.apache.http.cookie.CookieSpecFactory;
import org.apache.http.params.HttpParams;

@Immutable
public class BestMatchSpecFactory
  implements CookieSpecFactory
{
  public CookieSpec newInstance(HttpParams params)
  {
    if (params != null)
    {
      String[] patterns = null;
      Collection<?> param = (Collection)params.getParameter("http.protocol.cookie-datepatterns");
      if (param != null)
      {
        patterns = new String[param.size()];
        patterns = (String[])param.toArray(patterns);
      }
      boolean singleHeader = params.getBooleanParameter("http.protocol.single-cookie-header", false);
      
      return new BestMatchSpec(patterns, singleHeader);
    }
    return new BestMatchSpec();
  }
}

/* Location:
 * Qualified Name:     org.apache.http.impl.cookie.BestMatchSpecFactory
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.http.impl.cookie;

import java.util.Collection;
import org.apache.http.annotation.Immutable;
import org.apache.http.cookie.CookieSpec;
import org.apache.http.cookie.CookieSpecFactory;
import org.apache.http.params.HttpParams;

@Immutable
public class NetscapeDraftSpecFactory
  implements CookieSpecFactory
{
  public CookieSpec newInstance(HttpParams params)
  {
    if (params != null)
    {
      String[] patterns = null;
      Collection<?> param = (Collection)params.getParameter("http.protocol.cookie-datepatterns");
      if (param != null)
      {
        patterns = new String[param.size()];
        patterns = (String[])param.toArray(patterns);
      }
      return new NetscapeDraftSpec(patterns);
    }
    return new NetscapeDraftSpec();
  }
}

/* Location:
 * Qualified Name:     org.apache.http.impl.cookie.NetscapeDraftSpecFactory
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.http.impl.cookie;

import org.apache.http.annotation.Immutable;
import org.apache.http.cookie.Cookie;
import org.apache.http.cookie.CookieAttributeHandler;
import org.apache.http.cookie.CookieOrigin;
import org.apache.http.cookie.MalformedCookieException;

@Immutable
public abstract class AbstractCookieAttributeHandler
  implements CookieAttributeHandler
{
  public void validate(Cookie cookie, CookieOrigin origin)
    throws MalformedCookieException
  {}
  
  public boolean match(Cookie cookie, CookieOrigin origin)
  {
    return true;
  }
}

/* Location:
 * Qualified Name:     org.apache.http.impl.cookie.AbstractCookieAttributeHandler
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.http.impl.cookie;

import org.apache.http.annotation.Immutable;
import org.apache.http.cookie.Cookie;
import org.apache.http.cookie.CookieAttributeHandler;
import org.apache.http.cookie.CookieOrigin;
import org.apache.http.cookie.MalformedCookieException;
import org.apache.http.cookie.SetCookie;
import org.apache.http.cookie.SetCookie2;

@Immutable
public class RFC2965DiscardAttributeHandler
  implements CookieAttributeHandler
{
  public void parse(SetCookie cookie, String commenturl)
    throws MalformedCookieException
  {
    if ((cookie instanceof SetCookie2))
    {
      SetCookie2 cookie2 = (SetCookie2)cookie;
      cookie2.setDiscard(true);
    }
  }
  
  public void validate(Cookie cookie, CookieOrigin origin)
    throws MalformedCookieException
  {}
  
  public boolean match(Cookie cookie, CookieOrigin origin)
  {
    return true;
  }
}

/* Location:
 * Qualified Name:     org.apache.http.impl.cookie.RFC2965DiscardAttributeHandler
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.http.impl.cookie;

import org.apache.http.annotation.Immutable;
import org.apache.http.cookie.ClientCookie;
import org.apache.http.cookie.Cookie;
import org.apache.http.cookie.CookieAttributeHandler;
import org.apache.http.cookie.CookieOrigin;
import org.apache.http.cookie.CookieRestrictionViolationException;
import org.apache.http.cookie.MalformedCookieException;
import org.apache.http.cookie.SetCookie;
import org.apache.http.cookie.SetCookie2;

@Immutable
public class RFC2965VersionAttributeHandler
  implements CookieAttributeHandler
{
  public void parse(SetCookie cookie, String value)
    throws MalformedCookieException
  {
    if (cookie == null) {
      throw new IllegalArgumentException("Cookie may not be null");
    }
    if (value == null) {
      throw new MalformedCookieException("Missing value for version attribute");
    }
    int version = -1;
    try
    {
      version = Integer.parseInt(value);
    }
    catch (NumberFormatException e)
    {
      version = -1;
    }
    if (version < 0) {
      throw new MalformedCookieException("Invalid cookie version.");
    }
    cookie.setVersion(version);
  }
  
  public void validate(Cookie cookie, CookieOrigin origin)
    throws MalformedCookieException
  {
    if (cookie == null) {
      throw new IllegalArgumentException("Cookie may not be null");
    }
    if (((cookie instanceof SetCookie2)) && 
      ((cookie instanceof ClientCookie)) && (!((ClientCookie)cookie).containsAttribute("version"))) {
      throw new CookieRestrictionViolationException("Violates RFC 2965. Version attribute is required.");
    }
  }
  
  public boolean match(Cookie cookie, CookieOrigin origin)
  {
    return true;
  }
}

/* Location:
 * Qualified Name:     org.apache.http.impl.cookie.RFC2965VersionAttributeHandler
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.http.impl.cookie;

import java.io.Serializable;
import java.util.Date;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
import org.apache.http.annotation.NotThreadSafe;
import org.apache.http.cookie.ClientCookie;
import org.apache.http.cookie.SetCookie;

@NotThreadSafe
public class BasicClientCookie
  implements SetCookie, ClientCookie, Cloneable, Serializable
{
  private static final long serialVersionUID = -3869795591041535538L;
  private final String name;
  private Map<String, String> attribs;
  private String value;
  private String cookieComment;
  private String cookieDomain;
  private Date cookieExpiryDate;
  private String cookiePath;
  private boolean isSecure;
  private int cookieVersion;
  
  public BasicClientCookie(String name, String value)
  {
    if (name == null) {
      throw new IllegalArgumentException("Name may not be null");
    }
    this.name = name;
    attribs = new HashMap();
    this.value = value;
  }
  
  public String getName()
  {
    return name;
  }
  
  public String getValue()
  {
    return value;
  }
  
  public void setValue(String value)
  {
    this.value = value;
  }
  
  public String getComment()
  {
    return cookieComment;
  }
  
  public void setComment(String comment)
  {
    cookieComment = comment;
  }
  
  public String getCommentURL()
  {
    return null;
  }
  
  public Date getExpiryDate()
  {
    return cookieExpiryDate;
  }
  
  public void setExpiryDate(Date expiryDate)
  {
    cookieExpiryDate = expiryDate;
  }
  
  public boolean isPersistent()
  {
    return null != cookieExpiryDate;
  }
  
  public String getDomain()
  {
    return cookieDomain;
  }
  
  public void setDomain(String domain)
  {
    if (domain != null) {
      cookieDomain = domain.toLowerCase(Locale.ENGLISH);
    } else {
      cookieDomain = null;
    }
  }
  
  public String getPath()
  {
    return cookiePath;
  }
  
  public void setPath(String path)
  {
    cookiePath = path;
  }
  
  public boolean isSecure()
  {
    return isSecure;
  }
  
  public void setSecure(boolean secure)
  {
    isSecure = secure;
  }
  
  public int[] getPorts()
  {
    return null;
  }
  
  public int getVersion()
  {
    return cookieVersion;
  }
  
  public void setVersion(int version)
  {
    cookieVersion = version;
  }
  
  public boolean isExpired(Date date)
  {
    if (date == null) {
      throw new IllegalArgumentException("Date may not be null");
    }
    return (cookieExpiryDate != null) && (cookieExpiryDate.getTime() <= date.getTime());
  }
  
  public void setAttribute(String name, String value)
  {
    attribs.put(name, value);
  }
  
  public String getAttribute(String name)
  {
    return (String)attribs.get(name);
  }
  
  public boolean containsAttribute(String name)
  {
    return attribs.get(name) != null;
  }
  
  public Object clone()
    throws CloneNotSupportedException
  {
    BasicClientCookie clone = (BasicClientCookie)super.clone();
    attribs = new HashMap(attribs);
    return clone;
  }
  
  public String toString()
  {
    StringBuilder buffer = new StringBuilder();
    buffer.append("[version: ");
    buffer.append(Integer.toString(cookieVersion));
    buffer.append("]");
    buffer.append("[name: ");
    buffer.append(name);
    buffer.append("]");
    buffer.append("[value: ");
    buffer.append(value);
    buffer.append("]");
    buffer.append("[domain: ");
    buffer.append(cookieDomain);
    buffer.append("]");
    buffer.append("[path: ");
    buffer.append(cookiePath);
    buffer.append("]");
    buffer.append("[expiry: ");
    buffer.append(cookieExpiryDate);
    buffer.append("]");
    return buffer.toString();
  }
}

/* Location:
 * Qualified Name:     org.apache.http.impl.cookie.BasicClientCookie
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.http.impl.cookie;

import org.apache.http.annotation.Immutable;
import org.apache.http.cookie.Cookie;
import org.apache.http.cookie.CookieAttributeHandler;
import org.apache.http.cookie.CookieOrigin;
import org.apache.http.cookie.CookieRestrictionViolationException;
import org.apache.http.cookie.MalformedCookieException;
import org.apache.http.cookie.SetCookie;

@Immutable
public class BasicPathHandler
  implements CookieAttributeHandler
{
  public void parse(SetCookie cookie, String value)
    throws MalformedCookieException
  {
    if (cookie == null) {
      throw new IllegalArgumentException("Cookie may not be null");
    }
    if ((value == null) || (value.trim().length() == 0)) {
      value = "/";
    }
    cookie.setPath(value);
  }
  
  public void validate(Cookie cookie, CookieOrigin origin)
    throws MalformedCookieException
  {
    if (!match(cookie, origin)) {
      throw new CookieRestrictionViolationException("Illegal path attribute \"" + cookie.getPath() + "\". Path of origin: \"" + origin.getPath() + "\"");
    }
  }
  
  public boolean match(Cookie cookie, CookieOrigin origin)
  {
    if (cookie == null) {
      throw new IllegalArgumentException("Cookie may not be null");
    }
    if (origin == null) {
      throw new IllegalArgumentException("Cookie origin may not be null");
    }
    String targetpath = origin.getPath();
    String topmostPath = cookie.getPath();
    if (topmostPath == null) {
      topmostPath = "/";
    }
    if ((topmostPath.length() > 1) && (topmostPath.endsWith("/"))) {
      topmostPath = topmostPath.substring(0, topmostPath.length() - 1);
    }
    boolean match = targetpath.startsWith(topmostPath);
    if ((match) && (targetpath.length() != topmostPath.length()) && 
      (!topmostPath.endsWith("/"))) {
      match = targetpath.charAt(topmostPath.length()) == '/';
    }
    return match;
  }
}

/* Location:
 * Qualified Name:     org.apache.http.impl.cookie.BasicPathHandler
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.http.impl.cookie;

import java.util.ArrayList;
import java.util.List;
import org.apache.http.FormattedHeader;
import org.apache.http.Header;
import org.apache.http.HeaderElement;
import org.apache.http.annotation.NotThreadSafe;
import org.apache.http.cookie.Cookie;
import org.apache.http.cookie.CookieOrigin;
import org.apache.http.cookie.MalformedCookieException;
import org.apache.http.message.BufferedHeader;
import org.apache.http.message.ParserCursor;
import org.apache.http.util.CharArrayBuffer;

@NotThreadSafe
public class NetscapeDraftSpec
  extends CookieSpecBase
{
  protected static final String EXPIRES_PATTERN = "EEE, dd-MMM-yy HH:mm:ss z";
  private final String[] datepatterns;
  
  public NetscapeDraftSpec(String[] datepatterns)
  {
    if (datepatterns != null) {
      this.datepatterns = ((String[])datepatterns.clone());
    } else {
      this.datepatterns = new String[] { "EEE, dd-MMM-yy HH:mm:ss z" };
    }
    registerAttribHandler("path", new BasicPathHandler());
    registerAttribHandler("domain", new NetscapeDomainHandler());
    registerAttribHandler("max-age", new BasicMaxAgeHandler());
    registerAttribHandler("secure", new BasicSecureHandler());
    registerAttribHandler("comment", new BasicCommentHandler());
    registerAttribHandler("expires", new BasicExpiresHandler(this.datepatterns));
  }
  
  public NetscapeDraftSpec()
  {
    this(null);
  }
  
  public List<Cookie> parse(Header header, CookieOrigin origin)
    throws MalformedCookieException
  {
    if (header == null) {
      throw new IllegalArgumentException("Header may not be null");
    }
    if (origin == null) {
      throw new IllegalArgumentException("Cookie origin may not be null");
    }
    if (!header.getName().equalsIgnoreCase("Set-Cookie")) {
      throw new MalformedCookieException("Unrecognized cookie header '" + header.toString() + "'");
    }
    NetscapeDraftHeaderParser parser = NetscapeDraftHeaderParser.DEFAULT;
    ParserCursor cursor;
    CharArrayBuffer buffer;
    ParserCursor cursor;
    if ((header instanceof FormattedHeader))
    {
      CharArrayBuffer buffer = ((FormattedHeader)header).getBuffer();
      cursor = new ParserCursor(((FormattedHeader)header).getValuePos(), buffer.length());
    }
    else
    {
      String s = header.getValue();
      if (s == null) {
        throw new MalformedCookieException("Header value is null");
      }
      buffer = new CharArrayBuffer(s.length());
      buffer.append(s);
      cursor = new ParserCursor(0, buffer.length());
    }
    return parse(new HeaderElement[] { parser.parseHeader(buffer, cursor) }, origin);
  }
  
  public List<Header> formatCookies(List<Cookie> cookies)
  {
    if (cookies == null) {
      throw new IllegalArgumentException("List of cookies may not be null");
    }
    if (cookies.isEmpty()) {
      throw new IllegalArgumentException("List of cookies may not be empty");
    }
    CharArrayBuffer buffer = new CharArrayBuffer(20 * cookies.size());
    buffer.append("Cookie");
    buffer.append(": ");
    for (int i = 0; i < cookies.size(); i++)
    {
      Cookie cookie = (Cookie)cookies.get(i);
      if (i > 0) {
        buffer.append("; ");
      }
      buffer.append(cookie.getName());
      String s = cookie.getValue();
      if (s != null)
      {
        buffer.append("=");
        buffer.append(s);
      }
    }
    List<Header> headers = new ArrayList(1);
    headers.add(new BufferedHeader(buffer));
    return headers;
  }
  
  public int getVersion()
  {
    return 0;
  }
  
  public Header getVersionHeader()
  {
    return null;
  }
  
  public String toString()
  {
    return "netscape";
  }
}

/* Location:
 * Qualified Name:     org.apache.http.impl.cookie.NetscapeDraftSpec
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.http.impl.cookie;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Map.Entry;
import org.apache.http.Header;
import org.apache.http.HeaderElement;
import org.apache.http.NameValuePair;
import org.apache.http.annotation.NotThreadSafe;
import org.apache.http.cookie.ClientCookie;
import org.apache.http.cookie.Cookie;
import org.apache.http.cookie.CookieAttributeHandler;
import org.apache.http.cookie.CookieOrigin;
import org.apache.http.cookie.MalformedCookieException;
import org.apache.http.message.BufferedHeader;
import org.apache.http.util.CharArrayBuffer;

@NotThreadSafe
public class RFC2965Spec
  extends RFC2109Spec
{
  public RFC2965Spec()
  {
    this(null, false);
  }
  
  public RFC2965Spec(String[] datepatterns, boolean oneHeader)
  {
    super(datepatterns, oneHeader);
    registerAttribHandler("domain", new RFC2965DomainAttributeHandler());
    registerAttribHandler("port", new RFC2965PortAttributeHandler());
    registerAttribHandler("commenturl", new RFC2965CommentUrlAttributeHandler());
    registerAttribHandler("discard", new RFC2965DiscardAttributeHandler());
    registerAttribHandler("version", new RFC2965VersionAttributeHandler());
  }
  
  public List<Cookie> parse(Header header, CookieOrigin origin)
    throws MalformedCookieException
  {
    if (header == null) {
      throw new IllegalArgumentException("Header may not be null");
    }
    if (origin == null) {
      throw new IllegalArgumentException("Cookie origin may not be null");
    }
    if (!header.getName().equalsIgnoreCase("Set-Cookie2")) {
      throw new MalformedCookieException("Unrecognized cookie header '" + header.toString() + "'");
    }
    origin = adjustEffectiveHost(origin);
    HeaderElement[] elems = header.getElements();
    return createCookies(elems, origin);
  }
  
  protected List<Cookie> parse(HeaderElement[] elems, CookieOrigin origin)
    throws MalformedCookieException
  {
    origin = adjustEffectiveHost(origin);
    return createCookies(elems, origin);
  }
  
  private List<Cookie> createCookies(HeaderElement[] elems, CookieOrigin origin)
    throws MalformedCookieException
  {
    List<Cookie> cookies = new ArrayList(elems.length);
    for (HeaderElement headerelement : elems)
    {
      String name = headerelement.getName();
      String value = headerelement.getValue();
      if ((name == null) || (name.length() == 0)) {
        throw new MalformedCookieException("Cookie name may not be empty");
      }
      BasicClientCookie2 cookie = new BasicClientCookie2(name, value);
      cookie.setPath(getDefaultPath(origin));
      cookie.setDomain(getDefaultDomain(origin));
      cookie.setPorts(new int[] { origin.getPort() });
      
      NameValuePair[] attribs = headerelement.getParameters();
      
      Map<String, NameValuePair> attribmap = new HashMap(attribs.length);
      for (int j = attribs.length - 1; j >= 0; j--)
      {
        NameValuePair param = attribs[j];
        attribmap.put(param.getName().toLowerCase(Locale.ENGLISH), param);
      }
      for (Map.Entry<String, NameValuePair> entry : attribmap.entrySet())
      {
        NameValuePair attrib = (NameValuePair)entry.getValue();
        String s = attrib.getName().toLowerCase(Locale.ENGLISH);
        
        cookie.setAttribute(s, attrib.getValue());
        
        CookieAttributeHandler handler = findAttribHandler(s);
        if (handler != null) {
          handler.parse(cookie, attrib.getValue());
        }
      }
      cookies.add(cookie);
    }
    return cookies;
  }
  
  public void validate(Cookie cookie, CookieOrigin origin)
    throws MalformedCookieException
  {
    if (cookie == null) {
      throw new IllegalArgumentException("Cookie may not be null");
    }
    if (origin == null) {
      throw new IllegalArgumentException("Cookie origin may not be null");
    }
    origin = adjustEffectiveHost(origin);
    super.validate(cookie, origin);
  }
  
  public boolean match(Cookie cookie, CookieOrigin origin)
  {
    if (cookie == null) {
      throw new IllegalArgumentException("Cookie may not be null");
    }
    if (origin == null) {
      throw new IllegalArgumentException("Cookie origin may not be null");
    }
    origin = adjustEffectiveHost(origin);
    return super.match(cookie, origin);
  }
  
  protected void formatCookieAsVer(CharArrayBuffer buffer, Cookie cookie, int version)
  {
    super.formatCookieAsVer(buffer, cookie, version);
    if ((cookie instanceof ClientCookie))
    {
      String s = ((ClientCookie)cookie).getAttribute("port");
      if (s != null)
      {
        buffer.append("; $Port");
        buffer.append("=\"");
        if (s.trim().length() > 0)
        {
          int[] ports = cookie.getPorts();
          if (ports != null)
          {
            int i = 0;
            for (int len = ports.length; i < len; i++)
            {
              if (i > 0) {
                buffer.append(",");
              }
              buffer.append(Integer.toString(ports[i]));
            }
          }
        }
        buffer.append("\"");
      }
    }
  }
  
  private static CookieOrigin adjustEffectiveHost(CookieOrigin origin)
  {
    String host = origin.getHost();
    
    boolean isLocalHost = true;
    for (int i = 0; i < host.length(); i++)
    {
      char ch = host.charAt(i);
      if ((ch == '.') || (ch == ':'))
      {
        isLocalHost = false;
        break;
      }
    }
    if (isLocalHost)
    {
      host = host + ".local";
      return new CookieOrigin(host, origin.getPort(), origin.getPath(), origin.isSecure());
    }
    return origin;
  }
  
  public int getVersion()
  {
    return 1;
  }
  
  public Header getVersionHeader()
  {
    CharArrayBuffer buffer = new CharArrayBuffer(40);
    buffer.append("Cookie2");
    buffer.append(": ");
    buffer.append("$Version=");
    buffer.append(Integer.toString(getVersion()));
    return new BufferedHeader(buffer);
  }
  
  public String toString()
  {
    return "rfc2965";
  }
}

/* Location:
 * Qualified Name:     org.apache.http.impl.cookie.RFC2965Spec
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.http.impl.cookie;

import org.apache.http.annotation.Immutable;
import org.apache.http.cookie.Cookie;
import org.apache.http.cookie.CookieAttributeHandler;
import org.apache.http.cookie.CookieOrigin;
import org.apache.http.cookie.CookieRestrictionViolationException;
import org.apache.http.cookie.MalformedCookieException;
import org.apache.http.cookie.SetCookie;

@Immutable
public class BasicDomainHandler
  implements CookieAttributeHandler
{
  public void parse(SetCookie cookie, String value)
    throws MalformedCookieException
  {
    if (cookie == null) {
      throw new IllegalArgumentException("Cookie may not be null");
    }
    if (value == null) {
      throw new MalformedCookieException("Missing value for domain attribute");
    }
    if (value.trim().length() == 0) {
      throw new MalformedCookieException("Blank value for domain attribute");
    }
    cookie.setDomain(value);
  }
  
  public void validate(Cookie cookie, CookieOrigin origin)
    throws MalformedCookieException
  {
    if (cookie == null) {
      throw new IllegalArgumentException("Cookie may not be null");
    }
    if (origin == null) {
      throw new IllegalArgumentException("Cookie origin may not be null");
    }
    String host = origin.getHost();
    String domain = cookie.getDomain();
    if (domain == null) {
      throw new CookieRestrictionViolationException("Cookie domain may not be null");
    }
    if (host.contains("."))
    {
      if (!host.endsWith(domain))
      {
        if (domain.startsWith(".")) {
          domain = domain.substring(1, domain.length());
        }
        if (!host.equals(domain)) {
          throw new CookieRestrictionViolationException("Illegal domain attribute \"" + domain + "\". Domain of origin: \"" + host + "\"");
        }
      }
    }
    else if (!host.equals(domain)) {
      throw new CookieRestrictionViolationException("Illegal domain attribute \"" + domain + "\". Domain of origin: \"" + host + "\"");
    }
  }
  
  public boolean match(Cookie cookie, CookieOrigin origin)
  {
    if (cookie == null) {
      throw new IllegalArgumentException("Cookie may not be null");
    }
    if (origin == null) {
      throw new IllegalArgumentException("Cookie origin may not be null");
    }
    String host = origin.getHost();
    String domain = cookie.getDomain();
    if (domain == null) {
      return false;
    }
    if (host.equals(domain)) {
      return true;
    }
    if (!domain.startsWith(".")) {
      domain = '.' + domain;
    }
    return (host.endsWith(domain)) || (host.equals(domain.substring(1)));
  }
}

/* Location:
 * Qualified Name:     org.apache.http.impl.cookie.BasicDomainHandler
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.http.impl.cookie;

import java.util.Collection;
import org.apache.http.annotation.Immutable;
import org.apache.http.cookie.CookieSpec;
import org.apache.http.cookie.CookieSpecFactory;
import org.apache.http.params.HttpParams;

@Immutable
public class RFC2109SpecFactory
  implements CookieSpecFactory
{
  public CookieSpec newInstance(HttpParams params)
  {
    if (params != null)
    {
      String[] patterns = null;
      Collection<?> param = (Collection)params.getParameter("http.protocol.cookie-datepatterns");
      if (param != null)
      {
        patterns = new String[param.size()];
        patterns = (String[])param.toArray(patterns);
      }
      boolean singleHeader = params.getBooleanParameter("http.protocol.single-cookie-header", false);
      
      return new RFC2109Spec(patterns, singleHeader);
    }
    return new RFC2109Spec();
  }
}

/* Location:
 * Qualified Name:     org.apache.http.impl.cookie.RFC2109SpecFactory
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.http.impl.cookie;

import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import org.apache.http.HeaderElement;
import org.apache.http.NameValuePair;
import org.apache.http.annotation.NotThreadSafe;
import org.apache.http.cookie.Cookie;
import org.apache.http.cookie.CookieAttributeHandler;
import org.apache.http.cookie.CookieOrigin;
import org.apache.http.cookie.MalformedCookieException;

@NotThreadSafe
public abstract class CookieSpecBase
  extends AbstractCookieSpec
{
  protected static String getDefaultPath(CookieOrigin origin)
  {
    String defaultPath = origin.getPath();
    int lastSlashIndex = defaultPath.lastIndexOf('/');
    if (lastSlashIndex >= 0)
    {
      if (lastSlashIndex == 0) {
        lastSlashIndex = 1;
      }
      defaultPath = defaultPath.substring(0, lastSlashIndex);
    }
    return defaultPath;
  }
  
  protected static String getDefaultDomain(CookieOrigin origin)
  {
    return origin.getHost();
  }
  
  protected List<Cookie> parse(HeaderElement[] elems, CookieOrigin origin)
    throws MalformedCookieException
  {
    List<Cookie> cookies = new ArrayList(elems.length);
    for (HeaderElement headerelement : elems)
    {
      String name = headerelement.getName();
      String value = headerelement.getValue();
      if ((name == null) || (name.length() == 0)) {
        throw new MalformedCookieException("Cookie name may not be empty");
      }
      BasicClientCookie cookie = new BasicClientCookie(name, value);
      cookie.setPath(getDefaultPath(origin));
      cookie.setDomain(getDefaultDomain(origin));
      
      NameValuePair[] attribs = headerelement.getParameters();
      for (int j = attribs.length - 1; j >= 0; j--)
      {
        NameValuePair attrib = attribs[j];
        String s = attrib.getName().toLowerCase(Locale.ENGLISH);
        
        cookie.setAttribute(s, attrib.getValue());
        
        CookieAttributeHandler handler = findAttribHandler(s);
        if (handler != null) {
          handler.parse(cookie, attrib.getValue());
        }
      }
      cookies.add(cookie);
    }
    return cookies;
  }
  
  public void validate(Cookie cookie, CookieOrigin origin)
    throws MalformedCookieException
  {
    if (cookie == null) {
      throw new IllegalArgumentException("Cookie may not be null");
    }
    if (origin == null) {
      throw new IllegalArgumentException("Cookie origin may not be null");
    }
    for (CookieAttributeHandler handler : getAttribHandlers()) {
      handler.validate(cookie, origin);
    }
  }
  
  public boolean match(Cookie cookie, CookieOrigin origin)
  {
    if (cookie == null) {
      throw new IllegalArgumentException("Cookie may not be null");
    }
    if (origin == null) {
      throw new IllegalArgumentException("Cookie origin may not be null");
    }
    for (CookieAttributeHandler handler : getAttribHandlers()) {
      if (!handler.match(cookie, origin)) {
        return false;
      }
    }
    return true;
  }
}

/* Location:
 * Qualified Name:     org.apache.http.impl.cookie.CookieSpecBase
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.http.impl.cookie;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import org.apache.http.Header;
import org.apache.http.HeaderElement;
import org.apache.http.annotation.NotThreadSafe;
import org.apache.http.cookie.ClientCookie;
import org.apache.http.cookie.Cookie;
import org.apache.http.cookie.CookieOrigin;
import org.apache.http.cookie.CookiePathComparator;
import org.apache.http.cookie.CookieRestrictionViolationException;
import org.apache.http.cookie.MalformedCookieException;
import org.apache.http.message.BufferedHeader;
import org.apache.http.util.CharArrayBuffer;

@NotThreadSafe
public class RFC2109Spec
  extends CookieSpecBase
{
  private static final CookiePathComparator PATH_COMPARATOR = new CookiePathComparator();
  private static final String[] DATE_PATTERNS = { "EEE, dd MMM yyyy HH:mm:ss zzz", "EEEE, dd-MMM-yy HH:mm:ss zzz", "EEE MMM d HH:mm:ss yyyy" };
  private final String[] datepatterns;
  private final boolean oneHeader;
  
  public RFC2109Spec(String[] datepatterns, boolean oneHeader)
  {
    if (datepatterns != null) {
      this.datepatterns = ((String[])datepatterns.clone());
    } else {
      this.datepatterns = DATE_PATTERNS;
    }
    this.oneHeader = oneHeader;
    registerAttribHandler("version", new RFC2109VersionHandler());
    registerAttribHandler("path", new BasicPathHandler());
    registerAttribHandler("domain", new RFC2109DomainHandler());
    registerAttribHandler("max-age", new BasicMaxAgeHandler());
    registerAttribHandler("secure", new BasicSecureHandler());
    registerAttribHandler("comment", new BasicCommentHandler());
    registerAttribHandler("expires", new BasicExpiresHandler(this.datepatterns));
  }
  
  public RFC2109Spec()
  {
    this(null, false);
  }
  
  public List<Cookie> parse(Header header, CookieOrigin origin)
    throws MalformedCookieException
  {
    if (header == null) {
      throw new IllegalArgumentException("Header may not be null");
    }
    if (origin == null) {
      throw new IllegalArgumentException("Cookie origin may not be null");
    }
    if (!header.getName().equalsIgnoreCase("Set-Cookie")) {
      throw new MalformedCookieException("Unrecognized cookie header '" + header.toString() + "'");
    }
    HeaderElement[] elems = header.getElements();
    return parse(elems, origin);
  }
  
  public void validate(Cookie cookie, CookieOrigin origin)
    throws MalformedCookieException
  {
    if (cookie == null) {
      throw new IllegalArgumentException("Cookie may not be null");
    }
    String name = cookie.getName();
    if (name.indexOf(' ') != -1) {
      throw new CookieRestrictionViolationException("Cookie name may not contain blanks");
    }
    if (name.startsWith("$")) {
      throw new CookieRestrictionViolationException("Cookie name may not start with $");
    }
    super.validate(cookie, origin);
  }
  
  public List<Header> formatCookies(List<Cookie> cookies)
  {
    if (cookies == null) {
      throw new IllegalArgumentException("List of cookies may not be null");
    }
    if (cookies.isEmpty()) {
      throw new IllegalArgumentException("List of cookies may not be empty");
    }
    if (cookies.size() > 1)
    {
      cookies = new ArrayList(cookies);
      Collections.sort(cookies, PATH_COMPARATOR);
    }
    if (oneHeader) {
      return doFormatOneHeader(cookies);
    }
    return doFormatManyHeaders(cookies);
  }
  
  private List<Header> doFormatOneHeader(List<Cookie> cookies)
  {
    int version = Integer.MAX_VALUE;
    for (Cookie cookie : cookies) {
      if (cookie.getVersion() < version) {
        version = cookie.getVersion();
      }
    }
    CharArrayBuffer buffer = new CharArrayBuffer(40 * cookies.size());
    buffer.append("Cookie");
    buffer.append(": ");
    buffer.append("$Version=");
    buffer.append(Integer.toString(version));
    for (Cookie cooky : cookies)
    {
      buffer.append("; ");
      Cookie cookie = cooky;
      formatCookieAsVer(buffer, cookie, version);
    }
    List<Header> headers = new ArrayList(1);
    headers.add(new BufferedHeader(buffer));
    return headers;
  }
  
  private List<Header> doFormatManyHeaders(List<Cookie> cookies)
  {
    List<Header> headers = new ArrayList(cookies.size());
    for (Cookie cookie : cookies)
    {
      int version = cookie.getVersion();
      CharArrayBuffer buffer = new CharArrayBuffer(40);
      buffer.append("Cookie: ");
      buffer.append("$Version=");
      buffer.append(Integer.toString(version));
      buffer.append("; ");
      formatCookieAsVer(buffer, cookie, version);
      headers.add(new BufferedHeader(buffer));
    }
    return headers;
  }
  
  protected void formatParamAsVer(CharArrayBuffer buffer, String name, String value, int version)
  {
    buffer.append(name);
    buffer.append("=");
    if (value != null) {
      if (version > 0)
      {
        buffer.append('"');
        buffer.append(value);
        buffer.append('"');
      }
      else
      {
        buffer.append(value);
      }
    }
  }
  
  protected void formatCookieAsVer(CharArrayBuffer buffer, Cookie cookie, int version)
  {
    formatParamAsVer(buffer, cookie.getName(), cookie.getValue(), version);
    if ((cookie.getPath() != null) && 
      ((cookie instanceof ClientCookie)) && (((ClientCookie)cookie).containsAttribute("path")))
    {
      buffer.append("; ");
      formatParamAsVer(buffer, "$Path", cookie.getPath(), version);
    }
    if ((cookie.getDomain() != null) && 
      ((cookie instanceof ClientCookie)) && (((ClientCookie)cookie).containsAttribute("domain")))
    {
      buffer.append("; ");
      formatParamAsVer(buffer, "$Domain", cookie.getDomain(), version);
    }
  }
  
  public int getVersion()
  {
    return 1;
  }
  
  public Header getVersionHeader()
  {
    return null;
  }
  
  public String toString()
  {
    return "rfc2109";
  }
}

/* Location:
 * Qualified Name:     org.apache.http.impl.cookie.RFC2109Spec
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.http.impl.cookie;

import java.lang.ref.SoftReference;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
import java.util.TimeZone;
import org.apache.http.annotation.Immutable;

@Immutable
public final class DateUtils
{
  public static final String PATTERN_RFC1123 = "EEE, dd MMM yyyy HH:mm:ss zzz";
  public static final String PATTERN_RFC1036 = "EEEE, dd-MMM-yy HH:mm:ss zzz";
  public static final String PATTERN_ASCTIME = "EEE MMM d HH:mm:ss yyyy";
  private static final String[] DEFAULT_PATTERNS = { "EEEE, dd-MMM-yy HH:mm:ss zzz", "EEE, dd MMM yyyy HH:mm:ss zzz", "EEE MMM d HH:mm:ss yyyy" };
  private static final Date DEFAULT_TWO_DIGIT_YEAR_START;
  public static final TimeZone GMT = TimeZone.getTimeZone("GMT");
  
  static
  {
    Calendar calendar = Calendar.getInstance();
    calendar.setTimeZone(GMT);
    calendar.set(2000, 0, 1, 0, 0, 0);
    calendar.set(14, 0);
    DEFAULT_TWO_DIGIT_YEAR_START = calendar.getTime();
  }
  
  public static Date parseDate(String dateValue)
    throws DateParseException
  {
    return parseDate(dateValue, null, null);
  }
  
  public static Date parseDate(String dateValue, String[] dateFormats)
    throws DateParseException
  {
    return parseDate(dateValue, dateFormats, null);
  }
  
  public static Date parseDate(String dateValue, String[] dateFormats, Date startDate)
    throws DateParseException
  {
    if (dateValue == null) {
      throw new IllegalArgumentException("dateValue is null");
    }
    if (dateFormats == null) {
      dateFormats = DEFAULT_PATTERNS;
    }
    if (startDate == null) {
      startDate = DEFAULT_TWO_DIGIT_YEAR_START;
    }
    if ((dateValue.length() > 1) && (dateValue.startsWith("'")) && (dateValue.endsWith("'"))) {
      dateValue = dateValue.substring(1, dateValue.length() - 1);
    }
    for (String dateFormat : dateFormats)
    {
      SimpleDateFormat dateParser = DateFormatHolder.formatFor(dateFormat);
      dateParser.set2DigitYearStart(startDate);
      try
      {
        return dateParser.parse(dateValue);
      }
      catch (ParseException pe) {}
    }
    throw new DateParseException("Unable to parse the date " + dateValue);
  }
  
  public static String formatDate(Date date)
  {
    return formatDate(date, "EEE, dd MMM yyyy HH:mm:ss zzz");
  }
  
  public static String formatDate(Date date, String pattern)
  {
    if (date == null) {
      throw new IllegalArgumentException("date is null");
    }
    if (pattern == null) {
      throw new IllegalArgumentException("pattern is null");
    }
    SimpleDateFormat formatter = DateFormatHolder.formatFor(pattern);
    return formatter.format(date);
  }
  
  static final class DateFormatHolder
  {
    private static final ThreadLocal<SoftReference<Map<String, SimpleDateFormat>>> THREADLOCAL_FORMATS = new ThreadLocal()
    {
      protected SoftReference<Map<String, SimpleDateFormat>> initialValue()
      {
        return new SoftReference(new HashMap());
      }
    };
    
    public static SimpleDateFormat formatFor(String pattern)
    {
      SoftReference<Map<String, SimpleDateFormat>> ref = (SoftReference)THREA
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15

Further reading...

For more information on Java 1.5 Tiger, you may find Java 1.5 Tiger, A developer's Notebook by D. Flanagan and B. McLaughlin from O'Reilly of interest.

New!JAR listings


Copyright 2006-2017. Infinite Loop Ltd