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

CookieSpecBase

public abstract class CookieSpecBase extends AbstractCookieSpec
Cookie management functions shared by all specification.
author
Oleg Kalnichevski
since
4.0

(Omit source code)

Fields Summary
Constructors Summary
Methods Summary
protected static java.lang.StringgetDefaultDomain(org.apache.http.cookie.CookieOrigin origin)

        return origin.getHost();
    
protected static java.lang.StringgetDefaultPath(org.apache.http.cookie.CookieOrigin origin)

        String defaultPath = origin.getPath();    
        int lastSlashIndex = defaultPath.lastIndexOf('/");
        if (lastSlashIndex >= 0) {
            if (lastSlashIndex == 0) {
                //Do not remove the very first slash
                lastSlashIndex = 1;
            }
            defaultPath = defaultPath.substring(0, lastSlashIndex);
        }
        return defaultPath;
    
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");
        }
        for (CookieAttributeHandler handler: getAttribHandlers()) {
            if (!handler.match(cookie, origin)) {
                return false;
            }
        }
        return true;
    
protected java.util.Listparse(org.apache.http.HeaderElement[] elems, org.apache.http.cookie.CookieOrigin origin)

        List<Cookie> cookies = new ArrayList<Cookie>(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));

            // cycle through the parameters
            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 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");
        }
        for (CookieAttributeHandler handler: getAttribHandlers()) {
            handler.validate(cookie, origin);
        }