Class PropertyValues
- java.lang.Object
-
- org.jboss.logmanager.PropertyValues
-
public class PropertyValues extends Object
A utility for converting objects into strings and strings into objects for storage in logging configurations.- Author:
- James R. Perkins
-
-
Constructor Summary
Constructors Constructor Description PropertyValues()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static voidescapeKey(StringBuilder sb, String key)Escapes a maps key value for serialization to a string.static voidescapeValue(StringBuilder sb, String value)Escapes a maps value for serialization to a string.static <K extends Enum<K>>
StringmapToString(EnumMap<K,String> map)Converts a map into a string that can be parsed bystringToMap(String).static <K> StringmapToString(Map<K,String> map)Converts a map into a string that can be parsed bystringToMap(String).static <E extends Enum<E>>
EnumMap<E,String>stringToEnumMap(Class<E> enumType, String s)Parses a string of key/value pairs into an enum map.static <E extends Enum<E>>
EnumMap<E,String>stringToEnumMap(Class<E> enumType, String s, boolean convertKeyCase)Parses a string of key/value pairs into an enum map.static Map<String,String>stringToMap(String s)Parses a string of key/value pairs into a map.
-
-
-
Method Detail
-
stringToMap
public static Map<String,String> stringToMap(String s)
Parses a string of key/value pairs into a map.The key/value pairs are separated by a comma (
,). The key and value are separated by an equals (=).If a key contains a
\or an=it must be escaped by a preceding\. Example:key\==value,\\key=value.If a value contains a
\or a,it must be escaped by a preceding\. Example:key=part1\,part2,key2=value\\other.If the value for a key is empty there is no trailing
=after a key the will benull.- Parameters:
s- the string to parse- Returns:
- a map of the key value pairs or an empty map if the string is
nullor empty
-
stringToEnumMap
public static <E extends Enum<E>> EnumMap<E,String> stringToEnumMap(Class<E> enumType, String s)
Parses a string of key/value pairs into an enum map.The key/value pairs are separated by a comma (
,). The key and value are separated by an equals (=). The key must be a valid enum value. For convenience the case of each character will be converted to uppercase and any dashes (-) will be converted to underscores (_).If a value contains a
\or a,it must be escaped by a preceding\. Example:key=part1\,part2,key2=value\\other.If the value for a key is empty there is no trailing
=after a key the value will benull.- Parameters:
enumType- the enum types- the string to parse- Returns:
- a map of the key value pairs or an empty map if the string is
nullor empty
-
stringToEnumMap
public static <E extends Enum<E>> EnumMap<E,String> stringToEnumMap(Class<E> enumType, String s, boolean convertKeyCase)
Parses a string of key/value pairs into an enum map.The key/value pairs are separated by a comma (
,). The key and value are separated by an equals (=). The key must be a valid enum value. For convenience any dashes (-) will be converted to underscores (_). IfconvertKeyCaseis set totruethe case will also be converted to uppercase for each key character.If a value contains a
\or a,it must be escaped by a preceding\. Example:key=part1\,part2,key2=value\\other.If the value for a key is empty there is no trailing
=after a key the value will benull.- Parameters:
enumType- the enum types- the string to parseconvertKeyCase-trueif the each character from the key should be converted to uppercase, otherwisefalseto keep the case as is- Returns:
- a map of the key value pairs or an empty map if the string is
nullor empty
-
mapToString
public static <K> String mapToString(Map<K,String> map)
Converts a map into a string that can be parsed bystringToMap(String). Note that if this is anEnumMapthemapToString(EnumMap)will be used and the key will be the enum name.- Type Parameters:
K- the type of the key- Parameters:
map- the map to convert to a string- Returns:
- a string value for that map that can be used for configuration properties
- See Also:
escapeKey(StringBuilder, String),escapeValue(StringBuilder, String)
-
mapToString
public static <K extends Enum<K>> String mapToString(EnumMap<K,String> map)
Converts a map into a string that can be parsed bystringToMap(String). The kwy will be the enum name.- Type Parameters:
K- the type of the key- Parameters:
map- the map to convert to a string- Returns:
- a string value for that map that can be used for configuration properties
- See Also:
escapeKey(StringBuilder, String),escapeValue(StringBuilder, String)
-
escapeKey
public static void escapeKey(StringBuilder sb, String key)
Escapes a maps key value for serialization to a string. If the key contains a\or an=it will be escaped by a preceding\. Example:key\=or\\key.- Parameters:
sb- the string builder to append the escaped key tokey- the key
-
escapeValue
public static void escapeValue(StringBuilder sb, String value)
Escapes a maps value for serialization to a string. If a value contains a\or a,it will be escaped by a preceding\. Example:part1\,part2orvalue\\other.- Parameters:
sb- the string builder to append the escaped value tovalue- the value
-
-