struts-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lukaszlen...@apache.org
Subject [02/33] struts git commit: Defines global-allowed-methods
Date Mon, 28 Sep 2015 18:52:51 GMT
Defines global-allowed-methods


Project: http://git-wip-us.apache.org/repos/asf/struts/repo
Commit: http://git-wip-us.apache.org/repos/asf/struts/commit/ce884e92
Tree: http://git-wip-us.apache.org/repos/asf/struts/tree/ce884e92
Diff: http://git-wip-us.apache.org/repos/asf/struts/diff/ce884e92

Branch: refs/heads/master
Commit: ce884e92a15ef601b0e119963d3c521fa68d8bb1
Parents: 065b5b7
Author: Lukasz Lenart <lukaszlenart@apache.org>
Authored: Mon Aug 31 14:33:31 2015 +0200
Committer: Lukasz Lenart <lukaszlenart@apache.org>
Committed: Mon Aug 31 14:33:31 2015 +0200

----------------------------------------------------------------------
 .../xwork2/config/entities/ActionConfig.java    |   1 +
 .../providers/XmlConfigurationProvider.java     |  48 ++++--
 .../config/StrutsXmlConfigurationProvider.java  |   1 +
 core/src/main/resources/struts-2.5.dtd          | 156 +++++++++++++++++++
 core/src/main/resources/struts-default.xml      |   6 +-
 core/src/main/resources/xwork-2.5.dtd           | 135 ++++++++++++++++
 6 files changed, 336 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/struts/blob/ce884e92/core/src/main/java/com/opensymphony/xwork2/config/entities/ActionConfig.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/com/opensymphony/xwork2/config/entities/ActionConfig.java
