public class LegacyListDelimiterHandler extends AbstractListDelimiterHandler
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.
NOOP_TRANSFORMER
Constructor and Description |
---|
LegacyListDelimiterHandler(char listDelimiter)
Creates a new instance of
LegacyListDelimiterHandler and sets the list delimiter character. |
Modifier and Type | Method and Description |
---|---|
Object |
escape(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.
|
Object |
escapeList(List<?> values,
ValueTransformer transformer)
Escapes all values in the given list and concatenates them to a single string.
|
protected String |
escapeString(String s)
Escapes the specified string.
|
protected String |
escapeValue(Object value,
boolean inList,
ValueTransformer transformer)
Escapes the given property value.
|
char |
getDelimiter()
Returns 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.
|
parse, split
public LegacyListDelimiterHandler(char listDelimiter)
LegacyListDelimiterHandler
and sets the list delimiter character.listDelimiter
- the list delimiter characterpublic char getDelimiter()
public Object escape(Object value, ValueTransformer transformer)
AbstractListDelimiterHandler.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).escape
in interface ListDelimiterHandler
escape
in class AbstractListDelimiterHandler
value
- the value to be escapedtransformer
- a ValueTransformer
for an additional encoding (must not be null)public Object escapeList(List<?> values, ValueTransformer transformer)
values
- the list with all the values to be converted to a single valuetransformer
- a ValueTransformer
for an additional encoding (must not be null)protected Collection<String> splitString(String s, boolean trim)
split()
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.splitString
in class AbstractListDelimiterHandler
s
- the string to be split (not null)trim
- a flag whether the single components have to be trimmedprotected String escapeString(String s)
escape()
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.escapeString
in class AbstractListDelimiterHandler
s
- the string to be escaped (not null)protected String escapeBackslashs(Object value, boolean inList)
escapeValue()
.value
- the value to be escapedinList
- a flag whether the value is part of a listprotected String escapeValue(Object value, boolean inList, ValueTransformer transformer)
value
- the property valueinList
- a flag whether the value is part of a listtransformer
- the ValueTransformer
Copyright © 2001–2022 The Apache Software Foundation. All rights reserved.