org.apache.commons.configuration2.convert

## Class LegacyListDelimiterHandler

- java.lang.Object
- - org.apache.commons.configuration2.convert.AbstractListDelimiterHandler
  - - org.apache.commons.configuration2.convert.LegacyListDelimiterHandler

- All Implemented Interfaces:
    ListDelimiterHandler

      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.

  Since:
    2.0

- - ### Field Summary

    - ### Fields inherited from interface org.apache.commons.configuration2.convert.ListDelimiterHandler

      `NOOP_TRANSFORMER`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `LegacyListDelimiterHandler(char listDelimiter)` Creates a new instance of `LegacyListDelimiterHandler` and sets the list delimiter character.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    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.

    - ### 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`

- - ### Constructor Detail

    - #### LegacyListDelimiterHandler

          public LegacyListDelimiterHandler(char listDelimiter)

      Creates a new instance of `LegacyListDelimiterHandler` and sets the list delimiter character.
      Parameters:
        `listDelimiter` - the list delimiter character

  - ### Method Detail

    - #### getDelimiter

          public char getDelimiter()

      Returns the list delimiter character.
      Returns:
        the list delimiter character

    - #### escape

          public Object escape(Object value,
                               ValueTransformer transformer)

      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 to `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).
      Specified by:
        `escape` in interface `ListDelimiterHandler`
      Overrides:
        `escape` in class `AbstractListDelimiterHandler`
      Parameters:
        `value` - the value to be escaped
        `transformer` - a `ValueTransformer` for an additional encoding (must not be null)
      Returns:
        the escaped value

    - #### escapeList

          public Object escapeList(List<?> values,
                                   ValueTransformer transformer)

      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 value
        `transformer` - a `ValueTransformer` for an additional encoding (must not be null)
      Returns:
        the resulting escaped value

    - #### splitString

          protected Collection<String> splitString(String s,
                                                   boolean trim)

      Actually splits the passed in string which is guaranteed to be not null. This method is called by the base implementation of the `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.
      Specified by:
        `splitString` in class `AbstractListDelimiterHandler`
      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

    - #### escapeString

          protected String escapeString(String s)

      Escapes the specified string. This method is called by `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.
      Specified by:
        `escapeString` in class `AbstractListDelimiterHandler`
      Parameters:
        `s` - the string to be escaped (not null)
      Returns:
        the escaped string

    - #### escapeBackslashs

          protected String escapeBackslashs(Object value,
                                            boolean inList)

      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 by `escapeValue()`.
      Parameters:
        `value` - the value to be escaped
        `inList` - a flag whether the value is part of a list
      Returns:
        the value with escaped backslashes as string

    - #### escapeValue

          protected String escapeValue(Object value,
                                       boolean inList,
                                       ValueTransformer transformer)

      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 value
        `inList` - a flag whether the value is part of a list
        `transformer` - the `ValueTransformer`
      Returns:
        the escaped property value

Copyright © 2001–2022 The Apache Software Foundation. All rights reserved.