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

RFC2965VersionAttributeHandler

public class RFC2965VersionAttributeHandler extends Object implements CookieAttributeHandler
"Version" cookie attribute handler for RFC 2965 cookie spec.

Fields Summary
Constructors Summary
public RFC2965VersionAttributeHandler()

        super();
    
Methods Summary
public booleanmatch(org.apache.http.cookie.Cookie cookie, org.apache.http.cookie.CookieOrigin origin)

        return true;
    
public voidparse(org.apache.http.cookie.SetCookie cookie, java.lang.String value)
Parse cookie version attribute.

        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 voidvalidate(org.apache.http.cookie.Cookie cookie, org.apache.http.cookie.CookieOrigin origin)
validate cookie version attribute. Version attribute is REQUIRED.

        if (cookie == null) {
            throw new IllegalArgumentException("Cookie may not be null");
        }
        if (cookie instanceof SetCookie2) {
            if (cookie instanceof ClientCookie 
                    && !((ClientCookie) cookie).containsAttribute(ClientCookie.VERSION_ATTR)) {
                throw new MalformedCookieException(
                        "Violates RFC 2965. Version attribute is required.");
            }
        }