directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From seelm...@apache.org
Subject svn commit: r895446 - in /directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/name: FastLdapDnParser.java RdnParser.java
Date Sun, 03 Jan 2010 16:59:06 GMT
Author: seelmann
Date: Sun Jan  3 16:59:05 2010
New Revision: 895446

URL: http://svn.apache.org/viewvc?rev=895446&view=rev
Log:
Removed hand-written code from RDN parser, use newer FastLdapDnParser and ComplexLdapDnParser
instead.

Modified:
    directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/name/FastLdapDnParser.java
    directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/name/RdnParser.java

Modified: directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/name/FastLdapDnParser.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/name/FastLdapDnParser.java?rev=895446&r1=895445&r2=895446&view=diff
==============================================================================
--- directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/name/FastLdapDnParser.java
(original)
+++ directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/name/FastLdapDnParser.java
Sun Jan  3 16:59:05 2010
@@ -133,17 +133,16 @@
         {
             throw new InvalidNameException( "RDN must not be empty" );
         }
+        if( rdn == null )
+        {
+            throw new InvalidNameException( "RDN must not be null" );
+        }
 
         Position pos = new Position();
         pos.start = 0;
         pos.length = name.length();
 
         parseRdnInternal( name, pos, rdn );
-
-        if ( !hasMoreChars( pos ) )
-        {
-            throw new InvalidNameException( "Expected no more characters at position " +
pos.start );
-        }
     }
 
 

Modified: directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/name/RdnParser.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/name/RdnParser.java?rev=895446&r1=895445&r2=895446&view=diff
==============================================================================
--- directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/name/RdnParser.java
(original)
+++ directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/name/RdnParser.java
Sun Jan  3 16:59:05 2010
@@ -22,12 +22,6 @@
 
 import javax.naming.InvalidNameException;
 
