directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From seelm...@apache.org
Subject svn commit: r765066 - in /directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/name: LdapDN.java LdapDnParser.java
Date Wed, 15 Apr 2009 06:41:40 GMT
Author: seelmann
Date: Wed Apr 15 06:41:39 2009
New Revision: 765066

URL: http://svn.apache.org/viewvc?rev=765066&view=rev
Log:
DIRSHARED-15,DIRSHARED-32: Activated new DN parsers

Modified:
    directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/name/LdapDN.java
    directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/name/LdapDnParser.java

Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/name/LdapDN.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/name/LdapDN.java?rev=765066&r1=765065&r2=765066&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/name/LdapDN.java
(original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/name/LdapDN.java
Wed Apr 15 06:41:39 2009
@@ -290,7 +290,7 @@
     public LdapDN( byte[] bytes ) throws InvalidNameException
     {
         upName = StringTools.utf8ToString( bytes );
-        LdapDnParser.parseInternal( bytes, rdns );
+        LdapDnParser.parseInternal( upName, rdns );
         this.normName = toNormName();
         normalized = false;
     }

Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/name/LdapDnParser.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/name/LdapDnParser.java?rev=765066&r1=765065&r2=765066&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/name/LdapDnParser.java
(original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/name/LdapDnParser.java
Wed Apr 15 06:41:39 2009
@@ -27,11 +27,6 @@
 import javax.naming.NameParser;
 
 
-import org.apache.directory.shared.ldap.util.DNUtils;
-import org.apache.directory.shared.ldap.util.Position;
-import org.apache.directory.shared.ldap.util.StringTools;
-
-
 /**
  * This class parses a DN. The DN MUST respect this BNF grammar (as of RFC2253,
  * par. 3, and RFC1779, fig. 1) <br>
@@ -67,188 +62,76 @@
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  * @version $Rev$, $Date$
  */
-public class LdapDnParser implements NameParser
+public enum LdapDnParser implements NameParser
 {
-   private static LdapDnParser instance = new LdapDnParser();
-
+    INSTANCE;
 
-   /**
-    * A private constructor. It's useless, as this object is totally stateless,
-    * but we need to expose a NameParser.
-    */
-   private LdapDnParser()
-   {
-       // Nothing to do
-   }
-
-
-   /**
-    * Get a reference to the NameParser. Needed to be compliant with the JNDI
-    * API
-    *
-    * @return An instance of the NameParser
-    */
-   public static NameParser getNameParser()
-   {
-       return instance;
-   }
-
-
-   /**
-    * Parse a DN
-    *
-    * @param dn The DN to be parsed
-    * @param rdns The list that will contain the RDNs
-    * @throws InvalidNameException If the DN is invalid
-    */
-   public static void parseInternal( String dn, List<Rdn> rdns ) throws InvalidNameException
-   {
-       if ( dn.length() == 0 )
-       {
-           // We have an empty DN, just get out of the function.
-           return;
-       }
-
-       parseInternal( StringTools.getBytesUtf8( dn ), rdns );
-       
-       return;
-   }
-
-
-   /**
-    * Parse a DN
-    *
-    * @param dn The DN to be parsed
-    * @param rdns The list that will contain the RDNs
-    * @throws InvalidNameException If the DN is invalid
-    */
-   public static void parseInternal( byte[] dn, List<Rdn> rdns ) throws InvalidNameException
-   {
-       if ( dn.length == 0 )
-       {
-           // We have an empty DN, just get out of the function.
-           return;
-       }
-
-       Position pos = new Position();
-       pos.start = 0;
-       Rdn rdn = new Rdn();
-
-       // <name> ::= <name-component> <name-components>
-       // <name-components> ::= <spaces> <separator> <spaces> <name-component>
-       // <name-components> | e
-       if ( RdnParser.parse( dn, pos, rdn ) != DNUtils.PARSING_ERROR )
-       {
-           // Now, parse the following nameComponents
-           do
-           {
-               rdns.add( rdn );
-               rdn = new Rdn();
-
-               if ( ( !StringTools.isCharASCII( dn, pos.start, ',' ) )
-                   && ( !StringTools.isCharASCII( dn, pos.start, ';' ) ) )
-               {
-
-                   if ( pos.start != dn.length )
-                   {
-                       throw new InvalidNameException( "Bad DN : " + StringTools.utf8ToString(
dn ) );
-                   }
-                   else
-                   {
-                       return;
-                   }
-               }
-
-               pos.start++;
-           }
-           while ( RdnParser.parse( dn, pos, rdn ) != DNUtils.PARSING_ERROR );
-           
-           throw new InvalidNameException( "Bad DN : " + StringTools.utf8ToString( dn ) );
-       }
-       else
-       {
-           throw new InvalidNameException( "Bad DN : " + StringTools.utf8ToString( dn ) );
-       }
-   }
-
-
-   /**
-    * Validate a DN
-    *
-    * @param dn The DN to be parsed
-    *            
-    * @return <code>true</code> if the DN is valid
-    */
-   private static boolean validateInternal( byte[] dn )
-   {
-
-       Position pos = new Position();
-       pos.start = 0;
-
-       // <name> ::= <name-component> <name-components>
-       // <name-components> ::= <spaces> <separator> <spaces> <name-component>
-       // <name-components> | e
-       if ( RdnParser.isValid( dn, pos, true ) )
-       {
-           // Now, parse the following nameComponents
-           do
-           {
-               if ( ( !StringTools.isCharASCII( dn, pos.start, ',' ) )
-                   && ( !StringTools.isCharASCII( dn, pos.start, ';' ) ) )
-               {
-
-                   if ( pos.start != dn.length )
-                   {
-                       return false;
-                   }
-                   else
-                   {
-                       return true;
-                   }
-               }
-
-               pos.start++;
-           }
-           while ( RdnParser.isValid( dn, pos, false ) );
-           
-       }
-
-       return false;
-   }
-
-   
-   /**
-    * Validate a DN
-    *
-    * @param dn The DN to be parsed
-    *            
-    * @return <code>true</code> if the DN is valid
-    */
-   public static boolean validateInternal( String dn )
-   {
-       if ( dn.length() == 0 )
-       {
-           // We have an empty DN, just get out of the function.
-           return true;
-       }
-
-       return validateInternal( StringTools.getBytesUtf8( dn ) );
-   }
-
-
-   /**
-    * Parse a String and return a LdapDN if the String is a valid DN
-    *
-    * @param dn
-    *            The DN to parse
-    * @return A LdapDN
-    * @throws InvalidNameException
-    *             If the String is not a valid DN
-    */
-   public Name parse( String dn ) throws InvalidNameException
-   {
-       return new LdapDN( dn );
-   }
+    /**
+     * Get a reference to the NameParser. Needed to be compliant with the JNDI
+     * API
+     *
+     * @return An instance of the NameParser
+     */
+    public static NameParser getNameParser()
+    {
+        return INSTANCE;
+    }
+
+
+    /**
+     * Parse a DN.
+     *
+     * @param dn The DN to be parsed
+     * @param rdns The list that will contain the RDNs
+     * @throws InvalidNameException If the DN is invalid
+     */
+    public static void parseInternal( String name, List<Rdn> rdns ) throws InvalidNameException
+    {
+        try
+        {
+            FastLdapDnParser.INSTANCE.parseDn( name, rdns );
+        }
+        catch ( TooComplexException e )
+        {
+            rdns.clear();
+            new ComplexLdapDnParser().parseDn( name, rdns );
+        }
+    }
+
+
+    /**
+     * Validate a DN
+     *
+     * @param dn The DN to be parsed
+     *            
+     * @return <code>true</code> if the DN is valid
+     */
+    public static boolean validateInternal( String name )
+    {
+        LdapDN dn = new LdapDN();
+        try
+        {
+            parseInternal( name, dn.rdns );
+            return true;
+        }
+        catch ( InvalidNameException e )
+        {
+            return false;
+        }
+    }
+
+
+    /**
+     * Parse a String and return a LdapDN if the String is a valid DN
+     *
+     * @param dn
+     *            The DN to parse
+     * @return A LdapDN
+     * @throws InvalidNameException
+     *             If the String is not a valid DN
+     */
+    public Name parse( String dn ) throws InvalidNameException
+    {
+        return new LdapDN( dn );
+    }
 }
-
-



Mime
View raw message