Class LegacyListDelimiterHandler
- All Implemented Interfaces:
ListDelimiterHandler
A specialized implementation of ListDelimiterHandler
which simulates the list delimiter handling as it was
used by PropertiesConfiguration
in Commons Configuration 1.x.
This class mainly exists for compatibility reasons. It is intended to be used by applications which have to deal with properties files created by an older version of this library.
In the 1.x series of Commons Configuration list handling was not fully consistent. The escaping of property values
was done in a different way if they contained a list delimiter or not. From version 2.0 on, escaping is more
stringent which might cause slightly different results when parsing properties files created by or for Configuration
1.x. If you encounter such problems, you can switch to this ListDelimiterHandler
implementation rather than
the default one. In other cases, this class should not be used!
Implementation note: An instance of this class can safely be shared between multiple Configuration
instances.
- Since:
- 2.0
-
Field Summary
Fields inherited from interface org.apache.commons.configuration2.convert.ListDelimiterHandler
NOOP_TRANSFORMER
-
Constructor Summary
ConstructorDescriptionLegacyListDelimiterHandler
(char listDelimiter) Creates a new instance ofLegacyListDelimiterHandler
and sets the list delimiter character. -
Method Summary
Modifier and TypeMethodDescriptionescape
(Object value, ValueTransformer transformer) Escapes the specified single value object.protected String
escapeBackslashs
(Object value, boolean inList) Performs the escaping of backslashes in the specified properties value.escapeList
(List<?> values, ValueTransformer transformer) Escapes all values in the given list and concatenates them to a single string.protected String
Escapes the specified string.protected String
escapeValue
(Object value, boolean inList, ValueTransformer transformer) Escapes the given property value.char
Gets the list delimiter character.protected Collection<String>
splitString
(String s, boolean trim) Actually splits the passed in string which is guaranteed to be not null.Methods inherited from class org.apache.commons.configuration2.convert.AbstractListDelimiterHandler
parse, split
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.apache.commons.configuration2.convert.ListDelimiterHandler
flatten
-
Constructor Details
-
LegacyListDelimiterHandler
Creates a new instance ofLegacyListDelimiterHandler
and sets the list delimiter character.- Parameters:
listDelimiter
- the list delimiter character
-
-
Method Details
-
escape
Escapes the specified single value object. This method is called for properties containing only a single value. So this method can rely on the fact that the passed in object is not a list. An implementation has to check whether the value contains list delimiter characters and - if so - escape them accordingly. This implementation checks whether the object to be escaped is a string. If yes, it delegates toAbstractListDelimiterHandler.escapeString(String)
, otherwise no escaping is performed. Eventually, the passed in transformer is invoked so that additional encoding can be performed. This implementation performs delimiter escaping for a single value (which is not part of a list).- Specified by:
escape
in interfaceListDelimiterHandler
- Overrides:
escape
in classAbstractListDelimiterHandler
- Parameters:
value
- the value to be escapedtransformer
- aValueTransformer
for an additional encoding (must not be null)- Returns:
- the escaped value
-
escapeBackslashs
Performs the escaping of backslashes in the specified properties value. Because a double backslash is used to escape the escape character of a list delimiter, double backslashes also have to be escaped if the property is part of a (single line) list. In addition, because the output is written into a properties file, each occurrence of a backslash again has to be doubled. This method is called byescapeValue()
.- Parameters:
value
- the value to be escapedinList
- a flag whether the value is part of a list- Returns:
- the value with escaped backslashes as string
-
escapeList
Escapes all values in the given list and concatenates them to a single string. This operation is required by configurations that have to represent properties with multiple values in a single line in their external configuration representation. This may require an advanced escaping in some cases. This implementation performs a special encoding of backslashes at the end of a string so that they are not interpreted as escape character for a following list delimiter.- Parameters:
values
- the list with all the values to be converted to a single valuetransformer
- aValueTransformer
for an additional encoding (must not be null)- Returns:
- the resulting escaped value
-
escapeString
Escapes the specified string. This method is called byescape()
if the passed in object is a string. Concrete subclasses have to implement their specific escaping logic here, so that the list delimiters they support are properly escaped. This is just a dummy implementation. It is never called.- Specified by:
escapeString
in classAbstractListDelimiterHandler
- Parameters:
s
- the string to be escaped (not null)- Returns:
- the escaped string
-
escapeValue
Escapes the given property value. This method is called on saving the configuration for each property value. It ensures a correct handling of backslash characters and also takes care that list delimiter characters in the value are escaped.- Parameters:
value
- the property valueinList
- a flag whether the value is part of a listtransformer
- theValueTransformer
- Returns:
- the escaped property value
-
getDelimiter
Gets the list delimiter character.- Returns:
- the list delimiter character
-
splitString
Actually splits the passed in string which is guaranteed to be not null. This method is called by the base implementation of thesplit()
method. Here the actual splitting logic has to be implemented. This implementation simulates the old splitting algorithm. The string is split at the delimiter character if it is not escaped. If the delimiter character is not found, the input is returned unchanged.- Specified by:
splitString
in classAbstractListDelimiterHandler
- Parameters:
s
- the string to be split (not null)trim
- a flag whether the single components have to be trimmed- Returns:
- a collection with the extracted components of the passed in string
-