hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r418097 - in /jakarta/httpcomponents/httpclient/trunk/src: java/org/apache/http/cookie/ java/org/apache/http/cookie/impl/ java/org/apache/http/cookie/params/ test/org/apache/http/cookie/
Date Thu, 29 Jun 2006 17:48:46 GMT
Author: olegk
Date: Thu Jun 29 10:48:45 2006
New Revision: 418097

URL: http://svn.apache.org/viewvc?rev=418097&view=rev
Log:
Refactoring of the CookiePolicy class

Added:
    jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/cookie/CookiePolicy.java
      - copied, changed from r417830, jakarta/commons/proper/httpclient/trunk/src/java/org/apache/commons/httpclient/cookie/CookiePolicy.java
    jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/cookie/CookieSpecFactory.java
  (with props)
    jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/cookie/impl/BrowserCompatSpecFactory.java
  (with props)
    jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/cookie/impl/NetscapeDraftSpecFactory.java
  (with props)
    jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/cookie/impl/RFC2109SpecFactory.java
  (with props)
    jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/cookie/params/
    jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/cookie/params/CookieSpecParams.java
  (with props)
    jakarta/httpcomponents/httpclient/trunk/src/test/org/apache/http/cookie/TestCookiePolicy.java
  (with props)
Modified:
    jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/cookie/Cookie.java
    jakarta/httpcomponents/httpclient/trunk/src/test/org/apache/http/cookie/TestAllCookie.java

Modified: jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/cookie/Cookie.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/cookie/Cookie.java?rev=418097&r1=418096&r2=418097&view=diff
==============================================================================
--- jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/cookie/Cookie.java (original)
+++ jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/cookie/Cookie.java Thu
Jun 29 10:48:45 2006
@@ -49,10 +49,10 @@
  * @author Sean C. Sullivan
  * @author <a href="mailto:JEvans@Cyveillance.com">John Evans</a>
  * @author Marc A. Saegesser
- * @author <a href="mailto:oleg@ural.ru">Oleg Kalnichevski</a>
+ * @author <a href="mailto:oleg at ural.ru">Oleg Kalnichevski</a>
  * @author <a href="mailto:mbowler@GargoyleSoftware.com">Mike Bowler</a>
  * 