b/core/src/main/java/com/opensymphony/xwork2/config/entities/ActionConfig.java
index b947ed9..fd61ad9 100644
--- a/core/src/main/java/com/opensymphony/xwork2/config/entities/ActionConfig.java
+++ b/core/src/main/java/com/opensymphony/xwork2/config/entities/ActionConfig.java
@@ -42,6 +42,7 @@ import java.util.*;
 public class ActionConfig extends Located implements Serializable {
 
     public static final String DEFAULT_METHOD = "execute";
+    public static final String WILDCARD = "*";
 
     protected List<InterceptorMapping> interceptors; // a list of interceptorMapping
Objects eg. List<InterceptorMapping>
     protected Map<String,String> params;

http://git-wip-us.apache.org/repos/asf/struts/blob/ce884e92/core/src/main/java/com/opensymphony/xwork2/config/providers/XmlConfigurationProvider.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/com/opensymphony/xwork2/config/providers/XmlConfigurationProvider.java
b/core/src/main/java/com/opensymphony/xwork2/config/providers/XmlConfigurationProvider.java
index 12a71c7..449d254 100644
--- a/core/src/main/java/com/opensymphony/xwork2/config/providers/XmlConfigurationProvider.java
+++ b/core/src/main/java/com/opensymphony/xwork2/config/providers/XmlConfigurationProvider.java
@@ -15,12 +15,24 @@
  */
 package com.opensymphony.xwork2.config.providers;
 
-import com.opensymphony.xwork2.*;
+import com.opensymphony.xwork2.Action;
+import com.opensymphony.xwork2.FileManager;
+import com.opensymphony.xwork2.FileManagerFactory;
+import com.opensymphony.xwork2.ObjectFactory;
+import com.opensymphony.xwork2.XWorkException;
 import com.opensymphony.xwork2.config.Configuration;
 import com.opensymphony.xwork2.config.ConfigurationException;
 import com.opensymphony.xwork2.config.ConfigurationProvider;
 import com.opensymphony.xwork2.config.ConfigurationUtil;
-import com.opensymphony.xwork2.config.entities.*;
+import com.opensymphony.xwork2.config.entities.ActionConfig;
+import com.opensymphony.xwork2.config.entities.ExceptionMappingConfig;
+import com.opensymphony.xwork2.config.entities.InterceptorConfig;
+import com.opensymphony.xwork2.config.entities.InterceptorMapping;
+import com.opensymphony.xwork2.config.entities.InterceptorStackConfig;
+import com.opensymphony.xwork2.config.entities.PackageConfig;
+import com.opensymphony.xwork2.config.entities.ResultConfig;
+import com.opensymphony.xwork2.config.entities.ResultTypeConfig;
+import com.opensymphony.xwork2.config.entities.UnknownHandlerConfig;
 import com.opensymphony.xwork2.config.impl.LocatableFactory;
 import com.opensymphony.xwork2.inject.Container;
 import com.opensymphony.xwork2.inject.ContainerBuilder;
@@ -47,7 +59,17 @@ import java.io.IOException;
 import java.io.InputStream;
 import java.lang.reflect.Modifier;
 import java.net.URL;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.Vector;
 
 
 /**
@@ -90,6 +112,7 @@ public class XmlConfigurationProvider implements ConfigurationProvider
{
         this.errorIfMissing = errorIfMissing;
 
         Map<String, String> mappings = new HashMap<>();
+        mappings.put("-//Apache Struts//XWork 2.5//EN", "xwork-2.5.dtd");
         mappings.put("-//Apache Struts//XWork 2.3//EN", "xwork-2.3.dtd");
         mappings.put("-//Apache Struts//XWork 2.1.3//EN", "xwork-2.1.3.dtd");
         mappings.put("-//Apache Struts//XWork 2.1//EN", "xwork-2.1.dtd");
@@ -522,6 +545,8 @@ public class XmlConfigurationProvider implements ConfigurationProvider
{
         // load the global result list for this package
         loadGlobalResults(newPackage, packageElement);
 
+        loadGlobalAllowedMethods(newPackage, packageElement);
+
         // load the global exception handler list for this package
         loadGobalExceptionMappings(newPackage, packageElement);
 
@@ -623,8 +648,6 @@ public class XmlConfigurationProvider implements ConfigurationProvider
{
         boolean isAbstract = Boolean.parseBoolean(abstractVal);
         String name = StringUtils.defaultString(packageElement.getAttribute("name"));
         String namespace = StringUtils.defaultString(packageElement.getAttribute("namespace"));
-        String strictDMIVal = StringUtils.defaultString(packageElement.getAttribute("strict-method-invocation"));
-        boolean strictDMI = Boolean.parseBoolean(strictDMIVal);
 
         if (StringUtils.isNotEmpty(packageElement.getAttribute("externalReferenceResolver")))
{
             throw new ConfigurationException("The 'externalReferenceResolver' attribute has
been removed.  Please use " +
@@ -634,7 +657,6 @@ public class XmlConfigurationProvider implements ConfigurationProvider
{
         PackageConfig.Builder cfg = new PackageConfig.Builder(name)
                 .namespace(namespace)
                 .isAbstract(isAbstract)
-                .strictMethodInvocation(strictDMI)
                 .location(DomHelper.getLocationObject(packageElement));
 
         if (StringUtils.isNotEmpty(StringUtils.defaultString(parent))) { // has parents,
let's look it up
@@ -825,7 +847,7 @@ public class XmlConfigurationProvider implements ConfigurationProvider
{
     protected Set<String> buildAllowedMethods(Element element, PackageConfig.Builder
packageContext) {
         NodeList allowedMethodsEls = element.getElementsByTagName("allowed-methods");
 
-        Set<String> allowedMethods = null;
+        Set<String> allowedMethods = packageContext.getGlobalAllowedMethods();
 
         if (allowedMethodsEls.getLength() > 0) {
             allowedMethods = new HashSet<>();
@@ -836,8 +858,6 @@ public class XmlConfigurationProvider implements ConfigurationProvider
{
                     allowedMethods = TextParseUtil.commaDelimitedStringToSet(s);
                 }
             }
-        } else if (packageContext.isStrictMethodInvocation()) {
-            allowedMethods = new HashSet<>();
         }
 
         return allowedMethods;
@@ -877,6 +897,16 @@ public class XmlConfigurationProvider implements ConfigurationProvider
{
         }
     }
 
+    protected void loadGlobalAllowedMethods(PackageConfig.Builder packageContext, Element
packageElement) {
+        NodeList globalAllowedMethods = packageElement.getElementsByTagName("global-allowed-methods");
+
+        if (globalAllowedMethods.getLength() > 0) {
+            Element globalAllowedMethodsElement = (Element) globalAllowedMethods.item(0);
+            Set<String> results = TextParseUtil.commaDelimitedStringToSet(globalAllowedMethodsElement.getAttribute("methods"));
+            packageContext.addGlobalAllowedMethods(results);
+        }
+    }
+
     protected void loadDefaultClassRef(PackageConfig.Builder packageContext, Element element)
{
         NodeList defaultClassRefList = element.getElementsByTagName("default-class-ref");
         if (defaultClassRefList.getLength() > 0) {

http://git-wip-us.apache.org/repos/asf/struts/blob/ce884e92/core/src/main/java/org/apache/struts2/config/StrutsXmlConfigurationProvider.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/struts2/config/StrutsXmlConfigurationProvider.java
b/core/src/main/java/org/apache/struts2/config/StrutsXmlConfigurationProvider.java
index cca80b7..e39e475 100644
--- a/core/src/main/java/org/apache/struts2/config/StrutsXmlConfigurationProvider.java
+++ b/core/src/main/java/org/apache/struts2/config/StrutsXmlConfigurationProvider.java
@@ -75,6 +75,7 @@ public class StrutsXmlConfigurationProvider extends XmlConfigurationProvider
{
         dtdMappings.put("-//Apache Software Foundation//DTD Struts Configuration 2.1//EN",
"struts-2.1.dtd");
         dtdMappings.put("-//Apache Software Foundation//DTD Struts Configuration 2.1.7//EN",
"struts-2.1.7.dtd");
         dtdMappings.put("-//Apache Software Foundation//DTD Struts Configuration 2.3//EN",
"struts-2.3.dtd");
+        dtdMappings.put("-//Apache Software Foundation//DTD Struts Configuration 2.5//EN",
"struts-2.5.dtd");
         setDtdMappings(dtdMappings);
         File file = new File(filename);
         if (file.getParent() != null) {

http://git-wip-us.apache.org/repos/asf/struts/blob/ce884e92/core/src/main/resources/struts-2.5.dtd
----------------------------------------------------------------------
diff --git a/core/src/main/resources/struts-2.5.dtd b/core/src/main/resources/struts-2.5.dtd
new file mode 100644
index 0000000..86afbc0
--- /dev/null
+++ b/core/src/main/resources/struts-2.5.dtd
@@ -0,0 +1,156 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+/*
+ * $Id: struts-2.0.dtd 651946 2008-04-27 13:41:38Z apetrelli $
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  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.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+-->
+<!-- START SNIPPET: strutsDtd -->
+
+<!--
+   Struts configuration DTD.
+   Use the following DOCTYPE
+
+   <!DOCTYPE struts PUBLIC
+	"-//Apache Software Foundation//DTD Struts Configuration 2.5//EN"
+	"http://struts.apache.org/dtds/struts-2.5.dtd">
+-->
+
+<!ELEMENT struts ((package|include|bean|constant)*, unknown-handler-stack?)>
+<!ATTLIST struts
+    order CDATA #IMPLIED
+>
+
+<!ELEMENT package (result-types?, interceptors?, default-interceptor-ref?, default-action-ref?,
default-class-ref?, global-results?, global-allowed-methods? global-exception-mappings?, action*)>
+<!ATTLIST package
+    name CDATA #REQUIRED
+    extends CDATA #IMPLIED
+    namespace CDATA #IMPLIED
+    abstract CDATA #IMPLIED
+    externalReferenceResolver NMTOKEN #IMPLIED
+>
+
+<!ELEMENT result-types (result-type+)>
+
+<!ELEMENT result-type (param*)>
+<!ATTLIST result-type
+    name CDATA #REQUIRED
+    class CDATA #REQUIRED
+    default (true|false) "false"
+>
+
+<!ELEMENT interceptors (interceptor|interceptor-stack)+>
+
+<!ELEMENT interceptor (param*)>
+<!ATTLIST interceptor
+    name CDATA #REQUIRED
+    class CDATA #REQUIRED
+>
+
+<!ELEMENT interceptor-stack (interceptor-ref*)>
+<!ATTLIST interceptor-stack
+    name CDATA #REQUIRED
+>
+
+<!ELEMENT interceptor-ref (param*)>
+<!ATTLIST interceptor-ref
+    name CDATA #REQUIRED
+>
+
+<!ELEMENT default-interceptor-ref (#PCDATA)>
+<!ATTLIST default-interceptor-ref
+    name CDATA #REQUIRED
+>
+
+<!ELEMENT default-action-ref (#PCDATA)>
+<!ATTLIST default-action-ref
+    name CDATA #REQUIRED
+>
+
+<!ELEMENT default-class-ref (#PCDATA)>
+<!ATTLIST default-class-ref
+    class CDATA #REQUIRED
+>
+
+<!ELEMENT global-results (result+)>
+
+<!ELEMENT global-allowed-methods (#PCDATA)>
+<!ATTLIST global-allowed-methods
+    methods CDATA #REQUIRED
+>
+
+<!ELEMENT global-exception-mappings (exception-mapping+)>
+
+<!ELEMENT action ((param|result|interceptor-ref|exception-mapping)*,allowed-methods?)>
+<!ATTLIST action
+    name CDATA #REQUIRED
+    class CDATA #IMPLIED
+    method CDATA #IMPLIED
+    converter CDATA #IMPLIED
+>
+
+<!ELEMENT param (#PCDATA)>
+<!ATTLIST param
+    name CDATA #REQUIRED
+>
+
+<!ELEMENT result (#PCDATA|param)*>
+<!ATTLIST result
+    name CDATA #IMPLIED
+    type CDATA #IMPLIED
+>
+
+<!ELEMENT exception-mapping (#PCDATA|param)*>
+<!ATTLIST exception-mapping
+    name CDATA #IMPLIED
+    exception CDATA #REQUIRED
+    result CDATA #REQUIRED
+>
+
+<!ELEMENT allowed-methods (#PCDATA)>
+
+<!ELEMENT include (#PCDATA)>
+<!ATTLIST include
+    file CDATA #REQUIRED
+>
+
+<!ELEMENT bean (#PCDATA)>
+<!ATTLIST bean
+    type CDATA #IMPLIED
+    name CDATA #IMPLIED
+    class CDATA #REQUIRED
+    scope CDATA #IMPLIED
+    static CDATA #IMPLIED
+    optional CDATA #IMPLIED
+>
+
+<!ELEMENT constant (#PCDATA)>
+<!ATTLIST constant
+    name CDATA #REQUIRED
+    value CDATA #REQUIRED
+>
+
+<!ELEMENT unknown-handler-stack (unknown-handler-ref*)>
+<!ELEMENT unknown-handler-ref (#PCDATA)>
+<!ATTLIST unknown-handler-ref
+    name CDATA #REQUIRED
+>
+
+<!-- END SNIPPET: strutsDtd -->
+

http://git-wip-us.apache.org/repos/asf/struts/blob/ce884e92/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 ca2a654..9fc1c21 100644
--- a/core/src/main/resources/struts-default.xml
+++ b/core/src/main/resources/struts-default.xml
@@ -33,8 +33,8 @@
     and {@link com.opensymphony.xwork2.inject.Inject}
 -->
 <!DOCTYPE struts PUBLIC
-    "-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
-    "http://struts.apache.org/dtds/struts-2.3.dtd">
+    "-//Apache Software Foundation//DTD Struts Configuration 2.5//EN"
+    "http://struts.apache.org/dtds/struts-2.5.dtd">
 
 <struts>
 
@@ -358,6 +358,8 @@
 
        </interceptors>
 
+       <global-allowed-methods methods="execute,input,back,cancel,browse"/>
+
         <default-interceptor-ref name="defaultStack"/>
 
         <default-class-ref class="com.opensymphony.xwork2.ActionSupport" />

http://git-wip-us.apache.org/repos/asf/struts/blob/ce884e92/core/src/main/resources/xwork-2.5.dtd
----------------------------------------------------------------------
diff --git a/core/src/main/resources/xwork-2.5.dtd b/core/src/main/resources/xwork-2.5.dtd
new file mode 100644
index 0000000..efbd765
--- /dev/null
+++ b/core/src/main/resources/xwork-2.5.dtd
@@ -0,0 +1,135 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!-- START SNIPPET: xworkDtd -->
+
+<!--
+   XWork configuration DTD.
+   Use the following DOCTYPE
+
+   <!DOCTYPE xwork PUBLIC
+	"-//Apache Struts//XWork 2.5//EN"
+	"http://struts.apache.org/dtds/xwork-2.5.dtd">
+-->
+
+<!ELEMENT xwork ((package|include|bean|constant)*, unknown-handler-stack?)>
+<!ATTLIST xwork
+    order CDATA #IMPLIED
+>
+
+<!ELEMENT package (result-types?, interceptors?, default-interceptor-ref?, default-action-ref?,
default-class-ref?, global-results?, global-allowed-methods?, global-exception-mappings?,
action*)>
+<!ATTLIST package
+    name CDATA #REQUIRED
+    extends CDATA #IMPLIED
+    namespace CDATA #IMPLIED
+    abstract CDATA #IMPLIED
+    strict-method-invocation CDATA #IMPLIED
+>
+
+<!ELEMENT result-types (result-type+)>
+
+<!ELEMENT result-type (param*)>
+<!ATTLIST result-type
+    name CDATA #REQUIRED
+    class CDATA #REQUIRED
+    default (true|false) "false"
+>
+
+<!ELEMENT interceptors (interceptor|interceptor-stack)+>
+
+<!ELEMENT interceptor (param*)>
+<!ATTLIST interceptor
+    name CDATA #REQUIRED
+    class CDATA #REQUIRED
+>
+
+<!ELEMENT interceptor-stack (interceptor-ref*)>
+<!ATTLIST interceptor-stack
+    name CDATA #REQUIRED
+>
+
+<!ELEMENT interceptor-ref (param*)>
+<!ATTLIST interceptor-ref
+    name CDATA #REQUIRED
+>
+
+<!ELEMENT default-interceptor-ref (#PCDATA)>
+<!ATTLIST default-interceptor-ref
+    name CDATA #REQUIRED
+>
+
+<!ELEMENT default-action-ref (#PCDATA)>
+<!ATTLIST default-action-ref
+    name CDATA #REQUIRED
+>
+
+<!ELEMENT default-class-ref (#PCDATA)>
+<!ATTLIST default-class-ref
+   class CDATA #REQUIRED
+>
+
+<!ELEMENT global-results (result+)>
+
+<!ELEMENT global-allowed-methods (#PCDATA)>
+<!ATTLIST global-allowed-methods
+    methods CDATA #REQUIRED
+>
+
+<!ELEMENT global-exception-mappings (exception-mapping+)>
+
+<!ELEMENT action ((param|result|interceptor-ref|exception-mapping)*,allowed-methods?)>
+<!ATTLIST action
+    name CDATA #REQUIRED
+    class CDATA #IMPLIED
+    method CDATA #IMPLIED
+    converter CDATA #IMPLIED
+>
+
+<!ELEMENT param (#PCDATA)>
+<!ATTLIST param
+    name CDATA #REQUIRED
+>
+
+<!ELEMENT result (#PCDATA|param)*>
+<!ATTLIST result
+    name CDATA #IMPLIED
+    type CDATA #IMPLIED
+>
+
+<!ELEMENT exception-mapping (#PCDATA|param)*>
+<!ATTLIST exception-mapping
+    name CDATA #IMPLIED
+    exception CDATA #REQUIRED
+    result CDATA #REQUIRED
+>
+
+<!ELEMENT allowed-methods (#PCDATA)>
+
+<!ELEMENT include (#PCDATA)>
+<!ATTLIST include
+    file CDATA #REQUIRED
+>
+
+<!ELEMENT bean (#PCDATA)>
+<!ATTLIST bean
+    type CDATA #IMPLIED
+    name CDATA #IMPLIED
+    class CDATA #REQUIRED
+    scope CDATA #IMPLIED
+    static CDATA #IMPLIED
+    optional CDATA #IMPLIED
+>
+
+<!ELEMENT constant (#PCDATA)>
+<!ATTLIST constant
+    name CDATA #REQUIRED
+    value CDATA #REQUIRED
+>
+
+<!ELEMENT unknown-handler-stack (unknown-handler-ref*)>
+<!ELEMENT unknown-handler-ref (#PCDATA)>
+<!ATTLIST unknown-handler-ref
+    name CDATA #REQUIRED
+>
+
+<!-- END SNIPPET: xworkDtd -->
+


Mime
View raw message