public class DefaultListDelimiterHandler extends AbstractListDelimiterHandler
The default implementation of the
This class supports list splitting and delimiter escaping using a delimiter
character that can be specified when constructing an instance. Splitting of
strings works by scanning the input for the list delimiter character. The
list delimiter character can be escaped by a backslash. So, provided that a
comma is configured as list delimiter, in the example
three values are recognized. In
3\,1415 the list delimiter is escaped
so that only a single element is detected. (Note that when writing these
examples in Java code, each backslash has to be doubled. This is also true
for all other examples in this documentation.)
Because the backslash has a special meaning as escaping character it is
always treated in a special way. If it occurs as a normal character in a
property value, it has to be escaped using another backslash (similar to the
rules of the Java programming language). The following example shows the
correct way to define windows network shares:
that each backslash is doubled. When combining the list delimiter with
backslashes the same escaping rules apply. For instance, in
C:\\Temp\\,D:\\data\\ the list delimiter is recognized; it is not
escaped by the preceding backslash because this backslash is itself escaped.
C:\\Temp\\\,D:\\data\\ defines a single element with a
comma being part of the value; two backslashes after
Temp result in a
single one, the third backslash escapes the list delimiter.
As can be seen, there are some constellations which are a bit tricky and cause a larger number of backslashes in sequence. Nevertheless, the escaping rules are consistent and do not cause ambiguous results.
Implementation node: An instance of this class can safely be shared between
|Constructor and Description|
Creates a new instance of
|Modifier and Type||Method and Description|
Escapes all values in the given list and concatenates them to a single string.
Escapes the specified string.
Returns the list delimiter character used by this instance.
Actually splits the passed in string which is guaranteed to be not null.
escape, parse, split
public DefaultListDelimiterHandler(char listDelimiter)
DefaultListDelimiterHandlerand sets the list delimiter character.
listDelimiter- the list delimiter character
public char getDelimiter()
public Object escapeList(List<?> values, ValueTransformer transformer)
values- the list with all the values to be converted to a single value
ValueTransformerfor an additional encoding (must not be null)
protected 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.
protected Collection<String> splitString(String s, boolean trim)
split()method. Here the actual splitting logic has to be implemented. This implementation reverses the escaping done by the
escape()methods of this class. However, it tries to be tolerant with unexpected escaping sequences: If after the escape character "\" no allowed character follows, both the backslash and the following character are output.
Copyright © 2001–2019 The Apache Software Foundation. All rights reserved.