From cf4f6755c8cc81b4a545bf65db5be66e59798fed Mon Sep 17 00:00:00 2001 From: felmer <felmer> Date: Thu, 17 Apr 2008 11:57:28 +0000 Subject: [PATCH] LMS-335 add a utility method SVN: 5659 --- .../cisd/common/utilities/PropertyUtils.java | 26 ++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/common/source/java/ch/systemsx/cisd/common/utilities/PropertyUtils.java b/common/source/java/ch/systemsx/cisd/common/utilities/PropertyUtils.java index fef27ebbd7a..d160ccb2638 100644 --- a/common/source/java/ch/systemsx/cisd/common/utilities/PropertyUtils.java +++ b/common/source/java/ch/systemsx/cisd/common/utilities/PropertyUtils.java @@ -83,7 +83,31 @@ public final class PropertyUtils } return property; } - + + /** + * Returns a certain property from the specified properties. + * + * @return the property value without leading and trailing white spaces. + * @throws ConfigurationFailureException if no property found or the result would be an empty + * string. + */ + public static String getProperty(Properties properties, String propertyKey) + throws ConfigurationFailureException + { + assertParameters(properties, propertyKey); + String property = properties.getProperty(propertyKey); + if (property == null) + { + throw new ConfigurationFailureException("Unspecified property '" + propertyKey + "'."); + } + property = property.trim(); + if (property.length() == 0) + { + throw new ConfigurationFailureException("Property '" + propertyKey + + "' is an empty string."); + } + return property; + } /** * Looks up given <var>propertyKey</var> in given <var>properties</var>. * -- GitLab