From a905c29b323ea95da645bfc4f1c2ba1d21305edb Mon Sep 17 00:00:00 2001 From: idfx Date: Thu, 13 Mar 2003 22:02:25 +0000 Subject: [PATCH] a bit nicer --- source/mir/config/MirPropertiesConfiguration.java | 40 ++++++++++++++++------- 1 file changed, 28 insertions(+), 12 deletions(-) diff --git a/source/mir/config/MirPropertiesConfiguration.java b/source/mir/config/MirPropertiesConfiguration.java index 52c3fc10..9c2c020c 100755 --- a/source/mir/config/MirPropertiesConfiguration.java +++ b/source/mir/config/MirPropertiesConfiguration.java @@ -34,7 +34,6 @@ import multex.Exc; import multex.Failure; import org.apache.commons.collections.ExtendedProperties; -import org.apache.commons.configuration.PropertiesConfiguration; import java.io.File; import java.io.FileNotFoundException; @@ -173,22 +172,39 @@ public class MirPropertiesConfiguration extends ExtendedProperties { } /** + * @return the vlaue of this property as String + * @param key the key of this property * @see org.apache.commons.configuration.Configuration#getString(java.lang.String) */ public String getString(String key) { - Object object = getProperty(key); - if(object != null){ - if (object instanceof String) { - return (String)object; - } else { - return object.toString(); - } - } else { - return new String(); - } + return getString(key, ""); + } + + + /** + * @return the value of this property as String + * @param key the key of the property + * @param defaultValue the default value of this property if it is null + * @see org.apache.commons.collections.ExtendedProperties#getString(java.lang.String, java.lang.String) + */ + public String getString(String key, String defaultValue) { + Object object = getProperty(key); + if(object == null){ + if (defaultValue == null) { + return new String(); + } + return defaultValue; + } + if (object instanceof String) { + return (String)object; + } + return object.toString(); } /** + * Returns a property according to the given key + * @param key the key of the property + * @return the value of the property as Object, if no property available it returns a empty String * @see org.apache.commons.configuration.Configuration#getString(java.lang.String) */ public Object getProperty(String key) { @@ -198,7 +214,7 @@ public class MirPropertiesConfiguration extends ExtendedProperties { return super.getProperty(key); } - + /** * @author idefix */ -- 2.11.0