Spring LDAP

org.springframework.ldap.core
Class LdapEncoder

java.lang.Object
  extended by org.springframework.ldap.core.LdapEncoder

public class LdapEncoder
extends Object

Helper class to encode and decode ldap names and values.

Author:
Adam Skogman, Mattias Hellborg Arthursson

Method Summary
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.
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

Spring LDAP