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

NetscapeDomainHandler

public class NetscapeDomainHandler extends BasicDomainHandler

Fields Summary
Constructors Summary
public NetscapeDomainHandler()

        super();
    
Methods Summary
private static booleanisSpecialDomain(java.lang.String domain)
Checks if the given domain is in one of the seven special top level domains defined by the Netscape cookie specification.

param
domain The domain.
return
True if the specified domain is "special"

       final String ucDomain = domain.toUpperCase(Locale.ENGLISH);
       return ucDomain.endsWith(".COM")
               || ucDomain.endsWith(".EDU")
               || ucDomain.endsWith(".NET")
               || ucDomain.endsWith(".GOV")
               || ucDomain.endsWith(".MIL")
               || ucDomain.endsWith(".ORG")
               || ucDomain.endsWith(".INT");
   
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");
       }
       String host = origin.getHost();
       String domain = cookie.getDomain();
       if (domain == null) {
           return false;
       }
       return host.endsWith(domain);
   
public voidvalidate(org.apache.http.cookie.Cookie cookie, org.apache.http.cookie.CookieOrigin origin)

        super.validate(cookie, origin);
        // Perform Netscape Cookie draft specific validation
        String host = origin.getHost();
        String domain = cookie.getDomain();
        if (host.contains(".")) {
            int domainParts = new StringTokenizer(domain, ".").countTokens();

            if (isSpecialDomain(domain)) {
                if (domainParts < 2) {
                    throw new MalformedCookieException("Domain attribute \""
                        + domain 
                        + "\" violates the Netscape cookie specification for "
                        + "special domains");
                }
            } else {
                if (domainParts < 3) {
                    throw new MalformedCookieException("Domain attribute \""
                        + domain 
                        + "\" violates the Netscape cookie specification");
                }            
            }
        }