diff --git a/Frameworks/Core/ERExtensions/Sources/er/extensions/foundation/ERXProperties.java b/Frameworks/Core/ERExtensions/Sources/er/extensions/foundation/ERXProperties.java index f4b47b38faa..63351d2a042 100644 --- a/Frameworks/Core/ERExtensions/Sources/er/extensions/foundation/ERXProperties.java +++ b/Frameworks/Core/ERExtensions/Sources/er/extensions/foundation/ERXProperties.java @@ -1110,7 +1110,46 @@ public static NSArray componentsSeparatedByStringWithDefault(String key, } return array; } - + + /** + * Returns an enum value for a given enum class and system property. If the property is not + * set or matches no enum constant, null will be returned. The search for the + * enum value is case insensitive, i.e. a property value "foo" will match the enum constant + * FOO. + * + * @param enumClass the enum class + * @param key the property key + * @return the enum value + */ + public static T enumValueForKey(Class enumClass, String key) { + return enumValueForKeyWithDefault(enumClass, key, null); + } + + /** + * Returns an enum value for a given enum class and system property. If the property is not + * set or matches no enum constant, the specified default value will be returned. The + * search for the enum value is case insensitive, i.e. a property value "foo" will match + * the enum constant FOO. + * + * @param enumClass the enum class + * @param key the property key + * @param defaultValue the default value + * @return the enum value + */ + public static T enumValueForKeyWithDefault(Class enumClass, String key, T defaultValue) { + T result = defaultValue; + String stringValue = stringForKey(key); + if (stringValue != null) { + for (T enumValue : enumClass.getEnumConstants()) { + if (enumValue.name().equalsIgnoreCase(stringValue)) { + result = enumValue; + break; + } + } + } + return result; + } + /** *
* Sets an array in the System properties for