- * @version $Revision$ $Date$
+ * @version $Revision$
  */
 public class Cookie extends NameValuePair {
 

Copied: jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/cookie/CookiePolicy.java
(from r417830, jakarta/commons/proper/httpclient/trunk/src/java/org/apache/commons/httpclient/cookie/CookiePolicy.java)
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/cookie/CookiePolicy.java?p2=jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/cookie/CookiePolicy.java&p1=jakarta/commons/proper/httpclient/trunk/src/java/org/apache/commons/httpclient/cookie/CookiePolicy.java&r1=417830&r2=418097&rev=418097&view=diff
==============================================================================
--- jakarta/commons/proper/httpclient/trunk/src/java/org/apache/commons/httpclient/cookie/CookiePolicy.java
(original)
+++ jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/cookie/CookiePolicy.java
Thu Jun 29 10:48:45 2006
@@ -1,11 +1,11 @@
 /*
- * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//httpclient/src/java/org/apache/commons/httpclient/cookie/CookiePolicy.java,v
1.15 2004/09/14 20:11:31 olegk Exp $
+ * $HeadURL$
  * $Revision$
  * $Date$
  *
  * ====================================================================
  *
- *  Copyright 2002-2004 The Apache Software Foundation
+ *  Copyright 2002-2006 The Apache Software Foundation
  *
  *  Licensed under the Apache License, Version 2.0 (the "License");
  *  you may not use this file except in compliance with the License.
@@ -27,160 +27,62 @@
  *
  */
 
-package org.apache.commons.httpclient.cookie;
+package org.apache.http.cookie;
 
 import java.util.Collections;
 import java.util.HashMap;
 import java.util.Map;
 
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
+import org.apache.http.cookie.params.CookieSpecParams;
+import org.apache.http.params.HttpParams;
 
 /**
  * Cookie management policy class. The cookie policy provides corresponding
  * cookie management interfrace for a given type or version of cookie. 
- * <p>RFC 2109 specification is used per default. Other supported specification
- * can be  chosen when appropriate or set default when desired
- * <p>The following specifications are provided:
- *  <ul>
- *   <li><tt>BROWSER_COMPATIBILITY</tt>: compatible with the common cookie

- *   management practices (even if they are not 100% standards compliant)
- *   <li><tt>NETSCAPE</tt>: Netscape cookie draft compliant
- *   <li><tt>RFC_2109</tt>: RFC2109 compliant (default)
- *   <li><tt>IGNORE_COOKIES</tt>: do not automcatically process cookies
- *  </ul>
  * 
- * @author <a href="mailto:oleg@ural.ru">Oleg Kalnichevski</a>
+ * @author <a href="mailto:oleg at ural.ru">Oleg Kalnichevski</a>
  * @author <a href="mailto:mbowler@GargoyleSoftware.com">Mike Bowler</a>
  *
  * @since 2.0
  */
-public abstract class CookiePolicy {
+public class CookiePolicy {
 
     private static Map SPECS = Collections.synchronizedMap(new HashMap());
     
-    /**
-     * The policy that provides high degree of compatibilty 
-     * with common cookie management of popular HTTP agents.
-     * 
-     * @since 3.0
-     */
-    public static final String BROWSER_COMPATIBILITY = "compatibility";
-    
-    /** 
-     * The Netscape cookie draft compliant policy. 
-     * 
-     * @since 3.0
-     */
-    public static final String NETSCAPE = "netscape";
-
-    /** 
-     * The RFC 2109 compliant policy. 
-     * 
-     * @since 3.0
-     */
-    public static final String RFC_2109 = "rfc2109";
-
-    /**
-     * The RFC 2965 compliant policy.
-     *
-     * @since 3.0
-     */
-    public static final String RFC_2965 = "rfc2965";
-
-    /**
-     * The policy that ignores cookies. 
-     * 
-     * @since 3.0
-     */
-    public static final String IGNORE_COOKIES = "ignoreCookies";
-    
-    /** 
-     * The default cookie policy. 
-     * 
-     * @since 3.0
-     */
-    public static final String DEFAULT = "default";
-    
-    static {
-        CookiePolicy.registerCookieSpec(DEFAULT, RFC2109Spec.class);
-        CookiePolicy.registerCookieSpec(RFC_2109, RFC2109Spec.class);
-        CookiePolicy.registerCookieSpec(RFC_2965, RFC2965Spec.class);
-        CookiePolicy.registerCookieSpec(BROWSER_COMPATIBILITY, CookieSpecBase.class);
-        CookiePolicy.registerCookieSpec(NETSCAPE, NetscapeDraftSpec.class);
-        CookiePolicy.registerCookieSpec(IGNORE_COOKIES, IgnoreCookiesSpec.class);
+    private CookiePolicy() {
     }
     
     /**
-     * The <tt>COMPATIBILITY</tt> policy provides high compatibilty 
-     * with common cookie management of popular HTTP agents.
-     * 
-     * @deprecated Use {@link #BROWSER_COMPATIBILITY}
-     */
-    public static final int COMPATIBILITY = 0;
-
-    /** 
-     * The <tt>NETSCAPE_DRAFT</tt> Netscape draft compliant policy.
-     * 
-     * @deprecated Use {@link #NETSCAPE} 
-     */
-    public static final int NETSCAPE_DRAFT = 1;
-
-    /** 
-     * The <tt>RFC2109</tt> RFC 2109 compliant policy.
-     * 
-     * @deprecated Use {@link #RFC_2109} 
-     */
-    public static final int RFC2109 = 2;
-
-    /**
-     * The <tt>RFC2965</tt> RFC 2965 compliant policy.
-     *
-     * @deprecated Use {@link #RFC_2965}
-     */
-    public static final int RFC2965 = 3;
-
-    /**
-     * The default cookie policy.
-     *  
-     * @deprecated Use {@link #DEFAULT} 
-     */
-    private static int defaultPolicy = RFC2109;
-
-    /** Log object. */
-    protected static final Log LOG = LogFactory.getLog(CookiePolicy.class);
-
-    /**
-     * Registers a new {@link CookieSpec cookie specification} with the given identifier.

+     * Registers a {@link CookieSpecFactory} with the given identifier. 
      * If a specification with the given ID already exists it will be overridden.  
-     * This ID is the same one used to retrieve the {@link CookieSpec cookie specification}

+     * This ID is the same one used to retrieve the {@link CookieSpecFactory} 
      * from {@link #getCookieSpec(String)}.
      * 
      * @param id the identifier for this specification
-     * @param clazz the {@link CookieSpec cookie specification} class to register
+     * @param factory the {@link CookieSpecFactory} class to register
      * 
      * @see #getCookieSpec(String)
      * 
      * @since 3.0
      */
-    public static void registerCookieSpec(final String id, final Class clazz) {
+    public static void register(final String id, final CookieSpecFactory factory) {
          if (id == null) {
              throw new IllegalArgumentException("Id may not be null");
          }
-        if (clazz == null) {
-            throw new IllegalArgumentException("Cookie spec class may not be null");
+        if (factory == null) {
+            throw new IllegalArgumentException("Cookie spec factory may not be null");
         }
-        SPECS.put(id.toLowerCase(), clazz);
+        SPECS.put(id.toLowerCase(), factory);
     }
 
     /**
-     * Unregisters the {@link CookieSpec cookie specification} with the given ID.
+     * Unregisters the {@link CookieSpecFactory} with the given ID.
      * 
      * @param id the ID of the {@link CookieSpec cookie specification} to unregister
      * 
      * @since 3.0
      */
-    public static void unregisterCookieSpec(final String id) {
+    public static void unregister(final String id) {
          if (id == null) {
              throw new IllegalArgumentException("Id may not be null");
          }
@@ -191,134 +93,68 @@
      * Gets the {@link CookieSpec cookie specification} with the given ID.
      * 
      * @param id the {@link CookieSpec cookie specification} ID
+     * @param params the {@link HttpParams HTTP parameters} for the cookie
+     *  specification. 
      * 
      * @return {@link CookieSpec cookie specification}
      * 
      * @throws IllegalStateException if a policy with the ID cannot be found
      * 
-     * @since 3.0
+     * @since 4.0
      */
-    public static CookieSpec getCookieSpec(final String id) 
+    public static CookieSpec getCookieSpec(final String id, final HttpParams params) 
         throws IllegalStateException {
 
         if (id == null) {
             throw new IllegalArgumentException("Id may not be null");
         }
-        Class clazz = (Class)SPECS.get(id.toLowerCase());
-
-        if (clazz != null) {
-            try {
-                return (CookieSpec)clazz.newInstance();
-            } catch (Exception e) {
-                LOG.error("Error initializing cookie spec: " + id, e);
-                throw new IllegalStateException(id + 
-                    " cookie spec implemented by " +
-                    clazz.getName() + " could not be initialized");
-            }
+        CookieSpecFactory factory = (CookieSpecFactory) SPECS.get(id.toLowerCase());
+        if (factory != null) {
+            return factory.newInstance(params);
         } else {
             throw new IllegalStateException("Unsupported cookie spec " + id);
         }
     } 
 
     /**
-     * @return default cookie policy
+     * Gets the {@link CookieSpec cookie specification} based on the given
+     * HTTP parameters. The cookie specification ID will be obtained from
+     * the HTTP parameters.
      * 
-     * @deprecated Use {@link #getDefaultSpec()}
+     * @param params the {@link HttpParams HTTP parameters} for the cookie
+     *  specification. 
      * 
-     * @see #getDefaultSpec()
-     */
-    public static int getDefaultPolicy() {
-        return defaultPolicy;
-    }
-    
-
-    /**
-     * @param policy new default cookie policy
+     * @return {@link CookieSpec cookie specification}
      * 
-     * @deprecated Use {@link CookiePolicy#registerCookieSpec(String, Class)}
-     * @see #DEFAULT 
-     */
-    public static void setDefaultPolicy(int policy) {
-        defaultPolicy = policy;
-    }
-    
-    /**
-     * @param policy cookie policy to get the CookieSpec for
-     * @return cookie specification interface for the given policy
+     * @throws IllegalStateException if a policy with the ID cannot be found
      * 
-     * @deprecated Use {@link CookiePolicy#getCookieSpec(String)} 
-     */
-    public static CookieSpec getSpecByPolicy(int policy) {
-        switch(policy) {
-            case COMPATIBILITY: 
-                return new CookieSpecBase(); 
-            case NETSCAPE_DRAFT: 
-                return new NetscapeDraftSpec(); 
-            case RFC2109:
-                return new RFC2109Spec();
-            case RFC2965:
-                return new RFC2965Spec();
-            default:
-                return getDefaultSpec(); 
-        }
-    }
-
-
-    /**
-     * Returns {@link CookieSpec cookie specification} registered as {@link #DEFAULT}. 
-     * If no default {@link CookieSpec cookie specification} has been registered, 
-     * {@link RFC2109Spec RFC2109 specification} is returned.
-     *  
-     * @return default {@link CookieSpec cookie specification}
+     * @see CookieSpecParams#getCookiePolicy(HttpParams)
      * 
-     * @see #DEFAULT
+     * @since 4.0
      */
-    public static CookieSpec getDefaultSpec() {
-        try {
-            return getCookieSpec(DEFAULT);
-        } catch (IllegalStateException e) {
-            LOG.warn("Default cookie policy is not registered");
-            return new RFC2109Spec();
+    public static CookieSpec getCookieSpec(final HttpParams params) 
+        throws IllegalStateException {
+        if (params == null) {
+            throw new IllegalArgumentException("HTTP parameters may not be null");
         }
-    }
-    
+        return getCookieSpec(CookieSpecParams.getCookiePolicy(params), params);
+    } 
 
     /**
-     * Gets the CookieSpec for a particular cookie version.
+     * Gets the {@link CookieSpec cookie specification} with the given ID.
      * 
-     * <p>Supported versions:
-     * <ul>
-     *  <li><tt>version 0</tt> corresponds to the Netscape draft
-     *  <li><tt>version 1</tt> corresponds to the RFC 2109
-     *  <li>Any other cookie value coresponds to the default spec
-     * <ul>
-     *
-     * @param ver the cookie version to get the spec for
-     * @return cookie specification interface intended for processing 
-     *  cookies with the given version
+     * @param id the {@link CookieSpec cookie specification} ID
      * 
-     * @deprecated Use {@link CookiePolicy#getCookieSpec(String)}
-     */
-    public static CookieSpec getSpecByVersion(int ver) {
-        switch(ver) {
-            case 0: 
-                return new NetscapeDraftSpec(); 
-            case 1:
-                return new RFC2109Spec();
-            default:
-                return getDefaultSpec(); 
-        }
-    }
-
-    /**
-     * @return cookie specification interface that provides high compatibilty 
-     * with common cookie management of popular HTTP agents
+     * @return {@link CookieSpec cookie specification}
+     * 
+     * @throws IllegalStateException if a policy with the ID cannot be found
      * 
-     * @deprecated Use {@link CookiePolicy#getCookieSpec(String)}
+     * @since 3.0
      */
-    public static CookieSpec getCompatibilitySpec() {
-        return getSpecByPolicy(COMPATIBILITY);
-    }
+    public static CookieSpec getCookieSpec(final String id) 
+        throws IllegalStateException {
+        return getCookieSpec(id, null);
+    } 
 
     /**
      * Obtains the currently registered cookie policy names.

Added: jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/cookie/CookieSpecFactory.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/cookie/CookieSpecFactory.java?rev=418097&view=auto
==============================================================================
--- jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/cookie/CookieSpecFactory.java
(added)
+++ jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/cookie/CookieSpecFactory.java
Thu Jun 29 10:48:45 2006
@@ -0,0 +1,44 @@
+/*
+ * $HeadURL$
+ * $Revision$
+ * $Date$
+ *
+ * ====================================================================
+ *
+ *  Copyright 2002-2004 The Apache Software Foundation
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+
+package org.apache.http.cookie;
+
+import org.apache.http.params.HttpParams;
+
+/**
+ * 
+ * @author <a href="mailto:oleg at ural.ru">Oleg Kalnichevski</a>
+ *
+ * @since 4.0
+ */
+public interface CookieSpecFactory {    
+
+    CookieSpec newInstance(HttpParams params);
+
+}

Propchange: jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/cookie/CookieSpecFactory.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/cookie/CookieSpecFactory.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/cookie/CookieSpecFactory.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/cookie/impl/BrowserCompatSpecFactory.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/cookie/impl/BrowserCompatSpecFactory.java?rev=418097&view=auto
==============================================================================
--- jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/cookie/impl/BrowserCompatSpecFactory.java
(added)
+++ jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/cookie/impl/BrowserCompatSpecFactory.java
Thu Jun 29 10:48:45 2006
@@ -0,0 +1,54 @@
+/*
+ * $HeadURL$
+ * $Revision$
+ * $Date$
+ *
+ * ====================================================================
+ *
+ *  Copyright 2002-2004 The Apache Software Foundation
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+
+package org.apache.http.cookie.impl;
+
+import org.apache.http.cookie.CookieSpec;
+import org.apache.http.cookie.CookieSpecFactory;
+import org.apache.http.cookie.params.CookieSpecParams;
+import org.apache.http.params.HttpParams;
+
+/**
+ * 
+ * @author <a href="mailto:oleg at ural.ru">Oleg Kalnichevski</a>
+ *
+ * @since 4.0
+ */
+public class BrowserCompatSpecFactory implements CookieSpecFactory {    
+
+    public CookieSpec newInstance(final HttpParams params) {
+        if (params != null) {
+            return new BrowserCompatSpec(
+                    (String []) params.getParameter(CookieSpecParams.DATE_PATTERNS));
+        } else {
+            return new BrowserCompatSpec();
+        }
+    }
+
+}

Propchange: jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/cookie/impl/BrowserCompatSpecFactory.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/cookie/impl/BrowserCompatSpecFactory.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/cookie/impl/BrowserCompatSpecFactory.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/cookie/impl/NetscapeDraftSpecFactory.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/cookie/impl/NetscapeDraftSpecFactory.java?rev=418097&view=auto
==============================================================================
--- jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/cookie/impl/NetscapeDraftSpecFactory.java
(added)
+++ jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/cookie/impl/NetscapeDraftSpecFactory.java
Thu Jun 29 10:48:45 2006
@@ -0,0 +1,48 @@
+/*
+ * $HeadURL$
+ * $Revision$
+ * $Date$
+ *
+ * ====================================================================
+ *
+ *  Copyright 2002-2004 The Apache Software Foundation
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+
+package org.apache.http.cookie.impl;
+
+import org.apache.http.cookie.CookieSpec;
+import org.apache.http.cookie.CookieSpecFactory;
+import org.apache.http.params.HttpParams;
+
+/**
+ * 
+ * @author <a href="mailto:oleg at ural.ru">Oleg Kalnichevski</a>
+ *
+ * @since 4.0
+ */
+public class NetscapeDraftSpecFactory implements CookieSpecFactory {    
+
+    public CookieSpec newInstance(final HttpParams params) {
+        return new NetscapeDraftSpec();
+    }
+
+}

Propchange: jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/cookie/impl/NetscapeDraftSpecFactory.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/cookie/impl/NetscapeDraftSpecFactory.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/cookie/impl/NetscapeDraftSpecFactory.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/cookie/impl/RFC2109SpecFactory.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/cookie/impl/RFC2109SpecFactory.java?rev=418097&view=auto
==============================================================================
--- jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/cookie/impl/RFC2109SpecFactory.java
(added)
+++ jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/cookie/impl/RFC2109SpecFactory.java
Thu Jun 29 10:48:45 2006
@@ -0,0 +1,55 @@
+/*
+ * $HeadURL$
+ * $Revision$
+ * $Date$
+ *
+ * ====================================================================
+ *
+ *  Copyright 2002-2004 The Apache Software Foundation
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+
+package org.apache.http.cookie.impl;
+
+import org.apache.http.cookie.CookieSpec;
+import org.apache.http.cookie.CookieSpecFactory;
+import org.apache.http.cookie.params.CookieSpecParams;
+import org.apache.http.params.HttpParams;
+
+/**
+ * 
+ * @author <a href="mailto:oleg at ural.ru">Oleg Kalnichevski</a>
+ *
+ * @since 4.0
+ */
+public class RFC2109SpecFactory implements CookieSpecFactory {    
+
+    public CookieSpec newInstance(final HttpParams params) {
+        if (params != null) {
+            return new RFC2109Spec(
+                    (String []) params.getParameter(CookieSpecParams.DATE_PATTERNS), 
+                    params.getBooleanParameter(CookieSpecParams.SINGLE_COOKIE_HEADER, false));
+        } else {
+            return new RFC2109Spec();
+        }
+    }
+
+}

Propchange: jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/cookie/impl/RFC2109SpecFactory.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/cookie/impl/RFC2109SpecFactory.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/cookie/impl/RFC2109SpecFactory.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/cookie/params/CookieSpecParams.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/cookie/params/CookieSpecParams.java?rev=418097&view=auto
==============================================================================
--- jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/cookie/params/CookieSpecParams.java
(added)
+++ jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/cookie/params/CookieSpecParams.java
Thu Jun 29 10:48:45 2006
@@ -0,0 +1,119 @@
+/*
+ * $HeadURL$
+ * $Revision$
+ * $Date$
+ *
+ * ====================================================================
+ *
+ *  Copyright 1999-2006 The Apache Software Foundation
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+
+package org.apache.http.cookie.params;
+
+import org.apache.http.params.HttpParams;
+
+/**
+ * This class implements an adaptor around the {@link HttpParams} interface
+ * to simplify manipulation of cookie management specific parameters.
+ * 
+ * @author <a href="mailto:oleg at ural.ru">Oleg Kalnichevski</a>
+ * 
+ * @version $Revision$
+ * 
+ * @since 4.0
+ */
+public final class CookieSpecParams {
+
+    /**
+     * The key used to look up the date patterns used for parsing. The String patterns are
stored
+     * in a {@link java.util.Collection} and must be compatible with 
+     * {@link java.text.SimpleDateFormat}.
+     * <p>
+     * This parameter expects a value of type {@link java.util.Collection}.
+     * </p>
+     */
+    public static final String DATE_PATTERNS = "http.protocol.cookie-datepatterns";
+    
+    /**
+     * Defines whether {@link org.apache.commons.httpclient.Cookie cookies} should be put
on 
+     * a single {@link org.apache.commons.httpclient.Header response header}.
+     * <p>
+     * This parameter expects a value of type {@link Boolean}.
+     * </p>
+     */
+    public static final String SINGLE_COOKIE_HEADER = "http.protocol.single-cookie-header";

+
+    /**
+     * Defines {@link CookieSpec cookie specification} to be used for cookie management.
+     * <p>
+     * This parameter expects a value of type {@link String}.
+     * </p>
+     */
+    public static final String COOKIE_POLICY = "http.protocol.cookie-policy";
+    
+    /**
+     * The policy that provides high degree of compatibilty 
+     * with common cookie management of popular HTTP agents.
+     */
+    public static final String BROWSER_COMPATIBILITY = "compatibility";
+    
+    /** 
+     * The Netscape cookie draft compliant policy. 
+     */
+    public static final String NETSCAPE = "netscape";
+
+    /** 
+     * The RFC 2109 compliant policy. 
+     */
+    public static final String RFC_2109 = "rfc2109";
+    
+    /** 
+     * The default cookie policy. 
+     */
+    public static final String DEFAULT = "default";
+    
+    public static String getCookiePolicy(final HttpParams params) { 
+        if (params == null) {
+            throw new IllegalArgumentException("HTTP parameters may not be null");
+        }
+        Object param = params.getParameter(COOKIE_POLICY);
+        if (param == null) {
+            return DEFAULT;
+        }
+        return (String) param;
+    }
+    
+    /**
+     * Assigns the {@link CookiePolicy cookie policy} to be used by the 
+     * {@link org.apache.commons.httpclient.HttpMethod HTTP methods} 
+     * this collection of parameters applies to. 
+     *
+     * @param policy the {@link CookiePolicy cookie policy}
+     */
+    public static void setCookiePolicy(final HttpParams params, String policy) {
+        if (params == null) {
+            throw new IllegalArgumentException("HTTP parameters may not be null");
+        }
+        params.setParameter(COOKIE_POLICY, policy);
+    }
+
+}

Propchange: jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/cookie/params/CookieSpecParams.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/cookie/params/CookieSpecParams.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/cookie/params/CookieSpecParams.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: jakarta/httpcomponents/httpclient/trunk/src/test/org/apache/http/cookie/TestAllCookie.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpclient/trunk/src/test/org/apache/http/cookie/TestAllCookie.java?rev=418097&r1=418096&r2=418097&view=diff
==============================================================================
--- jakarta/httpcomponents/httpclient/trunk/src/test/org/apache/http/cookie/TestAllCookie.java
(original)
+++ jakarta/httpcomponents/httpclient/trunk/src/test/org/apache/http/cookie/TestAllCookie.java
Thu Jun 29 10:48:45 2006
@@ -40,6 +40,7 @@
         TestSuite suite = new TestSuite();
         suite.addTest(TestCookieOrigin.suite());
         suite.addTest(TestCookiePathComparator.suite());
+        suite.addTest(TestCookiePolicy.suite());
         return suite;
     }
 

Added: jakarta/httpcomponents/httpclient/trunk/src/test/org/apache/http/cookie/TestCookiePolicy.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpclient/trunk/src/test/org/apache/http/cookie/TestCookiePolicy.java?rev=418097&view=auto
==============================================================================
--- jakarta/httpcomponents/httpclient/trunk/src/test/org/apache/http/cookie/TestCookiePolicy.java
(added)
+++ jakarta/httpcomponents/httpclient/trunk/src/test/org/apache/http/cookie/TestCookiePolicy.java
Thu Jun 29 10:48:45 2006
@@ -0,0 +1,156 @@
+/*
+ * $HeadURL$
+ * $Revision$
+ * $Date$
+ * ====================================================================
+ *
+ *  Copyright 1999-2006 The Apache Software Foundation
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+
+package org.apache.http.cookie;
+
+import org.apache.http.cookie.impl.BrowserCompatSpec;
+import org.apache.http.cookie.impl.BrowserCompatSpecFactory;
+import org.apache.http.cookie.impl.NetscapeDraftSpecFactory;
+import org.apache.http.cookie.impl.RFC2109SpecFactory;
+import org.apache.http.cookie.params.CookieSpecParams;
+import org.apache.http.impl.DefaultHttpParams;
+import org.apache.http.params.HttpParams;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+/**
+ * Test cases for {@link CookiePolicy}.
+ */
+public class TestCookiePolicy extends TestCase {
+
+
+    // ------------------------------------------------------------ Constructor
+
+    public TestCookiePolicy(String name) {
+        super(name);
+    }
+
+    // ------------------------------------------------------- TestCase Methods
+
+    public static Test suite() {
+        return new TestSuite(TestCookiePolicy.class);
+    }
+
+    public void testRegisterUnregisterCookieSpecFactory() {
+        String[] specs = CookiePolicy.getRegisteredCookieSpecs();
+        assertNotNull(specs);
+        assertEquals(0, specs.length);
+        
+        CookiePolicy.register(CookieSpecParams.BROWSER_COMPATIBILITY, 
+                new BrowserCompatSpecFactory());
+        CookiePolicy.register(CookieSpecParams.NETSCAPE, 
+                new NetscapeDraftSpecFactory());
+        CookiePolicy.register(CookieSpecParams.RFC_2109, 
+                new RFC2109SpecFactory());
+        CookiePolicy.register(CookieSpecParams.RFC_2109, 
+                new RFC2109SpecFactory());
+
+        specs = CookiePolicy.getRegisteredCookieSpecs();
+        assertNotNull(specs);
+        assertEquals(3, specs.length);
+
+        CookiePolicy.unregister(CookieSpecParams.NETSCAPE); 
+        CookiePolicy.unregister(CookieSpecParams.NETSCAPE); 
+        CookiePolicy.unregister(CookieSpecParams.RFC_2109); 
+        CookiePolicy.unregister(CookieSpecParams.BROWSER_COMPATIBILITY); 
+        CookiePolicy.unregister("whatever"); 
+        
+        specs = CookiePolicy.getRegisteredCookieSpecs();
+        assertNotNull(specs);
+        assertEquals(0, specs.length);
+    }
+
+    public void testGetNewCookieSpec() {
+        CookiePolicy.register(CookieSpecParams.BROWSER_COMPATIBILITY, 
+                new BrowserCompatSpecFactory());
+        CookiePolicy.register(CookieSpecParams.NETSCAPE, 
+                new NetscapeDraftSpecFactory());
+        CookiePolicy.register(CookieSpecParams.RFC_2109, 
+                new RFC2109SpecFactory());
+        
+        assertNotNull(CookiePolicy.getCookieSpec(CookieSpecParams.NETSCAPE));
+        assertNotNull(CookiePolicy.getCookieSpec(CookieSpecParams.RFC_2109));
+        assertNotNull(CookiePolicy.getCookieSpec(CookieSpecParams.BROWSER_COMPATIBILITY));
+        try {
+            CookiePolicy.getCookieSpec("whatever");
+            fail("IllegalStateException should have been thrown");
+        } catch (IllegalStateException ex) {
+            // expected
+        }
+        HttpParams params = new DefaultHttpParams();
+        assertNotNull(CookiePolicy.getCookieSpec(CookieSpecParams.NETSCAPE, params));
+        assertNotNull(CookiePolicy.getCookieSpec(CookieSpecParams.RFC_2109, params));
+        assertNotNull(CookiePolicy.getCookieSpec(CookieSpecParams.BROWSER_COMPATIBILITY,
params));
+        try {
+            CookiePolicy.getCookieSpec("whatever", params);
+            fail("IllegalStateException should have been thrown");
+        } catch (IllegalStateException ex) {
+            // expected
+        }
+        CookieSpecParams.setCookiePolicy(params, CookieSpecParams.BROWSER_COMPATIBILITY);
+        CookieSpec cookiespec = CookiePolicy.getCookieSpec(params);
+        assertTrue(cookiespec instanceof BrowserCompatSpec);
+    }
+
+    public void testInvalidInput() {
+        try {
+            CookiePolicy.register(null, null);
+            fail("IllegalArgumentException should have been thrown");
+        } catch (IllegalArgumentException ex) {
+            // expected
+        }
+        try {
+            CookiePolicy.register("whatever", null);
+            fail("IllegalArgumentException should have been thrown");
+        } catch (IllegalArgumentException ex) {
+            // expected
+        }
+        try {
+            CookiePolicy.unregister(null);
+            fail("IllegalArgumentException should have been thrown");
+        } catch (IllegalArgumentException ex) {
+            // expected
+        }
+        try {
+            CookiePolicy.getCookieSpec((String)null);
+            fail("IllegalArgumentException should have been thrown");
+        } catch (IllegalArgumentException ex) {
+            // expected
+        }
+        try {
+            CookiePolicy.getCookieSpec((HttpParams)null);
+            fail("IllegalArgumentException should have been thrown");
+        } catch (IllegalArgumentException ex) {
+            // expected
+        }
+    }
+    
+}
+

Propchange: jakarta/httpcomponents/httpclient/trunk/src/test/org/apache/http/cookie/TestCookiePolicy.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jakarta/httpcomponents/httpclient/trunk/src/test/org/apache/http/cookie/TestCookiePolicy.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: jakarta/httpcomponents/httpclient/trunk/src/test/org/apache/http/cookie/TestCookiePolicy.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain



Mime
View raw message