org.springframework.ldap.support

## Class LdapEncoder

- java.lang.Object
- - org.springframework.ldap.support.LdapEncoder

-     public final class LdapEncoder
      extends Object

  Helper class to encode and decode ldap names and values.
  Author:
    Adam Skogman, Mattias Hellborg Arthursson, Thomas Darimont

- - ### Method Summary

    All Methods Static Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `static String` | `filterEncode(String value)` Escape a value for use in a filter.
    `static String` | `nameDecode(String value)` Decodes a value.
    `static String` | `nameEncode(String value)` LDAP Encodes a value for use with a DN.
    `static byte[]` | `parseBase64Binary(String val)` Converts the Base64 encoded string argument into an array of bytes.
    `static String` | `printBase64Binary(byte[] val)` Converts an array of bytes into a Base64 encoded string according to the rules for converting LDAP Attributes in RFC2849.
    `protected static String` | `toTwoCharHex(char c)`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Method Detail

    - #### toTwoCharHex

          protected static String toTwoCharHex(char c)

    - #### filterEncode

          public static String filterEncode(String value)

      Escape a value for use in a filter.
      Parameters:
        `value` - the value to escape.
      Returns:
        a properly escaped representation of the supplied value.

    - #### nameEncode

          public static String nameEncode(String value)

      LDAP Encodes a value for use with a DN. Escapes for LDAP, not JNDI!
      Escapes:
      ' ' [space] - "\ " [if first or last]
      '#' [hash] - "\#"
      ',' [comma] - "\,"
      ';' [semicolon] - "\;"
      '= [equals] - "\="
      '+' [plus] - "\+"
      '<' [less than] - "\<"
      '>' [greater than] - "\>"
      '"' [double quote] - "\""
      '\' [backslash] - "\\"
      Parameters:
        `value` - the value to escape.
      Returns:
        The escaped value.

    - #### nameDecode

          public static String nameDecode(String value)
                                   throws BadLdapGrammarException

      Decodes a value. Converts escaped chars to ordinary chars.
      Parameters:
        `value` - Trimmed value, so no leading an trailing blanks, except an escaped space last.
      Returns:
        The decoded value as a string.
      Throws:
        `BadLdapGrammarException`

    - #### printBase64Binary

          public static String printBase64Binary(byte[] val)

      Converts an array of bytes into a Base64 encoded string according to the rules for converting LDAP Attributes in RFC2849.
      Parameters:
        `val` -
      Returns:
        A string containing a lexical representation of base64Binary wrapped around 76 characters.
      Throws:
        `IllegalArgumentException` - if `val` is null.

    - #### parseBase64Binary

          public static byte[] parseBase64Binary(String val)

      Converts the Base64 encoded string argument into an array of bytes.
      Parameters:
        `val` -
      Returns:
        An array of bytes represented by the string argument.
      Throws:
        `IllegalArgumentException` - if `val` is null or does not conform to lexical value space defined in XML Schema Part 2: Datatypes for xsd:base64Binary.