You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by an...@apache.org on 2019/02/19 12:34:46 UTC

svn commit: r1853875 - /cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/modules/input/CookieModule.java

Author: anathaniel
Date: Tue Feb 19 12:34:46 2019
New Revision: 1853875

URL: http://svn.apache.org/viewvc?rev=1853875&view=rev
Log:
Fix compile error in CookieModule

Modified:
    cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/modules/input/CookieModule.java

Modified: cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/modules/input/CookieModule.java
URL: http://svn.apache.org/viewvc/cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/modules/input/CookieModule.java?rev=1853875&r1=1853874&r2=1853875&view=diff
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/modules/input/CookieModule.java (original)
+++ cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/modules/input/CookieModule.java Tue Feb 19 12:34:46 2019
@@ -5,9 +5,9 @@
  * The ASF licenses this file to You 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.
@@ -21,33 +21,33 @@ import java.util.Iterator;
 import java.util.LinkedList;
 import java.util.List;
 import java.util.Map;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
 
 import org.apache.avalon.framework.configuration.Configuration;
 import org.apache.avalon.framework.configuration.ConfigurationException;
 import org.apache.avalon.framework.thread.ThreadSafe;
-import org.apache.cocoon.components.modules.input.AbstractInputModule;
 import org.apache.cocoon.environment.ObjectModelHelper;
 import org.apache.cocoon.environment.http.HttpCookie;
-import org.apache.regexp.RE;
 
 /**
  * Input module for cookies. Retrieves the value of the requested cookie.
- * 
+ *
  * @author Jon Evans <jo...@misgl.com>
  * @version CVS $Id:$
  */
 public class CookieModule extends AbstractInputModule implements ThreadSafe {
-    
+
     /**
      * @return the value of the cookie whose name matches the one requested,
      * or <code>null</code> if there is no match.
      */
     public Object getAttribute(String name, Configuration modeConf,
             Map objectModel) throws ConfigurationException {
-        
-        HttpCookie cookie = (HttpCookie) getCookieMap(objectModel).get(name);
+
+        HttpCookie cookie = getCookieMap(objectModel).get(name);
         String value = (cookie == null ? null : cookie.getValue());
-        
+
         if (getLogger().isDebugEnabled()) {
             getLogger().debug("Cookie[" + name + "]=" + value);
         }
@@ -56,34 +56,33 @@ public class CookieModule extends Abstra
 
     /*
      * (non-Javadoc)
-     * 
+     *
      * @see org.apache.cocoon.components.modules.input.InputModule#getAttributeNames(org.apache.avalon.framework.configuration.Configuration,
      *      java.util.Map)
      */
-    public Iterator getAttributeNames(Configuration modeConf, Map objectModel)
+    public Iterator<String> getAttributeNames(Configuration modeConf, Map objectModel)
             throws ConfigurationException {
-        
+
         return getCookieMap(objectModel).keySet().iterator();
     }
 
     /*
      * (non-Javadoc)
-     * 
+     *
      * @see org.apache.cocoon.components.modules.input.InputModule#getAttributeValues(java.lang.String,
      *      org.apache.avalon.framework.configuration.Configuration,
      *      java.util.Map)
      */
     public Object[] getAttributeValues(String name, Configuration modeConf,
             Map objectModel) throws ConfigurationException {
-        
-        Map allCookies = getCookieMap(objectModel);
-        
-        Iterator it = allCookies.values().iterator();
-        List matched = new LinkedList();
-        RE regexp = new RE(name);
-        while (it.hasNext()) {
-            HttpCookie cookie = (HttpCookie) it.next();
-            if (regexp.match(cookie.getName())) {
+
+        Pattern pattern = Pattern.compile(name);
+        List<String> matched = new LinkedList<String>();
+        Map<String, HttpCookie> allCookies = getCookieMap(objectModel);
+
+        for (HttpCookie cookie : allCookies.values()) {
+            Matcher matcher = pattern.matcher(cookie.getName());
+            if (matcher.matches()) {
                 matched.add(cookie.getValue());
             }
         }
@@ -96,7 +95,9 @@ public class CookieModule extends Abstra
      * @return a Map of {see: HttpCookie}s for the current request, keyed on
      *         cookie name.
      */
-    protected Map getCookieMap(Map objectModel) {
-        return ObjectModelHelper.getRequest(objectModel).getCookieMap();
+    protected Map<String, HttpCookie> getCookieMap(Map objectModel) {
+        @SuppressWarnings("unchecked")
+        Map<String, HttpCookie> result = (Map<String, HttpCookie>) ObjectModelHelper.getRequest(objectModel).getCookieMap();
+        return result;
     }
 }