How about javax.naming.ldap.LdapName
?
String dn = "CN=Jimmy Blooptoop,OU=Someplace,OU=Employees,DC=Bloopsoft-Inc";
LdapName ln = new LdapName(dn);
for(Rdn rdn : ln.getRdns()) {
if(rdn.getType().equalsIgnoreCase("CN")) {
System.err.println("CN is: " + rdn.getValue());
break;
}
}
It's not the most beautiful interface since there is something missing like LdapName#getByType(String)
but it saves you the trouble of having to think about what strange features DNs might have.