Repository: struts Updated Branches: refs/heads/develop 5665dd52b -> 54c642348
WW-4457 Uses dedicated type to match content type of uploaded files Project: http://git-wip-us.apache.org/repos/asf/struts/repo Commit: http://git-wip-us.apache.org/repos/asf/struts/commit/54c64234 Tree: http://git-wip-us.apache.org/repos/asf/struts/tree/54c64234 Diff: http://git-wip-us.apache.org/repos/asf/struts/diff/54c64234 Branch: refs/heads/develop Commit: 54c64234844488d178e4ac1579ab8194a36b8b4a Parents: 5665dd5 Author: Lukasz Lenart <lukaszlen...@apache.org> Authored: Fri Mar 6 22:34:35 2015 +0100 Committer: Lukasz Lenart <lukaszlen...@apache.org> Committed: Fri Mar 6 22:34:35 2015 +0100 ---------------------------------------------------------------------- .../org/apache/struts2/StrutsConstants.java | 2 ++ .../config/DefaultBeanSelectionProvider.java | 8 ++++++++ .../interceptor/FileUploadInterceptor.java | 6 +++--- .../apache/struts2/util/ContentTypeMatcher.java | 16 ++++++++++++++++ .../struts2/util/DefaultContentTypeMatcher.java | 20 ++++++++++++++++++++ core/src/main/resources/struts-default.xml | 2 ++ 6 files changed, 51 insertions(+), 3 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/struts/blob/54c64234/core/src/main/java/org/apache/struts2/StrutsConstants.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/struts2/StrutsConstants.java b/core/src/main/java/org/apache/struts2/StrutsConstants.java index 03287d6..4671eb1 100644 --- a/core/src/main/java/org/apache/struts2/StrutsConstants.java +++ b/core/src/main/java/org/apache/struts2/StrutsConstants.java @@ -299,4 +299,6 @@ public final class StrutsConstants { public static final String STRUTS_ADDITIONAL_EXCLUDED_PATTERNS = "struts.additional.excludedPatterns"; public static final String STRUTS_ADDITIONAL_ACCEPTED_PATTERNS = "struts.additional.acceptedPatterns"; + public static final String STRUTS_CONTENT_TYPE_MATCHER = "struts.contentTypeMatcher"; + } http://git-wip-us.apache.org/repos/asf/struts/blob/54c64234/core/src/main/java/org/apache/struts2/config/DefaultBeanSelectionProvider.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/struts2/config/DefaultBeanSelectionProvider.java b/core/src/main/java/org/apache/struts2/config/DefaultBeanSelectionProvider.java index f972979..3a6deb2 100644 --- a/core/src/main/java/org/apache/struts2/config/DefaultBeanSelectionProvider.java +++ b/core/src/main/java/org/apache/struts2/config/DefaultBeanSelectionProvider.java @@ -67,6 +67,7 @@ import org.apache.struts2.dispatcher.DispatcherErrorHandler; import org.apache.struts2.dispatcher.StaticContentLoader; import org.apache.struts2.dispatcher.mapper.ActionMapper; import org.apache.struts2.dispatcher.multipart.MultiPartRequest; +import org.apache.struts2.util.ContentTypeMatcher; import org.apache.struts2.views.freemarker.FreemarkerManager; import org.apache.struts2.views.util.UrlHelper; import org.apache.struts2.views.velocity.VelocityManager; @@ -327,6 +328,12 @@ import java.util.StringTokenizer; * <td>request</td> * <td>Used across different interceptors to check if given string matches one of the accepted patterns</td> * </tr> + * <tr> + * <td>org.apache.struts2.util.ContentTypeMatcher</td> + * <td>struts.contentTypeMatcher</td> + * <td>singleton</td> + * <td>Matches content type of uploaded files (since 2.3.22)</td> + * </tr> * </table> * * <!-- END SNIPPET: extensionPoints --> @@ -391,6 +398,7 @@ public class DefaultBeanSelectionProvider extends AbstractBeanSelectionProvider alias(ReflectionProvider.class, StrutsConstants.STRUTS_REFLECTIONPROVIDER, builder, props); alias(ReflectionContextFactory.class, StrutsConstants.STRUTS_REFLECTIONCONTEXTFACTORY, builder, props); alias(PatternMatcher.class, StrutsConstants.STRUTS_PATTERNMATCHER, builder, props); + alias(ContentTypeMatcher.class, StrutsConstants.STRUTS_CONTENT_TYPE_MATCHER, builder, props); alias(StaticContentLoader.class, StrutsConstants.STRUTS_STATIC_CONTENT_LOADER, builder, props); alias(UnknownHandlerManager.class, StrutsConstants.STRUTS_UNKNOWN_HANDLER_MANAGER, builder, props); alias(UrlHelper.class, StrutsConstants.STRUTS_URL_HELPER, builder, props); http://git-wip-us.apache.org/repos/asf/struts/blob/54c64234/core/src/main/java/org/apache/struts2/interceptor/FileUploadInterceptor.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/struts2/interceptor/FileUploadInterceptor.java b/core/src/main/java/org/apache/struts2/interceptor/FileUploadInterceptor.java index 0ce91bc..78970a0 100644 --- a/core/src/main/java/org/apache/struts2/interceptor/FileUploadInterceptor.java +++ b/core/src/main/java/org/apache/struts2/interceptor/FileUploadInterceptor.java @@ -31,12 +31,12 @@ import com.opensymphony.xwork2.ValidationAware; import com.opensymphony.xwork2.inject.Container; import com.opensymphony.xwork2.inject.Inject; import com.opensymphony.xwork2.interceptor.AbstractInterceptor; -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; import org.apache.struts2.ServletActionContext; import org.apache.struts2.dispatcher.multipart.MultiPartRequestWrapper; +import org.apache.struts2.util.ContentTypeMatcher; import javax.servlet.http.HttpServletRequest; import java.io.File; @@ -195,11 +195,11 @@ public class FileUploadInterceptor extends AbstractInterceptor { protected Set<String> allowedTypesSet = Collections.emptySet(); protected Set<String> allowedExtensionsSet = Collections.emptySet(); - private PatternMatcher matcher; + private ContentTypeMatcher matcher; private Container container; @Inject - public void setMatcher(PatternMatcher matcher) { + public void setMatcher(ContentTypeMatcher matcher) { this.matcher = matcher; } http://git-wip-us.apache.org/repos/asf/struts/blob/54c64234/core/src/main/java/org/apache/struts2/util/ContentTypeMatcher.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/struts2/util/ContentTypeMatcher.java b/core/src/main/java/org/apache/struts2/util/ContentTypeMatcher.java new file mode 100644 index 0000000..0e21b7a --- /dev/null +++ b/core/src/main/java/org/apache/struts2/util/ContentTypeMatcher.java @@ -0,0 +1,16 @@ +package org.apache.struts2.util; + +import java.util.Map; + +/** + * Matches content type of uploaded files, similar to {@link com.opensymphony.xwork2.util.PatternMatcher} + * + * @since 2.3.22 + */ +public interface ContentTypeMatcher<E extends Object> { + + E compilePattern(String data); + + boolean match(Map<String,String> map, String data, E expr); + +} http://git-wip-us.apache.org/repos/asf/struts/blob/54c64234/core/src/main/java/org/apache/struts2/util/DefaultContentTypeMatcher.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/struts2/util/DefaultContentTypeMatcher.java b/core/src/main/java/org/apache/struts2/util/DefaultContentTypeMatcher.java new file mode 100644 index 0000000..6160675 --- /dev/null +++ b/core/src/main/java/org/apache/struts2/util/DefaultContentTypeMatcher.java @@ -0,0 +1,20 @@ +package org.apache.struts2.util; + +import com.opensymphony.xwork2.util.PatternMatcher; +import com.opensymphony.xwork2.util.WildcardHelper; + +import java.util.Map; + +public class DefaultContentTypeMatcher implements ContentTypeMatcher<int[]> { + + private PatternMatcher<int[]> matcher = new WildcardHelper(); + + public int[] compilePattern(String data) { + return matcher.compilePattern(data); + } + + public boolean match(Map<String, String> map, String data, int[] expr) { + return matcher.match(map, data, expr); + } + +} http://git-wip-us.apache.org/repos/asf/struts/blob/54c64234/core/src/main/resources/struts-default.xml ---------------------------------------------------------------------- diff --git a/core/src/main/resources/struts-default.xml b/core/src/main/resources/struts-default.xml index c6eec34..88b6e13 100644 --- a/core/src/main/resources/struts-default.xml +++ b/core/src/main/resources/struts-default.xml @@ -74,6 +74,8 @@ <bean type="com.opensymphony.xwork2.util.PatternMatcher" name="namedVariable" class="com.opensymphony.xwork2.util.NamedVariablePatternMatcher"/> <bean type="com.opensymphony.xwork2.util.PatternMatcher" name="regex" class="org.apache.struts2.util.RegexPatternMatcher"/> + <bean type="org.apache.struts2.util.ContentTypeMatcher" name="struts" class="org.apache.struts2.util.DefaultContentTypeMatcher"/> + <bean type="org.apache.struts2.dispatcher.mapper.ActionMapper" name="struts" class="org.apache.struts2.dispatcher.mapper.DefaultActionMapper" /> <bean type="org.apache.struts2.dispatcher.mapper.ActionMapper" name="composite" class="org.apache.struts2.dispatcher.mapper.CompositeActionMapper" /> <bean type="org.apache.struts2.dispatcher.mapper.ActionMapper" name="restful" class="org.apache.struts2.dispatcher.mapper.RestfulActionMapper" />