--- java/org/apache/tomcat/util/digester/Digester.java (revision 1803027) +++ java/org/apache/tomcat/util/digester/Digester.java (working copy) @@ -29,12 +29,17 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Properties; import java.util.PropertyPermission; +import java.util.Set; import javax.xml.parsers.ParserConfigurationException; import javax.xml.parsers.SAXParser; import javax.xml.parsers.SAXParserFactory; +import org.apache.catalina.Lifecycle; +import org.apache.catalina.LifecycleEvent; +import org.apache.catalina.LifecycleListener; import org.apache.juli.logging.Log; import org.apache.juli.logging.LogFactory; import org.apache.tomcat.util.ExceptionUtils; @@ -308,6 +313,35 @@ } + public static class SystemPropertyReplacementListener + implements LifecycleListener { + protected Log log = LogFactory.getLog(Digester.class); + protected StringManager sm = StringManager.getManager(Digester.class); + @Override + public void lifecycleEvent(LifecycleEvent event) { + if (propertySource != null && Lifecycle.BEFORE_INIT_EVENT.equals(event.getType())) { + IntrospectionUtils.PropertySource[] propertySources = + new IntrospectionUtils.PropertySource[] { propertySource }; + Properties properties = System.getProperties(); + Set names = properties.stringPropertyNames(); + for (String name : names) { + String value = System.getProperty(name); + if (value != null) { + try { + String newValue = IntrospectionUtils.replaceProperties(value, null, propertySources); + if (value != newValue) { + System.setProperty(name, newValue); + } + } catch (Exception e) { + log.warn(sm.getString("digester.failedToUpdateSystemProperty", name, value), e); + } + } + } + } + } + } + + // ------------------------------------------------------------- Properties /** --- webapps/docs/config/systemprops.xml (revision 1803027) +++ webapps/docs/config/systemprops.xml (working copy) @@ -45,6 +45,10 @@ Required to have a public constructor with no arguments.

Use this to add a property source, that will be invoked when ${parameter} denoted parameters are found in the XML files that Tomcat parses.

+

Property replacement from the specified property source on the JVM + system properties can also be done by adding the + org.apache.tomcat.util.digester.Digester$SystemPropertyReplacementListener + listener as a Server listener in the container.

--- java/org/apache/tomcat/util/digester/LocalStrings.properties (revision 1803027) +++ java/org/apache/tomcat/util/digester/LocalStrings.properties (working copy) @@ -15,3 +15,4 @@ disgester.encodingInvalid=The encoding [{0}] is not recognised by the JRE and will be ignored digester.failedToUpdateAttributes=Attribute [{0}] failed to update and remains [{1}] +digester.failedToUpdateSystemProperty=System property [{0}] failed to update and remains [{1}]