Author: markt
Date: Sat Feb  9 10:45:05 2008
New Revision: 620173

URL: http://svn.apache.org/viewvc?rev=620173&view=rev
Log:
Add support for system property replacement.

Modified:
    tomcat/container/branches/tc4.1.x/RELEASE-NOTES-4.1.txt
    
tomcat/container/branches/tc4.1.x/catalina/src/share/org/apache/catalina/core/StandardHostDeployer.java
    
tomcat/container/branches/tc4.1.x/catalina/src/share/org/apache/catalina/startup/Catalina.java
    
tomcat/container/branches/tc4.1.x/catalina/src/share/org/apache/catalina/startup/HostConfig.java
    tomcat/current/tc4.1.x/STATUS.txt

Modified: tomcat/container/branches/tc4.1.x/RELEASE-NOTES-4.1.txt
URL: 
http://svn.apache.org/viewvc/tomcat/container/branches/tc4.1.x/RELEASE-NOTES-4.1.txt?rev=620173&r1=620172&r2=620173&view=diff
==============================================================================
--- tomcat/container/branches/tc4.1.x/RELEASE-NOTES-4.1.txt (original)
+++ tomcat/container/branches/tc4.1.x/RELEASE-NOTES-4.1.txt Sat Feb  9 10:45:05 
2008
@@ -302,6 +302,9 @@
          Startup scripts
          Provide greater control over redirection of stdout and stderr
 
+[4.1.37] Configuration files
+         Add support for system property replacement in configuration files
+
 
 -------------------
 Jasper New Features:

Modified: 
tomcat/container/branches/tc4.1.x/catalina/src/share/org/apache/catalina/core/StandardHostDeployer.java
URL: 
http://svn.apache.org/viewvc/tomcat/container/branches/tc4.1.x/catalina/src/share/org/apache/catalina/core/StandardHostDeployer.java?rev=620173&r1=620172&r2=620173&view=diff
==============================================================================
--- 
tomcat/container/branches/tc4.1.x/catalina/src/share/org/apache/catalina/core/StandardHostDeployer.java
 (original)
+++ 
tomcat/container/branches/tc4.1.x/catalina/src/share/org/apache/catalina/core/StandardHostDeployer.java
 Sat Feb  9 10:45:05 2008
@@ -23,6 +23,7 @@
 import java.io.InputStream;
 import java.io.IOException;
 import java.net.URL;
+import java.util.Map;
 import org.apache.catalina.Container;
 import org.apache.catalina.Context;
 import org.apache.catalina.Deployer;
@@ -36,6 +37,9 @@
 import org.apache.catalina.startup.NamingRuleSet;
 import org.apache.catalina.util.StringManager;
 import org.apache.commons.digester.Digester;
+import org.apache.commons.digester.Substitutor;
+import org.apache.commons.digester.substitution.VariableSubstitutor;
+import org.apache.commons.digester.substitution.MultiVariableExpander;
 
 
 /**
@@ -680,6 +684,23 @@
 
 
     /**
+     * Adds a substitutor to interpolate system properties
+     *
+     * @param digester The digester to which we add the substitutor
+     */
+    protected void enableDigesterSubstitutor(Digester digester)
+    {
+        Map systemProperties = System.getProperties();
+        MultiVariableExpander expander = new MultiVariableExpander();
+        expander.addSource("$", systemProperties);
+
+        // allow expansion in both xml attributes and element text
+        Substitutor substitutor = new VariableSubstitutor(expander);
+        digester.setSubstitutor(substitutor);
+    }
+
+
+    /**
      * Create (if necessary) and return a Digester configured to process the
      * context configuration descriptor for an application.
      */
@@ -690,6 +711,8 @@
             if (host.getDebug() > 0)
                 digester.setDebug(3);
             digester.setValidating(false);
+            // Add a substitutor to resolve system properties
+            enableDigesterSubstitutor(digester);
             contextRuleSet = new ContextRuleSet("");
             digester.addRuleSet(contextRuleSet);
             namingRuleSet = new NamingRuleSet("Context/");

Modified: 
tomcat/container/branches/tc4.1.x/catalina/src/share/org/apache/catalina/startup/Catalina.java
URL: 
http://svn.apache.org/viewvc/tomcat/container/branches/tc4.1.x/catalina/src/share/org/apache/catalina/startup/Catalina.java?rev=620173&r1=620172&r2=620173&view=diff
==============================================================================
--- 
tomcat/container/branches/tc4.1.x/catalina/src/share/org/apache/catalina/startup/Catalina.java
 (original)
+++ 
tomcat/container/branches/tc4.1.x/catalina/src/share/org/apache/catalina/startup/Catalina.java
 Sat Feb  9 10:45:05 2008
@@ -25,6 +25,7 @@
 import java.io.OutputStream;
 import java.net.Socket;
 import java.security.Security;
+import java.util.Map;
 import org.apache.catalina.Container;
 import org.apache.catalina.Lifecycle;
 import org.apache.catalina.LifecycleException;
@@ -32,6 +33,9 @@
 import org.apache.catalina.core.StandardServer;
 import org.apache.commons.digester.Digester;
 import org.apache.commons.digester.Rule;
