View | Details | Raw Unified | Return to bug 61345
Collapse All | Expand All

(-)java/org/apache/tomcat/util/digester/Digester.java (+34 lines)
Lines 29-40 Link Here
29
import java.util.HashMap;
29
import java.util.HashMap;
30
import java.util.List;
30
import java.util.List;
31
import java.util.Map;
31
import java.util.Map;
32
import java.util.Properties;
32
import java.util.PropertyPermission;
33
import java.util.PropertyPermission;
34
import java.util.Set;
33
35
34
import javax.xml.parsers.ParserConfigurationException;
36
import javax.xml.parsers.ParserConfigurationException;
35
import javax.xml.parsers.SAXParser;
37
import javax.xml.parsers.SAXParser;
36
import javax.xml.parsers.SAXParserFactory;
38
import javax.xml.parsers.SAXParserFactory;
37
39
40
import org.apache.catalina.Lifecycle;
41
import org.apache.catalina.LifecycleEvent;
42
import org.apache.catalina.LifecycleListener;
38
import org.apache.juli.logging.Log;
43
import org.apache.juli.logging.Log;
39
import org.apache.juli.logging.LogFactory;
44
import org.apache.juli.logging.LogFactory;
40
import org.apache.tomcat.util.ExceptionUtils;
45
import org.apache.tomcat.util.ExceptionUtils;
Lines 308-313 Link Here
308
    }
313
    }
309
314
310
315
316
    public static class SystemPropertyReplacementListener
317
            implements LifecycleListener {
318
        protected Log log = LogFactory.getLog(Digester.class);
319
        protected StringManager sm = StringManager.getManager(Digester.class);
320
        @Override
321
        public void lifecycleEvent(LifecycleEvent event) {
322
            if (propertySource != null && Lifecycle.BEFORE_INIT_EVENT.equals(event.getType())) {
323
                IntrospectionUtils.PropertySource[] propertySources =
324
                        new IntrospectionUtils.PropertySource[] { propertySource };
325
                Properties properties = System.getProperties();
326
                Set<String> names = properties.stringPropertyNames();
327
                for (String name : names) {
328
                    String value = System.getProperty(name);
329
                    if (value != null) {
330
                        try {
331
                            String newValue = IntrospectionUtils.replaceProperties(value, null, propertySources);
332
                            if (value != newValue) {
333
                                System.setProperty(name, newValue);
334
                            }
335
                        } catch (Exception e) {
336
                            log.warn(sm.getString("digester.failedToUpdateSystemProperty", name, value), e);
337
                        }
338
                    }
339
                }
340
            }
341
        }
342
    }
343
344
311
    // ------------------------------------------------------------- Properties
345
    // ------------------------------------------------------------- Properties
312
346
313
    /**
347
    /**
(-)webapps/docs/config/systemprops.xml (+4 lines)
Lines 45-50 Link Here
45
         Required to have a public constructor with no arguments.</p>
45
         Required to have a public constructor with no arguments.</p>
46
      <p>Use this to add a property source, that will be invoked when <code>${parameter}</code>
46
      <p>Use this to add a property source, that will be invoked when <code>${parameter}</code>
47
         denoted parameters are found in the XML files that Tomcat parses.</p>
47
         denoted parameters are found in the XML files that Tomcat parses.</p>
48
      <p>Property replacement from the specified property source on the JVM
49
         system properties can also be done by adding the
50
         <code>org.apache.tomcat.util.digester.Digester$SystemPropertyReplacementListener</code>
51
         listener as a Server listener in the container.</p>
48
    </property>
52
    </property>
49
  </properties>
53
  </properties>
50
54
(-)java/org/apache/tomcat/util/digester/LocalStrings.properties (+1 lines)
Lines 15-17 Link Here
15
15
16
disgester.encodingInvalid=The encoding [{0}] is not recognised by the JRE and will be ignored
16
disgester.encodingInvalid=The encoding [{0}] is not recognised by the JRE and will be ignored
17
digester.failedToUpdateAttributes=Attribute [{0}] failed to update and remains [{1}]
17
digester.failedToUpdateAttributes=Attribute [{0}] failed to update and remains [{1}]
18
digester.failedToUpdateSystemProperty=System property [{0}] failed to update and remains [{1}]

Return to bug 61345