Commits

Anonymous committed bd55478

XW-73: Allow any mixture of "include" and "package" elements below xwork element to be processed in order

git-svn-id: http://svn.opensymphony.com/svn/xwork/trunk@17e221344d-f017-0410-9bd5-d282ab1896d7

  • Participants
  • Parent commits 5d6ecbf

Comments (0)

Files changed (4)

File src/etc/xwork-1.0.dtd

 <?xml version="1.0" encoding="UTF-8"?>
-<!ELEMENT xwork (package+,include*)>
+<!ELEMENT xwork (package|include)+>
 
 <!ELEMENT package (result-types?, interceptors?, default-interceptor-ref?, global-results?, action*)>
 <!ATTLIST package

File src/java/com/opensymphony/xwork/config/providers/XmlConfigurationProvider.java

         }
     }
 
-    protected void loadIncludes(Element rootElement, DocumentBuilder db) throws Exception {
-        NodeList includeList = rootElement.getElementsByTagName("include");
-
-        for (int i = 0; i < includeList.getLength(); i++) {
-            Element includeElement = (Element) includeList.item(i);
-            String fileName = includeElement.getAttribute("file");
-            includedFileNames.add(fileName);
-            loadConfigurationFile(fileName, db);
-        }
-    }
-
+    //    protected void loadIncludes(Element rootElement, DocumentBuilder db) throws Exception {
+    //        NodeList includeList = rootElement.getElementsByTagName("include");
+    //
+    //        for (int i = 0; i < includeList.getLength(); i++) {
+    //            Element includeElement = (Element) includeList.item(i);
+    //            String fileName = includeElement.getAttribute("file");
+    //            includedFileNames.add(fileName);
+    //            loadConfigurationFile(fileName, db);
+    //        }
+    //    }
     protected InterceptorStackConfig loadInterceptorStack(Element element, PackageConfig context) throws ConfigurationException {
         String name = element.getAttribute("name");
 
         loadInterceptorStacks(element, context);
     }
 
-    protected void loadPackages(Element rootElement) throws ConfigurationException {
-        NodeList packageList = rootElement.getElementsByTagName("package");
-
-        for (int i = 0; i < packageList.getLength(); i++) {
-            Element packageElement = (Element) packageList.item(i);
-            addPackage(packageElement);
-        }
-    }
-
+    //    protected void loadPackages(Element rootElement) throws ConfigurationException {
+    //        NodeList packageList = rootElement.getElementsByTagName("package");
+    //
+    //        for (int i = 0; i < packageList.getLength(); i++) {
+    //            Element packageElement = (Element) packageList.item(i);
+    //            addPackage(packageElement);
+    //        }
+    //    }
     private void loadConfigurationFile(String fileName, DocumentBuilder db) throws Exception {
         Document doc = null;
         InputStream is = null;
         }
 
         Element rootElement = doc.getDocumentElement();
+        NodeList children = rootElement.getChildNodes();
+        int childSize = children.getLength();
+
+        for (int i = 0; i < childSize; i++) {
+            Node childNode = children.item(i);
+
+            if (childNode instanceof Element) {
+                Element child = (Element) childNode;
+
+                final String nodeName = child.getNodeName();
+
+                if (nodeName.equals("package")) {
+                    addPackage(child);
+                } else if (nodeName.equals("include")) {
+                    String includeFileName = child.getAttribute("file");
+                    includedFileNames.add(includeFileName);
+                    loadConfigurationFile(includeFileName, db);
+                }
+            }
+        }
 
-        loadPackages(rootElement);
-        loadIncludes(rootElement, db);
+        //        loadPackages(rootElement);
+        //        loadIncludes(rootElement, db);
     }
 
     /**

File src/test/xwork-default.xml

+<!DOCTYPE xwork PUBLIC
+    "-//OpenSymphony Group//XWork 1.0//EN"
+    "http://www.opensymphony.com/xwork/xwork-1.0.dtd"
+ >
+
+<xwork>
+    <package name="xwork-default">
+        <result-types>
+            <result-type name="chain" class="com.opensymphony.xwork.ActionChainResult" default="true"/>
+        </result-types>
+
+        <interceptors>
+            <interceptor name="timer" class="com.opensymphony.xwork.interceptor.TimerInterceptor"/>
+            <interceptor name="logger" class="com.opensymphony.xwork.interceptor.LoggingInterceptor"/>
+            <interceptor name="chain" class="com.opensymphony.xwork.interceptor.ChainingInterceptor"/>
+            <interceptor name="params" class="com.opensymphony.xwork.interceptor.ParametersInterceptor"/>
+            <interceptor name="static-params" class="com.opensymphony.xwork.interceptor.StaticParametersInterceptor"/>
+            <interceptor name="model-driven" class="com.opensymphony.xwork.interceptor.ModelDrivenInterceptor"/>
+            <interceptor name="component" class="com.opensymphony.xwork.interceptor.component.ComponentInterceptor"/>
+            <interceptor name="test" class="com.opensymphony.xwork.MockInterceptor">
+                <param name="foo">expectedFoo</param>
+            </interceptor>
+
+            <interceptor-stack name="defaultStack">
+                <interceptor-ref name="static-params"/>
+                <interceptor-ref name="model-driven"/>
+                <interceptor-ref name="params"/>
+            </interceptor-stack>
+
+            <interceptor-stack name="debugStack">
+                <interceptor-ref name="timer"/>
+                <interceptor-ref name="logger"/>
+            </interceptor-stack>
+        </interceptors>
+    </package>
+</xwork>

File src/test/xwork.xml

  >
 
 <xwork>
-    <package name="default">
-        <result-types>
-            <result-type name="chain" class="com.opensymphony.xwork.ActionChainResult" default="true"/>
-        </result-types>
-
-        <interceptors>
-            <interceptor name="timer" class="com.opensymphony.xwork.interceptor.TimerInterceptor"/>
-            <interceptor name="logger" class="com.opensymphony.xwork.interceptor.LoggingInterceptor"/>
-            <interceptor name="chain" class="com.opensymphony.xwork.interceptor.ChainingInterceptor"/>
-            <interceptor name="params" class="com.opensymphony.xwork.interceptor.ParametersInterceptor"/>
-            <interceptor name="static-params" class="com.opensymphony.xwork.interceptor.StaticParametersInterceptor"/>
-            <interceptor name="model-driven" class="com.opensymphony.xwork.interceptor.ModelDrivenInterceptor"/>
-            <interceptor name="component" class="com.opensymphony.xwork.interceptor.component.ComponentInterceptor"/>
-            <interceptor name="test" class="com.opensymphony.xwork.MockInterceptor">
-                <param name="foo">expectedFoo</param>
-            </interceptor>
-
-            <interceptor-stack name="defaultStack">
-                <interceptor-ref name="static-params"/>
-                <interceptor-ref name="model-driven"/>
-                <interceptor-ref name="params"/>
-            </interceptor-stack>
-
-            <interceptor-stack name="debugStack">
-                <interceptor-ref name="timer"/>
-                <interceptor-ref name="logger"/>
-            </interceptor-stack>
-        </interceptors>
-
+    <include file="xwork-default.xml"/>
+    <package name="default" extends="xwork-default">
         <global-results>
             <result name="login"> <!-- should be chain type since it is the default -->
                 <param name="actionName">login</param>