+import org.apache.commons.digester.Substitutor;
+import org.apache.commons.digester.substitution.VariableSubstitutor;
+import org.apache.commons.digester.substitution.MultiVariableExpander;
 import org.apache.tomcat.util.log.SystemLogHandler;
 import org.xml.sax.Attributes;
 import org.xml.sax.InputSource;
@@ -222,6 +226,23 @@
 
 
     /**
+     * Adds a substitutor to interpolate system properties
+     * 
+     * @param digester The digester to which we add the substitutor
+     */
+    protected void enableDigesterSubstitutor(Digester digester)
+    {
+        Map systemProperties = System.getProperties();
+        MultiVariableExpander expander = new MultiVariableExpander();
+        expander.addSource("$", systemProperties);
+
+        // allow expansion in both xml attributes and element text
+        Substitutor substitutor = new VariableSubstitutor(expander);
+        digester.setSubstitutor(substitutor);
+    }
+    
+
+    /**
      * Create and configure the Digester we will be using for startup.
      */
     protected Digester createStartDigester() {
@@ -230,6 +251,8 @@
         Digester digester = new Digester();
         digester.setClassLoader(StandardServer.class.getClassLoader());
         digester.setValidating(false);
+        // Add a substitutor to resolve system properties
+        enableDigesterSubstitutor(digester);
 
         // Configure the actions we will be using
         digester.addObjectCreate("Server",
@@ -322,6 +345,8 @@
 
         // Initialize the digester
         Digester digester = new Digester();
+        // Add a substitutor to resolve system properties
+        enableDigesterSubstitutor(digester);
 
         // Configure the rules we need for shutting down
         digester.addObjectCreate("Server",

Modified: 
tomcat/container/branches/tc4.1.x/catalina/src/share/org/apache/catalina/startup/HostConfig.java
URL: 
http://svn.apache.org/viewvc/tomcat/container/branches/tc4.1.x/catalina/src/share/org/apache/catalina/startup/HostConfig.java?rev=620173&r1=620172&r2=620173&view=diff
==============================================================================
--- 
tomcat/container/branches/tc4.1.x/catalina/src/share/org/apache/catalina/startup/HostConfig.java
 (original)
+++ 
tomcat/container/branches/tc4.1.x/catalina/src/share/org/apache/catalina/startup/HostConfig.java
 Sat Feb  9 10:45:05 2008
@@ -26,6 +26,7 @@
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.Iterator;
+import java.util.Map;
 
 import javax.naming.NamingException;
 import javax.naming.directory.DirContext;
@@ -42,6 +43,9 @@
 import org.apache.catalina.core.StandardHost;
 import org.apache.catalina.util.StringManager;
 import org.apache.commons.digester.Digester;
+import org.apache.commons.digester.Substitutor;
+import org.apache.commons.digester.substitution.VariableSubstitutor;
+import org.apache.commons.digester.substitution.MultiVariableExpander;
 
 
 /**
@@ -486,6 +490,23 @@
 
 
     /**
+     * Adds a substitutor to interpolate system properties
+     *
+     * @param digester The digester to which we add the substitutor
+     */
+    protected void enableDigesterSubstitutor(Digester digester)
+    {
+        Map systemProperties = System.getProperties();
+        MultiVariableExpander expander = new MultiVariableExpander();
+        expander.addSource("$", systemProperties);
+
+        // allow expansion in both xml attributes and element text
+        Substitutor substitutor = new VariableSubstitutor(expander);
+        digester.setSubstitutor(substitutor);
+    }
+
+
+    /**
      * Create (if necessary) and return a Digester configured to process the
      * context configuration descriptor for an application.
      */
@@ -494,6 +515,8 @@
         if (digester == null) {
             digester = new Digester();
             digester.setValidating(false);
+            // Add a substitutor to resolve system properties
+            enableDigesterSubstitutor(digester);
             digester.addRuleSet(new ContextRuleSet(""));
             digester.addRuleSet(new NamingRuleSet("Context/"));
         }

Modified: tomcat/current/tc4.1.x/STATUS.txt
URL: 
http://svn.apache.org/viewvc/tomcat/current/tc4.1.x/STATUS.txt?rev=620173&r1=620172&r2=620173&view=diff
==============================================================================
--- tomcat/current/tc4.1.x/STATUS.txt (original)
+++ tomcat/current/tc4.1.x/STATUS.txt Sat Feb  9 10:45:05 2008
@@ -25,10 +25,3 @@
 PATCHES PROPOSED TO BACKPORT:
   [ New proposals should be added at the end of the list ]
 
-* Add feature to use system properties in server.xml.
-  TC 5.0/5.5/6.0 already can do this, and since commons-digester
-  in TC 4.1 is recent enough, it's easy for TC 4.1 to.
-  
http://people.apache.org/~rjung/patches/replace_system_properties_20071018a.patch
-  +1: rjung, yoavs, markt, jim
-  -1:
-   0: I'd stick with serious bugs and security fixes for a release like this, 
not sure we should support new features, and the bugs they could generate



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to