You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@struts.apache.org by rg...@apache.org on 2009/02/23 17:21:14 UTC

svn commit: r747065 - in /struts/struts2/trunk/core/src: main/java/org/apache/struts2/config/ main/java/org/apache/struts2/interceptor/ test/java/org/apache/struts2/interceptor/

Author: rgielen
Date: Mon Feb 23 16:21:12 2009
New Revision: 747065

URL: http://svn.apache.org/viewvc?rev=747065&view=rev
Log:
WW-2883 StrutsXmlConfigurationProvider generics fix
- applied patch submitted by Mathias Bogaert

Modified:
    struts/struts2/trunk/core/src/main/java/org/apache/struts2/config/StrutsXmlConfigurationProvider.java
    struts/struts2/trunk/core/src/main/java/org/apache/struts2/interceptor/CookieInterceptor.java
    struts/struts2/trunk/core/src/main/java/org/apache/struts2/interceptor/CookiesAware.java
    struts/struts2/trunk/core/src/test/java/org/apache/struts2/interceptor/CookieInterceptorTest.java

Modified: struts/struts2/trunk/core/src/main/java/org/apache/struts2/config/StrutsXmlConfigurationProvider.java
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/core/src/main/java/org/apache/struts2/config/StrutsXmlConfigurationProvider.java?rev=747065&r1=747064&r2=747065&view=diff
==============================================================================
--- struts/struts2/trunk/core/src/main/java/org/apache/struts2/config/StrutsXmlConfigurationProvider.java (original)
+++ struts/struts2/trunk/core/src/main/java/org/apache/struts2/config/StrutsXmlConfigurationProvider.java Mon Feb 23 16:21:12 2009
@@ -91,8 +91,8 @@
     @Override
     public void register(ContainerBuilder containerBuilder, LocatableProperties props) throws ConfigurationException {
         if (servletContext != null && !containerBuilder.contains(ServletContext.class)) {
-            containerBuilder.factory(ServletContext.class, new Factory<ServletContext>() {
-                public ServletContext create(Context context) throws Exception {
+            containerBuilder.factory(ServletContext.class, new Factory() {
+                public Object create(Context context) throws Exception {
                     return servletContext;
                 }
                 
@@ -148,7 +148,7 @@
         }
         if (file.exists()) {
             try {
-                url = file.toURI().toURL();
+                url = file.toURL();
             } catch (MalformedURLException e) {
                 throw new IOException("Unable to convert "+file+" to a URL");
             }

Modified: struts/struts2/trunk/core/src/main/java/org/apache/struts2/interceptor/CookieInterceptor.java
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/core/src/main/java/org/apache/struts2/interceptor/CookieInterceptor.java?rev=747065&r1=747064&r2=747065&view=diff
==============================================================================
--- struts/struts2/trunk/core/src/main/java/org/apache/struts2/interceptor/CookieInterceptor.java (original)
+++ struts/struts2/trunk/core/src/main/java/org/apache/struts2/interceptor/CookieInterceptor.java Mon Feb 23 16:21:12 2009
@@ -21,7 +21,10 @@
 
 package org.apache.struts2.interceptor;
 
-import java.util.*;
+import java.util.Collections;
+import java.util.LinkedHashMap;
+import java.util.Map;
+import java.util.Set;
 
 import javax.servlet.http.Cookie;
 import javax.servlet.http.HttpServletRequest;
@@ -161,11 +164,11 @@
 
     private static final Logger LOG = LoggerFactory.getLogger(CookieInterceptor.class);
 
-    private Set<String> cookiesNameSet = Collections.emptySet();
-    private Set<String> cookiesValueSet = Collections.emptySet();
+    private Set cookiesNameSet = Collections.EMPTY_SET;
+    private Set cookiesValueSet = Collections.EMPTY_SET;
 
     /**
-     * Set the <code>cookiesName</code> which if matched will allow the cookie
+     * Set the <code>cookiesName</code> which if matche will allow the cookie
      * to be injected into action, could be comma-separated string.
      *
      * @param cookiesName
@@ -187,32 +190,35 @@
             this.cookiesValueSet = TextParseUtil.commaDelimitedStringToSet(cookiesValue);
     }
 
+
     public String intercept(ActionInvocation invocation) throws Exception {
+
         if (LOG.isDebugEnabled())
             LOG.debug("start interception");
 
+        final ValueStack stack = ActionContext.getContext().getValueStack();
+        HttpServletRequest request = ServletActionContext.getRequest();
+
         // contains selected cookies
-        final Map<String, String> cookiesMap = new LinkedHashMap<String, String>();
+        Map cookiesMap = new LinkedHashMap();
 
-        Cookie[] cookies = ServletActionContext.getRequest().getCookies();
+        Cookie cookies[] = request.getCookies();
         if (cookies != null) {
-            final ValueStack stack = ActionContext.getContext().getValueStack();
-
-            for (Cookie cookie : cookies) {
-                String name = cookie.getName();
-                String value = cookie.getValue();
+            for (int a=0; a< cookies.length; a++) {
+                String name = cookies[a].getName();
+                String value = cookies[a].getValue();
 
                 if (cookiesNameSet.contains("*")) {
                     if (LOG.isDebugEnabled())
-                        LOG.debug("contains cookie name [*] in configured cookies name set, cookie with name [" + name + "] with value [" + value + "] will be injected");
+                        LOG.debug("contains cookie name [*] in configured cookies name set, cookie with name ["+name+"] with value ["+value+"] will be injected");
                     populateCookieValueIntoStack(name, value, cookiesMap, stack);
-                } else if (cookiesNameSet.contains(cookie.getName())) {
+                }
+                else if (cookiesNameSet.contains(cookies[a].getName())) {
                     populateCookieValueIntoStack(name, value, cookiesMap, stack);
                 }
             }
         }
 
-        // inject the cookiesMap, even if we don't have any cookies
         injectIntoCookiesAwareAction(invocation.getAction(), cookiesMap);
 
         return invocation.invoke();
@@ -227,7 +233,7 @@
      * @param cookiesMap
      * @param stack
      */
-    protected void populateCookieValueIntoStack(String cookieName, String cookieValue, Map<String, String> cookiesMap, ValueStack stack) {
+    protected void populateCookieValueIntoStack(String cookieName, String cookieValue, Map cookiesMap, ValueStack stack) {
         if (cookiesValueSet.isEmpty() || cookiesValueSet.contains("*")) {
             // If the interceptor is configured to accept any cookie value
             // OR
@@ -261,11 +267,12 @@
      * @param action
      * @param cookiesMap
      */
-    protected void injectIntoCookiesAwareAction(Object action, Map<String, String> cookiesMap) {
+    protected void injectIntoCookiesAwareAction(Object action, Map cookiesMap) {
         if (action instanceof CookiesAware) {
             if (LOG.isDebugEnabled())
                 LOG.debug("action ["+action+"] implements CookiesAware, injecting cookies map ["+cookiesMap+"]");
             ((CookiesAware)action).setCookiesMap(cookiesMap);
         }
     }
+
 }

Modified: struts/struts2/trunk/core/src/main/java/org/apache/struts2/interceptor/CookiesAware.java
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/core/src/main/java/org/apache/struts2/interceptor/CookiesAware.java?rev=747065&r1=747064&r2=747065&view=diff
==============================================================================
--- struts/struts2/trunk/core/src/main/java/org/apache/struts2/interceptor/CookiesAware.java (original)
+++ struts/struts2/trunk/core/src/main/java/org/apache/struts2/interceptor/CookiesAware.java Mon Feb 23 16:21:12 2009
@@ -24,5 +24,5 @@
 import java.util.Map;
 
 public interface CookiesAware {
-    void setCookiesMap(Map<String, String> cookies);
-}
\ No newline at end of file
+    void setCookiesMap(Map cookies);
+}

Modified: struts/struts2/trunk/core/src/test/java/org/apache/struts2/interceptor/CookieInterceptorTest.java
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/core/src/test/java/org/apache/struts2/interceptor/CookieInterceptorTest.java?rev=747065&r1=747064&r2=747065&view=diff
==============================================================================
--- struts/struts2/trunk/core/src/test/java/org/apache/struts2/interceptor/CookieInterceptorTest.java (original)
+++ struts/struts2/trunk/core/src/test/java/org/apache/struts2/interceptor/CookieInterceptorTest.java Mon Feb 23 16:21:12 2009
@@ -326,10 +326,9 @@
         private String cookie2;
         private String cookie3;
 
-        public void setCookiesMap(Map<String, String> cookies) {
+        public void setCookiesMap(Map cookies) {
             this.cookies = cookies;
         }
-
         public Map getCookiesMap() {
             return this.cookies;
         }