com.ca.commons.naming
Class NameUtility

java.lang.Object
  |
  +--com.ca.commons.naming.NameUtility

public class NameUtility
extends java.lang.Object

Some specialised String utilities for parsing ldap names.


Constructor Summary
NameUtility()
           
 
Method Summary
static java.lang.String checkEndSpaces(java.lang.String ldapDNString)
          Apparently jndi does not handle end spaces correctly.
protected static java.lang.String cleanupSlashes(java.lang.String string)
           
static java.lang.String escape(java.lang.String string)
          escapes special characters using a backslash, as per RFC 2253.
static int next(java.lang.String searchMe, int startpos, char c)
          return position of next non-escaped character 'c' in a DN.
static java.lang.String removeEscapedUTF(java.lang.String utfString)
           
static java.lang.String trimQuotes(java.lang.String string)
          Not currently used?
static java.lang.String unescape(java.lang.String string)
          A commutative twin to escape(), this removes the leading slashes from a string.
static java.lang.String unescape(java.lang.String string, boolean jndiHack)
          Removes the escaping.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

NameUtility

public NameUtility()
Method Detail

next

public static int next(java.lang.String searchMe,
                       int startpos,
                       char c)
return position of next non-escaped character 'c' in a DN. (i.e. character 'c' without a preceeding '\' character, or not in double quotes) (unless the char is a quote, in which case it isn't. um.). Note that by definition '\' cannot exist, unescaped, as a first class character and therefore this function will not find '\'s.


unescape

public static java.lang.String unescape(java.lang.String string)
                                 throws javax.naming.InvalidNameException
A commutative twin to escape(), this removes the leading slashes from a string.

javax.naming.InvalidNameException

removeEscapedUTF

public static java.lang.String removeEscapedUTF(java.lang.String utfString)
                                         throws javax.naming.InvalidNameException
javax.naming.InvalidNameException

unescape

public static java.lang.String unescape(java.lang.String string,
                                        boolean jndiHack)
                                 throws javax.naming.InvalidNameException
Removes the escaping. If jndiHack is false, this is roughly the opposite of escape (however multiple valid formats resolve to the same final unicode string). If jndiHack is true, it does special handling to cope with both version 2 ldap escapes, and the wonky return values for slashes given by jndi.

If used for DNs, The string argument should be the smallest possible unit of an rdn value.

If the argument has beginning and end quotes, they are removed, leaving text otherwise untouched (ldap v2 escaping).
Otherwise, remove all leading '\' characters, giving special handling to escaped slashes.

Note that in the second form this ftn is not commutative with escape.

Parameters:
string - the string to remove escape characters from
jndiHack - if true, indicates special handling for ldap v2 escaping, and wierd jndi return values.
javax.naming.InvalidNameException

trimQuotes

public static java.lang.String trimQuotes(java.lang.String string)
Not currently used?


cleanupSlashes

protected static java.lang.String cleanupSlashes(java.lang.String string)

escape

public static java.lang.String escape(java.lang.String string)
escapes special characters using a backslash, as per RFC 2253. IN ADDITION: escapes forward slash '/' characters for jndi

Parameters:
string - the string to convert to escaped form.

checkEndSpaces

public static java.lang.String checkEndSpaces(java.lang.String ldapDNString)
Apparently jndi does not handle end spaces correctly. This checks for the condition that the DN is illegal, with a dangling slash on the end, representing a DN with an end space mashed by jndi.

Parameters:
ldapDNString - the potentially illegal DN to rescue
Returns:
the corrected string (unchanged if no correcting required)