Author: oheger Date: Sun Mar 17 17:42:51 2013 New Revision: 1457498 URL: http://svn.apache.org/r1457498 Log: [CONFIGURATION-534] Slightly reworked handling of include files in PropertiesConfiguration.
Include files are now enabled per default, even if no base path is set. Get and set methods for the includesAllowed property are now public and complient to JavaBeans conventions. Modified: commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/PropertiesConfiguration.java commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/TestPropertiesConfiguration.java Modified: commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/PropertiesConfiguration.java URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/PropertiesConfiguration.java?rev=1457498&r1=1457497&r2=1457498&view=diff ============================================================================== --- commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/PropertiesConfiguration.java (original) +++ commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/PropertiesConfiguration.java Sun Mar 17 17:42:51 2013 @@ -228,7 +228,7 @@ public class PropertiesConfiguration ext private volatile IOFactory ioFactory; /** Allow file inclusion or not */ - private boolean includesAllowed; + private boolean includesAllowed = true; /** * Creates an empty PropertyConfiguration object which can be @@ -238,7 +238,6 @@ public class PropertiesConfiguration ext public PropertiesConfiguration() { layout = createLayout(); - setIncludesAllowed(false); } /** @@ -310,12 +309,11 @@ public class PropertiesConfiguration ext /** * Controls whether additional files can be loaded by the include = <xxx> - * statement or not. Base rule is, that objects created by the empty - * C'tor can not have included files. + * statement or not. This is <b>true</b> per default. * - * @param includesAllowed includesAllowed True if Includes are allowed. + * @param includesAllowed True if Includes are allowed. */ - protected void setIncludesAllowed(boolean includesAllowed) + public void setIncludesAllowed(boolean includesAllowed) { this.includesAllowed = includesAllowed; } @@ -325,7 +323,7 @@ public class PropertiesConfiguration ext * * @return True if include files are loaded. */ - public boolean getIncludesAllowed() + public boolean isIncludesAllowed() { return this.includesAllowed; } @@ -587,7 +585,7 @@ public class PropertiesConfiguration ext if (StringUtils.isNotEmpty(getInclude()) && key.equalsIgnoreCase(getInclude())) { - if (getIncludesAllowed()) + if (isIncludesAllowed()) { String[] files; if (!isDelimiterParsingDisabled()) Modified: commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/TestPropertiesConfiguration.java URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/TestPropertiesConfiguration.java?rev=1457498&r1=1457497&r2=1457498&view=diff ============================================================================== --- commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/TestPropertiesConfiguration.java (original) +++ commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/TestPropertiesConfiguration.java Sun Mar 17 17:42:51 2013 @@ -156,6 +156,41 @@ public class TestPropertiesConfiguration assertEquals("true", loaded); } + /** + * Tests whether include files can be resolved if a configuration file is + * read from a reader. + */ + @Test + public void testLoadIncludeFromReader() throws ConfigurationException, + IOException + { + StringReader in = + new StringReader(PropertiesConfiguration.getInclude() + " = " + + ConfigurationAssert.getTestURL("include.properties")); + conf = new PropertiesConfiguration(); + conf.read(in); + assertEquals("Include file not loaded", "true", + conf.getString("include.loaded")); + } + + /** + * Tests whether include files can be disabled. + */ + @Test + public void testDisableIncludes() throws ConfigurationException, + IOException + { + String content = + PropertiesConfiguration.getInclude() + + " = nonExistingIncludeFile" + CR + PROP_NAME + " = " + + PROP_VALUE + CR; + StringReader in = new StringReader(content); + conf = new PropertiesConfiguration(); + conf.setIncludesAllowed(false); + conf.read(in); + assertEquals("Data not loaded", PROP_VALUE, conf.getString(PROP_NAME)); + } + @Test public void testSetInclude() throws Exception {