From 9bda4109c822999212425fba5f7cd539ec952806 Mon Sep 17 00:00:00 2001 From: idfx Date: Fri, 28 Feb 2003 18:15:55 +0000 Subject: [PATCH] Now there is a way to set default-values for non-existing properties --- source/mir/config/MirPropertiesConfiguration.java | 49 +++++++++++++++++------ 1 file changed, 36 insertions(+), 13 deletions(-) diff --git a/source/mir/config/MirPropertiesConfiguration.java b/source/mir/config/MirPropertiesConfiguration.java index 56f1bb24..2d618e0e 100755 --- a/source/mir/config/MirPropertiesConfiguration.java +++ b/source/mir/config/MirPropertiesConfiguration.java @@ -55,17 +55,17 @@ public class MirPropertiesConfiguration extends PropertiesConfiguration { private static String contextPath; //if one of these properties is not present a new - //emtpy property is added - private String[] needed = + //property is added with its default value; + private static NeededProperty[] neededWithValue = { - "Producer.DocRoot", "Producer.ImageRoot", "Producer.Image.Path", - "Producer.Media.Path", "Producer.RealMedia.Path", "Producer.Image.IconPath" + new NeededProperty("Producer.DocRoot",""), + new NeededProperty("Producer.ImageRoot",""), + new NeededProperty("Producer.Image.Path",""), + new NeededProperty("Producer.Media.Path",""), + new NeededProperty("Producer.RealMedia.Path",""), + new NeededProperty("Producer.Image.IconPath","") }; - //if one of these properties is not present a new - //emtpy property is added - private String[] neededWithValue = { "" }; - /** * Constructor for MirPropertiesConfiguration. */ @@ -154,11 +154,11 @@ public class MirPropertiesConfiguration extends PropertiesConfiguration { * Checks if one property is missing and adds a default value */ private void checkMissing() { - for (int i = 0; i < needed.length; i++) { - if (super.getProperty(needed[i]) == null) { - addProperty(needed[i], ""); - } - } + for (int i = 0; i < neededWithValue.length; i++) { + if (super.getProperty(neededWithValue[i].getKey()) == null) { + addProperty(neededWithValue[i].getKey(), neededWithValue[i].getValue()); + } + } } public File getFile(String key) throws FileNotFoundException { @@ -218,5 +218,28 @@ public class MirPropertiesConfiguration extends PropertiesConfiguration { public PropertiesConfigFailure(String msg, Throwable cause) { super(msg, cause); } + } + + /** + * A Class for properties to be checked + * @author idefix + */ + private static class NeededProperty { + private String _key; + private String _value; + + public NeededProperty(String key, String value) { + _key = key; + _value = value; + } + + public String getKey() { + return _key; + } + + public String getValue() { + return _value; + } + } } -- 2.11.0