public static String nameEncode ( String value ) { if ( value == null ) return null ; // make buffer roomy StringBuilder encodedValue = new StringBuilder ( value . length ( ) * 2 ) ; int length = value . length ( ) ; int last = length - 1 ; for ( int i = 0 ; i < length ; i ++ ) { char c = value . charAt ( i ) ; // space first or last if ( c == ' ' && ( i == 0 || i == last ) ) { encodedValue . append ( "\\ " ) ; continue ; } if ( c < NAME_ESCAPE_TABLE . length ) { // check in table for escapes String esc = NAME_ESCAPE_TABLE [ c ] ; if ( esc != null ) { encodedValue . append ( esc ) ; continue ; } } // default: add the char encodedValue . append ( c ) ; } return encodedValue . toString ( ) ; }
LDAP Encodes a value for use with a DN . Escapes for LDAP not JNDI!