struts-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lukaszlen...@apache.org
Subject svn commit: r941483 - in /struts/struts2/trunk/core/src: main/java/org/apache/struts2/interceptor/FileUploadInterceptor.java test/java/org/apache/struts2/interceptor/FileUploadInterceptorTest.java
Date Wed, 05 May 2010 20:59:20 GMT
Author: lukaszlenart
Date: Wed May  5 20:59:19 2010
New Revision: 941483

URL: http://svn.apache.org/viewvc?rev=941483&view=rev
Log:
Switched to PatternMatcher bean

Modified:
    struts/struts2/trunk/core/src/main/java/org/apache/struts2/interceptor/FileUploadInterceptor.java
    struts/struts2/trunk/core/src/test/java/org/apache/struts2/interceptor/FileUploadInterceptorTest.java

Modified: struts/struts2/trunk/core/src/main/java/org/apache/struts2/interceptor/FileUploadInterceptor.java
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/core/src/main/java/org/apache/struts2/interceptor/FileUploadInterceptor.java?rev=941483&r1=941482&r2=941483&view=diff
==============================================================================
--- struts/struts2/trunk/core/src/main/java/org/apache/struts2/interceptor/FileUploadInterceptor.java
(original)
+++ struts/struts2/trunk/core/src/main/java/org/apache/struts2/interceptor/FileUploadInterceptor.java
Wed May  5 20:59:19 2010
@@ -25,8 +25,10 @@ import com.opensymphony.xwork2.ActionCon
 import com.opensymphony.xwork2.ActionInvocation;
 import com.opensymphony.xwork2.ActionProxy;
 import com.opensymphony.xwork2.ValidationAware;
+import com.opensymphony.xwork2.inject.Inject;
 import com.opensymphony.xwork2.interceptor.AbstractInterceptor;
 import com.opensymphony.xwork2.util.LocalizedTextUtil;
+import com.opensymphony.xwork2.util.PatternMatcher;
 import com.opensymphony.xwork2.util.TextParseUtil;
 import com.opensymphony.xwork2.util.logging.Logger;
 import com.opensymphony.xwork2.util.logging.LoggerFactory;
@@ -35,14 +37,7 @@ import org.apache.struts2.dispatcher.mul
 
 import javax.servlet.http.HttpServletRequest;
 import java.io.File;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.Enumeration;
-import java.util.List;
-import java.util.Locale;
-import java.util.Map;
-import java.util.Set;
+import java.util.*;
 
 /**
  * <!-- START SNIPPET: description -->
@@ -192,6 +187,13 @@ public class FileUploadInterceptor exten
     protected Set<String> allowedTypesSet = Collections.emptySet();
     protected Set<String> allowedExtensionsSet = Collections.emptySet();
 
+    private PatternMatcher matcher;
+
+    @Inject
+    public void setMatcher(PatternMatcher matcher) {
+        this.matcher = matcher;
+    }
+
     public void setUseActionMessageBundle(String value) {
         this.useActionMessageBundle = Boolean.valueOf(value);
     }
@@ -417,36 +419,8 @@ public class FileUploadInterceptor exten
     }
 
     private boolean matchesWildcard(String pattern, String text) {
-        text += '\0';
-        pattern += '\0';
-
-        int N = pattern.length();
-
-        boolean[] states = new boolean[N + 1];
-        boolean[] old = new boolean[N + 1];
-        old[0] = true;
-
-        for (int i = 0; i < text.length(); i++) {
-            char c = text.charAt(i);
-            states = new boolean[N + 1];
-            for (int j = 0; j < N; j++) {
-                char p = pattern.charAt(j);
-
-                if (old[j] && (p == '*'))
-                    old[j + 1] = true;
-
-                if (old[j] && (p == c))
-                    states[j + 1] = true;
-                if (old[j] && (p == '?'))
-                    states[j + 1] = true;
-                if (old[j] && (p == '*'))
-                    states[j] = true;
-                if (old[j] && (p == '*'))
-                    states[j + 1] = true;
-            }
-            old = states;
-        }
-        return states[N];
+        Object o = matcher.compilePattern(pattern);
+        return matcher.match(new HashMap<String, String>(), text, o);
     }
 
     private boolean isNonEmpty(Object[] objArray) {

Modified: struts/struts2/trunk/core/src/test/java/org/apache/struts2/interceptor/FileUploadInterceptorTest.java
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/core/src/test/java/org/apache/struts2/interceptor/FileUploadInterceptorTest.java?rev=941483&r1=941482&r2=941483&view=diff
==============================================================================
--- struts/struts2/trunk/core/src/test/java/org/apache/struts2/interceptor/FileUploadInterceptorTest.java
(original)
+++ struts/struts2/trunk/core/src/test/java/org/apache/struts2/interceptor/FileUploadInterceptorTest.java
Wed May  5 20:59:19 2010
@@ -362,6 +362,7 @@ public class FileUploadInterceptorTest e
     protected void setUp() throws Exception {
         super.setUp();
         interceptor = new FileUploadInterceptor();
+        container.inject(interceptor);
         tempDir = File.createTempFile("struts", "fileupload");
         tempDir.delete();
         tempDir.mkdirs();



Mime
View raw message