You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by el...@apache.org on 2005/12/14 00:53:35 UTC
svn commit: r356652 -
/directory/shared/ldap/branches/DN-refactoring/common/src/main/java/org/apache/ldap/common/name/LdapDN.java
Author: elecharny
Date: Tue Dec 13 15:53:32 2005
New Revision: 356652
URL: http://svn.apache.org/viewcvs?rev=356652&view=rev
Log:
Added some constructors that take a List and an iterator
Modified:
directory/shared/ldap/branches/DN-refactoring/common/src/main/java/org/apache/ldap/common/name/LdapDN.java
Modified: directory/shared/ldap/branches/DN-refactoring/common/src/main/java/org/apache/ldap/common/name/LdapDN.java
URL: http://svn.apache.org/viewcvs/directory/shared/ldap/branches/DN-refactoring/common/src/main/java/org/apache/ldap/common/name/LdapDN.java?rev=356652&r1=356651&r2=356652&view=diff
==============================================================================
--- directory/shared/ldap/branches/DN-refactoring/common/src/main/java/org/apache/ldap/common/name/LdapDN.java (original)
+++ directory/shared/ldap/branches/DN-refactoring/common/src/main/java/org/apache/ldap/common/name/LdapDN.java Tue Dec 13 15:53:32 2005
@@ -135,6 +135,7 @@
import java.util.Enumeration;
import java.util.Iterator;
import java.util.List;
+import java.util.Map;
import java.util.NoSuchElementException;
import javax.naming.InvalidNameException;
@@ -196,6 +197,47 @@
}
/**
+ * Creates an ldap name using a list of NameComponents. Each NameComponent
+ * is a String
+ *
+ * @param a_list of String name components.
+ */
+ LdapDN( List list ) throws InvalidNameException
+ {
+ super();
+
+ if ( ( list != null ) && ( list.size() != 0 ) )
+ {
+ Iterator nameComponents = list.iterator();
+
+ while ( nameComponents.hasNext() )
+ {
+ String nameComponent = (String)nameComponents.next();
+ add( 0, nameComponent );
+ }
+ }
+ }
+
+ /**
+ * Creates an ldap name using a list of name components.
+ *
+ * @param nameComponents List of String name components.
+ */
+ LdapDN( Iterator nameComponents ) throws InvalidNameException
+ {
+ super();
+
+ if ( nameComponents != null )
+ {
+ while ( nameComponents.hasNext() )
+ {
+ String nameComponent = (String)nameComponents.next();
+ add( 0, nameComponent );
+ }
+ }
+ }
+
+ /**
* Parse a String and checks that it is a valid DN <br>
* <p>
* <distinguishedName> ::= <name> | e <br>
@@ -979,5 +1021,62 @@
{
return NOT_EQUALS;
}
+ }
+
+ public static Name toOidName( Name dn, Map oids ) throws InvalidNameException
+ {
+ if ( ( dn == null ) || ( dn.size() == 0 ) )
+ {
+ return dn;
+ }
+
+ LdapDN newDn = new LdapDN();
+
+ Enumeration rdns = dn.getAll();
+
+ while ( rdns.hasMoreElements() )
+ {
+ String rdn = (String)rdns.nextElement();
+
+ if ( rdn.indexOf( '+' ) != -1 )
+ {
+
+ }
+ else
+ {
+ int posEqual = rdn.indexOf( '=' );
+
+ if ( posEqual > 0 )
+ {
+ String name = StringUtils.trim( rdn.substring( 0, posEqual ) );
+
+ if ( StringUtils.isEmpty( StringUtils.lowerCase( name ) ) == false )
+ {
+ String oid = (String)oids.get( name );
+
+ if ( oid != null )
+ {
+ String newRdn = oid + rdn.substring( posEqual );
+ newDn.add( newRdn );
+ }
+ else
+ {
+ return null;
+ }
+ }
+ else
+ {
+ return null;
+ }
+ }
+ else
+ {
+ return null;
+ }
+
+ }
+ }
+
+ return newDn;
}
}