-import org.apache.directory.shared.ldap.entry.client.ClientBinaryValue;
-import org.apache.directory.shared.ldap.entry.client.ClientStringValue;
-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 parse the name-component part or the following BNF grammar (as of
@@ -91,828 +85,6 @@
 public class RdnParser
 {
     /**
-     * Parse this rule : <br>
-     * <p>
-     * &lt;oidValue&gt; ::= [0-9] &lt;digits&gt; &lt;oids&gt;
-     * </p>
-     *
-     * @param bytes The bytes array to parse
-     * @param pos The current position in the byte buffer
-     * @return The new position in the vyte array, or PARSING_ERROR if the rule
-     *         does not apply to the byte array
-     */
-    private static String parseOidValue( byte[] bytes, Position pos )
-    {
-        pos.start += pos.length;
-        pos.end = pos.start;
-
-        // <attributType> ::= [0-9] <digits> <oids>
-        if ( !StringTools.isDigit( bytes, pos.start ) )
-        {
-            // Nope... An error
-            return null;
-        }
-        else
-        {
-            // Let's process an oid
-            pos.end++;
-
-            while ( StringTools.isDigit( bytes, pos.end ) )
-            {
-                pos.end++;
-            }
-
-            // <oids> ::= '.' [0-9] <digits> <oids> | e
-            if ( !StringTools.isCharASCII( bytes, pos.end, '.' ) )
-            {
-                return null;
-            }
-            else
-            {
-                do
-                {
-                    pos.end++;
-
-                    if ( !StringTools.isDigit( bytes, pos.end ) )
-                    {
-                        return null;
-                    }
-                    else
-                    {
-                        pos.end++;
-
-                        while ( StringTools.isDigit( bytes, pos.end ) )
-                        {
-                            pos.end++;
-                        }
-                    }
-
-                }
-                while ( StringTools.isCharASCII( bytes, pos.end, '.' ) );
-
-                return StringTools.utf8ToString( bytes, pos.start - pos.length, pos.end -
pos.start + pos.length );
-            }
-        }
-    }
-
-    
-    /**
-     * Validate this rule : <br>
-     * <p>
-     * &lt;oidValue&gt; ::= [0-9] &lt;digits&gt; &lt;oids&gt;
-     * </p>
-     *
-     * @param bytes The byte array to parse
-     * @param pos The current position in the byte buffer
-     * @return <code>true</code> if this is a valid OID
-     */
-    private static boolean isValidOidValue( byte[] bytes, Position pos )
-    {
-        pos.start += pos.length;
-        pos.end = pos.start;
-
-        // <attributType> ::= [0-9] <digits> <oids>
-        if ( !StringTools.isDigit( bytes, pos.start ) )
-        {
-            // Nope... An error
-            return false;
-        }
-        else
-        {
-            // Let's process an oid
-            pos.end++;
-
-            while ( StringTools.isDigit( bytes, pos.end ) )
-            {
-                pos.end++;
-            }
-
-            // <oids> ::= '.' [0-9] <digits> <oids> | e
-            if ( !StringTools.isCharASCII( bytes, pos.end, '.' ) )
-            {
-                return false;
-            }
-            else
-            {
-                do
-                {
-                    pos.end++;
-
-                    if ( !StringTools.isDigit( bytes, pos.end ) )
-                    {
-                        return false;
-                    }
-                    else
-                    {
-                        pos.end++;
-
-                        while ( StringTools.isDigit( bytes, pos.end ) )
-                        {
-                            pos.end++;
-                        }
-                    }
-
-                }
-                while ( StringTools.isCharASCII( bytes, pos.end, '.' ) );
-
-                return true;
-            }
-        }
-    }
-
-
-    /**
-     * Parse this rule : <br>
-     * <p>
-     * &lt;oidPrefix&gt; ::= 'OID.' | 'oid.' | e
-     * </p>
-     *
-     * @param bytes The buffer to parse
-     * @param pos The current position in the byte array
-     * @return The new position in the byte array, or PARSING_ERROR if the rule
-     *         does not apply to the byte array
-     */
-    private static int parseOidPrefix( byte[] bytes, Position pos )
-    {
-        if ( StringTools.isICharASCII( bytes, pos.start, 'O' ) &&
-             StringTools.isICharASCII( bytes, pos.start + 1, 'I' ) && 
-             StringTools.isICharASCII( bytes, pos.start + 2, 'D' ) &&
-             StringTools.isICharASCII( bytes, pos.start + 3, '.' ) )
-        {
-            pos.end += DNUtils.OID_LOWER.length();
-            return DNUtils.PARSING_OK;
-        }
-        else
-        {
-            return DNUtils.PARSING_ERROR;
-        }
-    }
-
-
-    /**
-     * Parse this rule : <br>
-     * <p>
-     * &lt;attributType&gt; ::= [a-zA-Z] &lt;keychars&gt; | &lt;oidPrefix&gt;
-     * [0-9] &lt;digits&gt; &lt;oids&gt; | [0-9] &lt;digits&gt; &lt;oids&gt;
-     * </p>
-     * The string *MUST* be an ASCII string, not an unicode string.
-     *
-     * @param bytes The byte array to parse
-     * @param pos The current position in the byte array
-     * @return The new position in the byte array, or PARSING_ERROR if the rule
-     *         does not apply to the byte array
-     */
-    private static String parseAttributeType( byte[] bytes, Position pos )
-    {
-        // <attributType> ::= [a-zA-Z] <keychars> | <oidPrefix> [0-9] <digits>
-        // <oids> | [0-9] <digits> <oids>
-        if ( StringTools.isAlphaASCII( bytes, pos.start ) )
-        {
-            // <attributType> ::= [a-zA-Z] <keychars> | <oidPrefix> [0-9]
-            // <digits> <oids>
-
-            // We have got an Alpha char, it may be the begining of an OID ?
-            if ( parseOidPrefix( bytes, pos ) != DNUtils.PARSING_ERROR )
-            {
-                pos.length = 4;
-
-                return parseOidValue( bytes, pos );
-            }
-            else
-            {
-                // It's not an oid, it's a String (ASCII)
-                // <attributType> ::= [a-zA-Z] <keychars>
-                // <keychars> ::= [a-zA-Z] <keychar> | [0-9] <keychar>
| '-'
-                // <keychar> | e
-                pos.end++;
-
-                while ( StringTools.isAlphaDigitMinus( bytes, pos.end ) )
-                {
-                    pos.end++;
-                }
-
-                return StringTools.utf8ToString( bytes, pos.start, pos.end - pos.start );
-            }
-        }
-        else
-        {
-            // An oid
-            // <attributType> ::= [0-9] <digits> <oids>
-            return parseOidValue( bytes, pos );
-        }
-    }
-
-
-    /**
-     * Parse this rule : <br>
-     * <p>
-     * &lt;attributType&gt; ::= [a-zA-Z] &lt;keychars&gt; | &lt;oidPrefix&gt;
-     * [0-9] &lt;digits&gt; &lt;oids&gt; | [0-9] &lt;digits&gt; &lt;oids&gt;
-     * </p>
-     * The string *MUST* be an ASCII string, not an unicode string.
-     *
-     * @param bytes The byte array to parse
-     * @param pos The current position in the byte array
-     * @return The new position in the byte array, or PARSING_ERROR if the rule
-     *         does not apply to the byte array
-     */
-    private static boolean isValidAttributeType( byte[] bytes, Position pos )
-    {
-        // <attributType> ::= [a-zA-Z] <keychars> | <oidPrefix> [0-9] <digits>
-        // <oids> | [0-9] <digits> <oids>
-        if ( StringTools.isAlphaASCII( bytes, pos.start ) )
-        {
-            // <attributType> ::= [a-zA-Z] <keychars> | <oidPrefix> [0-9]
-            // <digits> <oids>
-
-            // We have got an Alpha char, it may be the begining of an OID ?
-            if ( parseOidPrefix( bytes, pos ) != DNUtils.PARSING_ERROR )
-            {
-                pos.length = 4;
-
-                return isValidOidValue( bytes, pos );
-            }
-            else
-            {
-                // It's not an oid, it's a String (ASCII)
-                // <attributType> ::= [a-zA-Z] <keychars>
-                // <keychars> ::= [a-zA-Z] <keychar> | [0-9] <keychar>
| '-'
-                // <keychar> | e
-                pos.end++;
-
-                while ( StringTools.isAlphaDigitMinus( bytes, pos.end ) )
-                {
-                    pos.end++;
-                }
-
-                return true;
-            }
-        }
-        else
-        {
-            // An oid
-            // <attributType> ::= [0-9] <digits> <oids>
-            return isValidOidValue( bytes, pos );
-        }
-    }
-
-
-    /**
-     * Parse this rule : <br>
-     * <p>
-     * &lt;attributeValue&gt; ::= &lt;pairs-or-strings&gt; | '#'
-     *     &lt;hexstring&gt; |'"' &lt;quotechar-or-pairs&gt; '"' <br>
-     * &lt;pairs-or-strings&gt; ::= '\' &lt;pairchar&gt;
-     * &lt;pairs-or-strings&gt; | &lt;stringchar&gt; &lt;pairs-or-strings&gt;
| |
-     * e <br>
-     * &lt;quotechar-or-pairs&gt; ::= &lt;quotechar&gt;
-     * &lt;quotechar-or-pairs&gt; | '\' &lt;pairchar&gt;
-     * &lt;quotechar-or-pairs&gt; | e <br>
-     * </p>
-     *
-     * @param bytes The byte array to parse
-     * @param pos The current position in the byte array
-     * @return The new position in the byte array, or PARSING_ERROR if the rule
-     *         does not apply to the byte array
-     */
-    private static Object parseAttributeValue( byte[] bytes, Position pos )
-    {
-        if ( pos.start == bytes.length )
-        {
-            // This is an empty value
-            return "";
-        }
-        
-        //StringBuffer sb = new StringBuffer();
-        byte c = bytes[pos.start];
-        byte[] buffer = new byte[bytes.length];
-        int currPos = 0;
-
-        if ( c == '#' )
-        {
-            pos.start++;
-            int nbHex = 0;
-            int currentPos = pos.start;
-
-            // First, we will count the number of hexPairs
-            while ( DNUtils.parseHexPair( bytes, currentPos ) >= 0 )
-            {
-                nbHex++;
-                currentPos += DNUtils.TWO_CHARS;
-            }
-
-            byte[] hexValue = new byte[nbHex];
-
-            // Now, convert the value
-            // <attributeValue> ::= '#' <hexstring>
-            if ( DNUtils.parseHexString( bytes, hexValue, pos ) == DNUtils.PARSING_ERROR
)
-            {
-                return null;
-            }
-
-            pos.start--;
-            StringTools.trimRight( bytes, pos );
-            pos.length = pos.end - pos.start;
-
-            return hexValue;
-        }
-        else if ( c == '"' )
-        {
-            pos.start++;
-            pos.length = 0;
-            pos.end = pos.start;
-            int nbBytes = 0;
-            int length = 0;
-
-            // <attributeValue> ::= '"' <quotechar-or-pair> '"'
-            // <quotechar-or-pairs> ::= <quotechar> <quotechar-or-pairs>
| '\'
-            //                                                  <pairchar> <quotechar-or-pairs>
| e
-            while ( true )
-            {
-                if ( StringTools.isCharASCII( bytes, pos.end, '\\' ) )
-                {
-                    pos.end++;
-                    int nbChars = 0;
-
-                    if ( ( nbChars = DNUtils.countPairChar( bytes, pos.end ) ) == DNUtils.PARSING_ERROR
)
-                    {
-                        return null;
-                    }
-                    else
-                    {
-                        if ( nbChars == 1 )
-                        {
-                            buffer[currPos++] = bytes[pos.end];
-                        }
-                        else
-                        {
-                            byte b = StringTools.getHexValue( bytes[pos.end], bytes[pos.end
+ 1] );
-
-                            buffer[currPos++] = b;
-                        }
-                        
-                        pos.end += nbChars;
-                        length += nbChars;
-                    }
-                }
-                else if ( ( nbBytes = DNUtils.isQuoteChar( bytes, pos.end ) ) != DNUtils.PARSING_ERROR
)
-                {
-                    for ( int i = 0; i < nbBytes; i++ )
-                    {
-                        buffer[currPos++] = bytes[pos.end + i];
-                    }
-                    
-                    pos.end += nbBytes;
-                    length += nbBytes;
-                }
-                else
-                {
-                    //pos.length = pos.end - pos.start;
-                    break;
-                }
-            }
-
-            if ( StringTools.isCharASCII( bytes, pos.end, '"' ) )
-            {
-                pos.end++;
-                pos.length = length + 2;
-                return StringTools.utf8ToString( buffer, length );
-            }
-            else
-            {
-                return null;
-            }
-        }
-        else
-        {
-            int escapedSpace = -1;
-
-            while ( true )
-            {
-                if ( StringTools.isCharASCII( bytes, pos.end, '\\' ) )
-                {
-                    // '\' <pairchar> <pairs-or-strings>
-                    pos.end++;
-
-                    int nbChars = 0;
-                    
-                    if ( ( nbChars = DNUtils.countPairChar( bytes, pos.end ) ) == DNUtils.PARSING_ERROR
)
-                    {
-                        return null;
-                    }
-                    else
-                    {
-                        if ( nbChars == 1 )
-                        {
-                            buffer[currPos++] = bytes[pos.end];
-                        }
-                        else
-                        {
-                            byte b = StringTools.getHexValue( bytes[pos.end], bytes[pos.end
+ 1] );
-
-                            buffer[currPos++] = b;
-                        }
-
-                        if ( bytes[pos.end] == ' ' )
-                        {
-                            escapedSpace = currPos;
-                        }
-                        else
-                        {
-                            escapedSpace = -1;
-                        }
-
-                        pos.end += nbChars;
-                    }
-                }
-                else
-                {
-                    int nbChars = 0;
-
-                    // <stringchar> <pairs-or-strings>
-                    if ( ( nbChars = DNUtils.isStringChar( bytes, pos.end ) ) != DNUtils.PARSING_ERROR
)
-                    {
-                        // If the char is not a space, we have to switch off the escapedSpace
flag
-                        if ( ( escapedSpace != -1 ) && ! StringTools.isCharASCII(
bytes, pos.end, ' ' ) )
-                        {
-                            escapedSpace = -1;
-                        }
-                        
-                        // A special case : if we have some spaces before the
-                        // '+' character,
-                        // we MUST skip them.
-                        if ( StringTools.isCharASCII( bytes, pos.end, '+' ) )
-                        {
-                            //StringTools.trimLeft( string, pos );
-
-                            if ( ( DNUtils.isStringChar( bytes, pos.end ) == DNUtils.PARSING_ERROR
)
-                                && ( !StringTools.isCharASCII( bytes, pos.end, '\\'
) ) )
-                            {
-                                // Ok, we are done with the stringchar.
-                                String result = StringTools.trimRight( 
-                                    StringTools.utf8ToString( bytes, pos.start, pos.start
+ pos.length ) );
-                                
-                                return result;
-                            }
-                            else
-                            {
-                                for ( int i = 0; i < nbChars; i++ )
-                                {
-                                    buffer[currPos++] = bytes[pos.end];
-                                    pos.end ++;
-                                }
-                            }
-                        }
-                        else
-                        {
-                            for ( int i = 0; i < nbChars; i++ )
-                            {
-                                buffer[currPos++] = bytes[pos.end];
-                                pos.end ++;
-                            }
-                        }
-                    }
-                    else
-                    {
-                        pos.length = pos.end - pos.start;
-                        
-                        if ( escapedSpace == -1 )
-                        {
-                            String result = StringTools.trimRight( StringTools.utf8ToString(
buffer, currPos ) );
-                            return result;
-                        }
-                        
-                        String result = StringTools.utf8ToString( buffer, escapedSpace );
-
-                        return result;
-                    }
-                }
-            }
-        }
-    }
-
-
-    /**
-     * Validate this rule : <br>
-     * <p>
-     * &lt;attributeValue&gt; ::= &lt;pairs-or-strings&gt; | '#'
-     *     &lt;hexstring&gt; |'"' &lt;quotechar-or-pairs&gt; '"' <br>
-     * &lt;pairs-or-strings&gt; ::= '\' &lt;pairchar&gt;
-     * &lt;pairs-or-strings&gt; | &lt;stringchar&gt; &lt;pairs-or-strings&gt;
| |
-     * e <br>
-     * &lt;quotechar-or-pairs&gt; ::= &lt;quotechar&gt;
-     * &lt;quotechar-or-pairs&gt; | '\' &lt;pairchar&gt;
-     * &lt;quotechar-or-pairs&gt; | e <br>
-     * </p>
-     *
-     * @param bytes The byte array to parse
-     * @param pos The current position in the byte array
-     * @return <code>true</code> if the rule is valid
-     */
-    private static boolean isValidAttributeValue( byte[] bytes, Position pos )
-    {
-        if( bytes.length <= pos.start )
-        {
-            // no attribute value
-            return true;
-        }
-
-        byte c = bytes[pos.start];
-
-        if ( c == '#' )
-        {
-            pos.start++;
-            int nbHex = 0;
-            int currentPos = pos.start;
-
-            // First, we will count the number of hexPairs
-            while ( DNUtils.parseHexPair( bytes, currentPos ) >= 0 )
-            {
-                nbHex++;
-                currentPos += DNUtils.TWO_CHARS;
-            }
-
-            byte[] hexValue = new byte[nbHex];
-
-            // Now, convert the value
-            // <attributeValue> ::= '#' <hexstring>
-            if ( DNUtils.parseHexString( bytes, hexValue, pos ) == DNUtils.PARSING_ERROR
)
-            {
-                return false;
-            }
-
-            pos.start--;
-            StringTools.trimRight( bytes, pos );
-            pos.length = pos.end - pos.start;
-
-            return true;
-        }
-        else if ( c == '"' )
-        {
-            pos.start++;
-            pos.length = 0;
-            pos.end = pos.start;
-            int nbBytes = 0;
-
-            // <attributeValue> ::= '"' <quotechar-or-pair> '"'
-            // <quotechar-or-pairs> ::= <quotechar> <quotechar-or-pairs>
| '\'
-            //                                                  <pairchar> <quotechar-or-pairs>
| e
-            while ( true )
-            {
-                if ( StringTools.isCharASCII( bytes, pos.end, '\\' ) )
-                {
-                    pos.end++;
-                    int nbChars = 0;
-
-                    if ( ( nbChars = DNUtils.countPairChar( bytes, pos.end ) ) != DNUtils.PARSING_ERROR
)
-                    {
-                        pos.end += nbChars;
-                    }
-                    else
-                    {
-                        return false;
-                    }
-                }
-                else if ( ( nbBytes = DNUtils.isQuoteChar( bytes, pos.end ) ) != DNUtils.PARSING_ERROR
)
-                {
-                    pos.end += nbBytes;
-                }
-                else
-                {
-                    pos.length = pos.end - pos.start;
-                    break;
-                }
-            }
-
-            if ( StringTools.isCharASCII( bytes, pos.end, '"' ) )
-            {
-                pos.end++;
-                return true;
-            }
-            else
-            {
-                return false;
-            }
-        }
-        else
-        {
-            while ( true )
-            {
-                if ( StringTools.isCharASCII( bytes, pos.end, '\\' ) )
-                {
-                    // '\' <pairchar> <pairs-or-strings>
-                    pos.end++;
-
-                    int nbChars = 0;
-                    
-                    if ( ( nbChars = DNUtils.countPairChar( bytes, pos.end ) ) == DNUtils.PARSING_ERROR
)
-                    {
-                        return false;
-                    }
-                    else
-                    {
-                        pos.end += nbChars;
-                    }
-                }
-                else
-                {
-                    int nbChars = 0;
-
-                    // <stringchar> <pairs-or-strings>
-                    if ( ( nbChars = DNUtils.isStringChar( bytes, pos.end ) ) != DNUtils.PARSING_ERROR
)
-                    {
-                        // A special case : if we have some spaces before the
-                        // '+' character,
-                        // we MUST skip them.
-                        if ( StringTools.isCharASCII( bytes, pos.end, '+' ) )
-                        {
-                            //StringTools.trimLeft( string, pos );
-
-                            if ( ( DNUtils.isStringChar( bytes, pos.end ) == DNUtils.PARSING_ERROR
)
-                                && ( !StringTools.isCharASCII( bytes, pos.end, '\\'
) ) )
-                            {
-                                // Ok, we are done with the stringchar.
-                                return true;
-                            }
-                            else
-                            {
-                                pos.end++;
-                            }
-                        }
-                        else
-                        {
-                            pos.end += nbChars;
-                        }
-                    }
-                    else
-                    {
-                        return true;
-                    }
-                }
-            }
-        }
-    }
-
-
-    /**
-     * Parse this rule : <br>
-     * <p>
-     * &lt;nameComponents&gt; ::= &lt;spaces&gt; '+' &lt;spaces&gt;
-     * &lt;attributeType&gt; &lt;spaces&gt; '=' &lt;spaces&gt;
-     * &lt;attributeValue&gt; &lt;nameComponents&gt; | e
-     * </p>
-     *
-     * @param bytes The byte buffer to parse
-     * @param pos The current position in the byte buffer
-     * @param rdn The rdn to generate
-     * @return The new position in the byte buffer, or PARSING_ERROR if the rule
-     *         does not apply to the byte buffer
-     * @throws InvalidNameException If the NameComponent is invalid
-     */
-    private static int parseNameComponents( byte[] bytes, Position pos, Rdn rdn ) throws
InvalidNameException
-    {
-        if ( rdn == null )
-        {
-            throw new InvalidNameException( "The RDN should not be null" );
-        }
-        
-        int newStart = 0;
-        String type = null;
-        Object value = null;
-
-        while ( true )
-        {
-            StringTools.trimLeft( bytes, pos );
-
-            if ( StringTools.isCharASCII( bytes, pos.end, '+' ) )
-            {
-                pos.start++;
-                pos.length = 0;
-            }
-            else
-            {
-                // <attributeTypeAndValues> ::= e
-                rdn.normalize();
-                return DNUtils.PARSING_OK;
-            }
-
-            StringTools.trimLeft( bytes, pos );
-
-            if ( ( type = parseAttributeType( bytes, pos ) ) == null )
-            {
-                return DNUtils.PARSING_ERROR;
-            }
-
-            pos.start = pos.end;
-
-            StringTools.trimLeft( bytes, pos );
-
-            if ( StringTools.isCharASCII( bytes, pos.end, '=' ) )
-            {
-                pos.start++;
-            }
-            else
-            {
-                return DNUtils.PARSING_ERROR;
-            }
-
-            StringTools.trimLeft( bytes, pos );
-
-            value = parseAttributeValue( bytes, pos );
-
-            newStart = pos.end;
-
-            if ( value != null )
-            {
-                if ( rdn != null )
-                {
-                    if ( value instanceof String )
-                    {
-                        rdn.addAttributeTypeAndValue( type, type, 
-                            new ClientStringValue( (String)value ), 
-                            new ClientStringValue( (String)value ) );
-                    }
-                    else
-                    {
-                        rdn.addAttributeTypeAndValue( type, type, 
-                            new ClientBinaryValue( (byte[])value ), 
-                            new ClientBinaryValue( (byte[])value ) );
-                    }
-                }
-            }
-
-            pos.start = newStart;
-            pos.end = newStart;
-        }
-    }
-
-
-    /**
-     * Validate this rule : <br>
-     * <p>
-     * &lt;nameComponents&gt; ::= &lt;spaces&gt; '+' &lt;spaces&gt;
-     * &lt;attributeType&gt; &lt;spaces&gt; '=' &lt;spaces&gt;
-     * &lt;attributeValue&gt; &lt;nameComponents&gt; | e
-     * </p>
-     *
-     * @param bytes The byte buffer to parse
-     * @param pos The current position in the byte buffer
-     * @param isFirstRdn A flag set if the RDN is the first one
-     * @return <code>true</code> if the rule is valid
-     */
-    private static boolean isValidNameComponents( byte[] bytes, Position pos, boolean isFirstRdn
)
-    {
-        int newStart = 0;
-
-        while ( true )
-        {
-            StringTools.trimLeft( bytes, pos );
-
-            if ( StringTools.isCharASCII( bytes, pos.end, '+' ) )
-            {
-                pos.start++;
-            }
-            else
-            {
-                // <attributeTypeAndValues> ::= e
-                return true;
-            }
-
-            StringTools.trimLeft( bytes, pos );
-
-            if ( !isValidAttributeType( bytes, pos ) )
-            {
-                return false;
-            }
-
-            pos.start = pos.end;
-
-            StringTools.trimLeft( bytes, pos );
-
-            if ( StringTools.isCharASCII( bytes, pos.end, '=' ) )
-            {
-                pos.start++;
-            }
-            else
-            {
-                return false;
-            }
-
-            StringTools.trimLeft( bytes, pos );
-
-            if ( !isValidAttributeValue( bytes, pos ) )
-            {
-                return false;
-            }
-
-            newStart = pos.end;
-            pos.start = newStart;
-            pos.end = newStart;
-        }
-    }
-
-
-    /**
      * Parse a NameComponent : <br>
      * <p>
      * &lt;name-component&gt; ::= &lt;attributeType&gt; &lt;spaces&gt;
'='
@@ -920,105 +92,21 @@
      * </p>
      *
      * @param dn The String to parse
-     * @param pos The current position in the buffer
-     * @param rdn The constructed RDN
-     * @return The new position in the char array, or PARSING_ERROR if the rule
-     *         does not apply to the char array
-     * @throws InvalidNameException If the NameComponent is invalid
-     */
-    public static int parse( String dn, Position pos, Rdn rdn ) throws InvalidNameException
-    {
-        return parse( StringTools.getBytesUtf8( dn ), pos, rdn );
-    }
-
-
-    /**
-     * Parse a NameComponent : <br>
-     * <p>
-     * &lt;name-component&gt; ::= &lt;attributeType&gt; &lt;spaces&gt;
'='
-     * &lt;spaces&gt; &lt;attributeValue&gt; &lt;nameComponents&gt;
-     * </p>
-     *
-     * @param dn The byte array to parse
-     * @param pos The current position in the buffer
-     * @param rdn The constructed RDN
-     * @return The new position in the byte array, or PARSING_ERROR if the rule
-     *         does not apply to the byte array
+     * @param rdn The RDN to fill. Beware that if the RDN is not empty, the new
+     *            AttributeTypeAndValue will be added.
      * @throws InvalidNameException If the NameComponent is invalid
      */
-    public static int parse( byte[] dn, Position pos, Rdn rdn ) throws InvalidNameException
+    public static void parse( String dn, Rdn rdn ) throws InvalidNameException
     {
-        if ( rdn == null )
+        try
         {
-            throw new InvalidNameException( "Cannot feed a null RDN structure" );
+            FastLdapDnParser.INSTANCE.parseRdn( dn, rdn );
         }
-        
-        String type = null;
-        Object value = null;
-        int start = pos.start;
-
-        StringTools.trimLeft( dn, pos );
-
-        pos.end = pos.start;
-        pos.length = 0;
-        
-        if ( ( type = parseAttributeType( dn, pos ) ) == null )
+        catch ( TooComplexException e )
         {
-            return DNUtils.PARSING_ERROR;
+            rdn.clear();
+            new ComplexLdapDnParser().parseRdn( dn, rdn );
         }
-
-        pos.start = pos.end;
-
-        StringTools.trimLeft( dn, pos );
-
-        if ( !StringTools.isCharASCII( dn, pos.start, '=' ) )
-        {
-            return DNUtils.PARSING_ERROR;
-        }
-        else
-        {
-            pos.start++;
-        }
-
-        StringTools.trimLeft( dn, pos );
-
-        pos.end = pos.start;
-        
-        int start2 = pos.start;
-
-        if ( ( value = parseAttributeValue( dn, pos ) ) == null )
-        {
-            return DNUtils.PARSING_ERROR;
-        }
-
-        String upValue = StringTools.utf8ToString( dn, start2, pos.length );
-        
-        if ( value instanceof String )
-        {
-            rdn.addAttributeTypeAndValue( type, type, 
-                new ClientStringValue( upValue ), 
-                new ClientStringValue( (String)value ) );
-        }
-        else
-        {
-            rdn.addAttributeTypeAndValue( type, type, 
-                new ClientStringValue( upValue ), 
-                new ClientBinaryValue( (byte[])value ) );
-        }
-        
-        rdn.normalize();
-
-        pos.start = pos.end;
-        pos.length = 0;
-
-        if ( parseNameComponents( dn, pos, rdn ) == DNUtils.PARSING_ERROR )
-        {
-            return DNUtils.PARSING_ERROR;
-        }
-        
-        rdn.setUpName( StringTools.utf8ToString( dn, start, pos.end - start ) );
-        pos.start = pos.end;
-        return DNUtils.PARSING_OK;
     }
 
 
@@ -1029,90 +117,21 @@
      * &lt;spaces&gt; &lt;attributeValue&gt; &lt;nameComponents&gt;
      * </p>
      *
-     * @param dn The byte array to parse
-     * @param pos The current position in the buffer
-     * @param isFirstRdn a flag set if the RDN is the first for the current DN
+     * @param dn The string to parse
      * @return <code>true</code> if the RDN is valid
      */
-    public static boolean isValid( byte[] dn, Position pos, boolean isFirstRdn )
+    public static boolean isValid( String dn )
     {
-        StringTools.trimLeft( dn, pos );
-
-        pos.end = pos.start;
-        pos.length = 0;
-        
-        if ( !isValidAttributeType( dn, pos ) )
-        {
-            return false;
-        }
-
-        pos.start = pos.end;
-
-        StringTools.trimLeft( dn, pos );
-
-        if ( !StringTools.isCharASCII( dn, pos.start, '=' ) )
-        {
-            return false;
-        }
-        else
-        {
-            pos.start++;
-        }
-
-        StringTools.trimLeft( dn, pos );
-
-        pos.end = pos.start;
-
-        if ( !isValidAttributeValue( dn, pos ) )
+        Rdn rdn = new Rdn();
+        try
         {
-            return false;
+            parse( dn, rdn );
+            return true;
         }
-
-        pos.start = pos.end;
-        pos.length = 0;
-
-        if ( !isValidNameComponents( dn, pos, isFirstRdn )  )
+        catch ( InvalidNameException e )
         {
             return false;
         }
-        
-        pos.start = pos.end;
-        return true;
-    }
-
-
-    /**
-     * Parse a NameComponent : <br>
-     * <p>
-     * &lt;name-component&gt; ::= &lt;attributeType&gt; &lt;spaces&gt;
'='
-     * &lt;spaces&gt; &lt;attributeValue&gt; &lt;nameComponents&gt;
-     * </p>
-     *
-     * @param dn The String to parse
-     * @param rdn The RDN to fill. Beware that if the RDN is not empty, the new
-     *            AttributeTypeAndValue will be added.
-     * @throws InvalidNameException If the NameComponent is invalid
-     */
-    public static void parse( String dn, Rdn rdn ) throws InvalidNameException
-    {
-        if ( parse( StringTools.getBytesUtf8( dn ), new Position(), rdn ) == DNUtils.PARSING_ERROR
)
-        {
-            throw new InvalidNameException( "The RDN can't be parsed." );
-        }
     }
 
-    /**
-     * Validate a NameComponent : <br>
-     * <p>
-     * &lt;name-component&gt; ::= &lt;attributeType&gt; &lt;spaces&gt;
'='
-     * &lt;spaces&gt; &lt;attributeValue&gt; &lt;nameComponents&gt;
-     * </p>
-     *
-     * @param dn The string to parse
-     * @return <code>true</code> if the RDN is valid
-     */
-    public static boolean isValid( String dn )
-    {
-        return isValid( StringTools.getBytesUtf8( dn ), new Position(), false );
-    }
 }



Mime
View raw message