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

BestMatchSpec

public class BestMatchSpec extends Object implements CookieSpec
'Meta' cookie specification that selects a cookie policy depending on the format of the cookie(s)
author
Oleg Kalnichevski
since
4.0

Fields Summary
private final String[]
datepatterns
private final boolean
oneHeader
private RFC2965Spec
strict
private BrowserCompatSpec
compat
private NetscapeDraftSpec
netscape
Constructors Summary
public BestMatchSpec(String[] datepatterns, boolean oneHeader)

        super();
        this.datepatterns = datepatterns;
        this.oneHeader = oneHeader;
    
public BestMatchSpec()

        this(null, false);
    
Methods Summary
public java.util.ListformatCookies(java.util.List cookies)

        if (cookies == null) {
            throw new IllegalArgumentException("List of cookie may not be null");
        }
        int version = Integer.MAX_VALUE;
        for (Cookie cookie: cookies) {
            if (cookie.getVersion() < version) {
                version = cookie.getVersion();
            }
        }
        if (version > 0) {
            return getStrict().formatCookies(cookies);
        } else {
            return getCompat().formatCookies(cookies);
        }
    
private org.apache.http.impl.cookie.BrowserCompatSpecgetCompat()

        if (this.compat == null) {
            this.compat = new BrowserCompatSpec(this.datepatterns);
        }
        return compat;
    
private org.apache.http.impl.cookie.NetscapeDraftSpecgetNetscape()

        if (this.netscape == null) {
            String[] patterns = this.datepatterns;
            if (patterns == null) {
                patterns = BrowserCompatSpec.DATE_PATTERNS;
            }
            this.netscape = new NetscapeDraftSpec(patterns);
        }
        return netscape;
    
private org.apache.http.impl.cookie.RFC2965SpecgetStrict()

        if (this.strict == null) {
             this.strict = new RFC2965Spec(this.datepatterns, this.oneHeader);
        }
        return strict;
    
public intgetVersion()

        return getStrict().getVersion();
    
public org.apache.http.HeadergetVersionHeader()

        return getStrict().getVersionHeader();
    
public booleanmatch(org.apache.http.cookie.Cookie cookie, org.apache.http.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");
        }
        if (cookie.getVersion() > 0) {
            return getStrict().match(cookie, origin);
        } else {
            return getCompat().match(cookie, origin);
        }
    
public java.util.Listparse(org.apache.http.Header header, org.apache.http.cookie.CookieOrigin origin)

        if (header == null) {
            throw new IllegalArgumentException("Header may not be null");
        }
        if (origin == null) {
           throw new IllegalArgumentException("Cookie origin may not be null");
        }
        HeaderElement[] helems = header.getElements();
        boolean versioned = false;
        boolean netscape = false;
        for (HeaderElement helem: helems) {
            if (helem.getParameterByName("version") != null) {
                versioned = true;
            }
            if (helem.getParameterByName("expires") != null) {
               netscape = true;
            }
        }
        if (netscape) {
            
        }
        // Do we have a cookie with a version attribute?
        if (versioned) {
            return getStrict().parse(helems, origin);
        } else if (netscape) {
            // Need to parse the header again,
            // because Netscape draft cannot handle
            // comma separators
            return getNetscape().parse(header, origin);
        } else {
            return getCompat().parse(helems, origin);
        }
    
public voidvalidate(org.apache.http.cookie.Cookie cookie, org.apache.http.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");
        }
        if (cookie.getVersion() > 0) {
            getStrict().validate(cookie, origin);
        } else {
            getCompat().validate(cookie, origin);
        }