Attached is a patch for ActionServlet to allow
multiple config files.  With this patch you can
specify a comma separated list of config files like
this:

<init-param>
    <param-name>config</param-name>
    <param-value>
        /WEB-INF/struts-config.xml,
        /WEB-INF/struts-config2.xml
    </param-value>
</init-param>

This is also backwards compatible so that existing
config files still work.

This is a patch for "STRUTS_1_0_BRANCH".  I will
follow up with a 1.1 patch too.

Thoughts?  I know there has been a reasonable amount
of desire for this functionality on the user list.

-james
[EMAIL PROTECTED]
http://www.ejcenter.com/struts/

__________________________________________________
Do You Yahoo!?
Make a great connection at Yahoo! Personals.
http://personals.yahoo.com
Index: jakarta-struts/src/share/org/apache/struts/action/ActionServlet.java
===================================================================
RCS file: 
/home/cvspublic/jakarta-struts/src/share/org/apache/struts/action/ActionServlet.java,v
retrieving revision 1.68.2.4
diff -u -r1.68.2.4 ActionServlet.java
--- jakarta-struts/src/share/org/apache/struts/action/ActionServlet.java        
2001/10/07 04:49:15     1.68.2.4
+++ jakarta-struts/src/share/org/apache/struts/action/ActionServlet.java        
+2001/10/19 21:07:37
@@ -72,6 +72,7 @@
 import java.util.Iterator;
 import java.util.Locale;
 import java.util.MissingResourceException;
+import java.util.StringTokenizer;
 import javax.servlet.RequestDispatcher;
 import javax.servlet.ServletException;
 import javax.servlet.UnavailableException;
@@ -159,9 +160,9 @@
  *     resources bundle base class.  [NONE]</li>
  * <li><strong>bufferSize</strong> - The size of the input buffer used when
  *     processing file uploads.  [4096]</li>
- * <li><strong>config</strong> - Context-relative path to the XML resource
- *     containing our configuration information.
- *     [/WEB-INF/struts-config.xml]</li>
+ * <li><strong>config</strong> - Comma seperated list of context-relative paths
+ *     to the XML resources containing our configuration information.
+ *     [/WEB-INF/struts-config.xml,/WEB-INF/struts-config2.xml]</li>
  * <li><strong>content</strong> - Default content type and character encoding
  *     to be set on each response; may be overridden by a forwarded-to
  *     servlet or JSP page.  [text/html]</li>
@@ -1311,34 +1312,44 @@
        if (debug >= 1)
            log(internal.getMessage("configInit", config));
 
-       // Acquire an input stream to our configuration resource
-       InputStream input = getServletContext().getResourceAsStream(config);
-       if (input == null)
-           throw new UnavailableException
-               (internal.getMessage("configMissing", config));
-
-       // Build a digester to process our configuration resource
-       Digester digester = null;
-       if (validate)
-           digester = initDigester(detail);
-       else
-           digester = initDigesterOld(detail);
+       // don't use fast
+       formBeans.setFast(false);
+       forwards.setFast(false);
+       mappings.setFast(false);
+
+       // Process each config file
+       StringTokenizer st = new StringTokenizer(config, ",");
+       while (st.hasMoreTokens()) {
+           String configToken = st.nextToken().trim();
+
+           // Acquire an input stream to our configuration resource
+           InputStream input = getServletContext().getResourceAsStream(configToken);
+           if (input == null)
+               throw new UnavailableException
+                  (internal.getMessage("configMissing", configToken));
+
+           // Build a digester to process our configuration resource
+           Digester digester = null;
+           if (validate)
+               digester = initDigester(detail);
+           else
+               digester = initDigesterOld(detail);
 
-       // Parse the input stream to configure our mappings
-       try {
-            formBeans.setFast(false);
-            forwards.setFast(false);
-            mappings.setFast(false);
-           digester.parse(input);
-            mappings.setFast(true);
-            forwards.setFast(true);
-            formBeans.setFast(true);
-       } catch (SAXException e) {
-           throw new ServletException
-               (internal.getMessage("configParse", config), e);
-        } finally {
-           input.close();
+           // Parse the input stream to configure our mappings
+           try {
+               digester.parse(input);
+           } catch (SAXException e) {
+               throw new ServletException
+                   (internal.getMessage("configParse", configToken), e);
+           } finally {
+               input.close();
+           }
        }
+
+       // use fast
+       mappings.setFast(true);
+       forwards.setFast(true);
+       formBeans.setFast(true);
 
         // Transitional support for old format
         if (!validate) {

Reply via email to