NIHVIVO-1942 when loading the deploy.properties file, strip any trailing whitespace from the properties.

This commit is contained in:
jeb228 2011-01-28 16:08:56 +00:00
parent 5a84820263
commit 8894597e7e
3 changed files with 11 additions and 2 deletions

View file

@ -35,6 +35,9 @@ import org.apache.commons.logging.LogFactory;
* to a value like <code>/usr/local/vitro/stuff/deploy.properties</code> for a * to a value like <code>/usr/local/vitro/stuff/deploy.properties</code> for a
* file, or like <code>deploy.properties</code> for a resource in the classpath. * file, or like <code>deploy.properties</code> for a resource in the classpath.
* *
* When the properties file is loaded, the values are trimmed to remove leading
* or trailing white space, since such white space is almost always an error.
*
* @author jeb228 * @author jeb228
*/ */
public class ConfigurationProperties { public class ConfigurationProperties {
@ -144,7 +147,10 @@ public class ConfigurationProperties {
Map<String, String> newMap = new HashMap<String, String>(); Map<String, String> newMap = new HashMap<String, String>();
for (Enumeration<?> keys = props.keys(); keys.hasMoreElements();) { for (Enumeration<?> keys = props.keys(); keys.hasMoreElements();) {
String key = (String) keys.nextElement(); String key = (String) keys.nextElement();
newMap.put(key, props.getProperty(key)); String value = props.getProperty(key);
// While we're copying, remove leading and trailing white space.
String trimmed = value.trim();
newMap.put(key, trimmed);
} }
log.info("Configuration properties are: " + newMap); log.info("Configuration properties are: " + newMap);

View file

@ -47,7 +47,7 @@ public class ConfigurationPropertiesTest extends AbstractTestClass {
* The mappings that we might find from the property files. * The mappings that we might find from the property files.
*/ */
private static final String[][] MAP_VALUES_DEFAULT = new String[][] { { private static final String[][] MAP_VALUES_DEFAULT = new String[][] { {
"whichfile", "test_config_default" } }; "whichfile", "test_config_default" }, {"trimmed", "whitespace_test"} };
private static final String[][] MAP_VALUES_CONFIGURED = new String[][] { { private static final String[][] MAP_VALUES_CONFIGURED = new String[][] { {
"whichfile", "test_config" } }; "whichfile", "test_config" } };

View file

@ -2,3 +2,6 @@
# This is a data file for ConfigurationPropertiesTest. # This is a data file for ConfigurationPropertiesTest.
# #
whichfile = test_config_default whichfile = test_config_default
# This ends with a blank, in order to test the removal of whitespace
trimmed = whitespace_test\u0020