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 2011/03/22 19:36:29 UTC

svn commit: r1084289 - in /directory: apacheds/trunk/core/src/main/java/org/apache/directory/server/core/partition/ shared/trunk/ldap/extras/aci/src/main/antlr/ shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/name/ shared/t...

Author: elecharny
Date: Tue Mar 22 18:36:29 2011
New Revision: 1084289

URL: http://svn.apache.org/viewvc?rev=1084289&view=rev
Log:
o Removed many useless methods in DnUtils
o Deleted DnUtilsTest, moved the tests in StringsTest
o 

Removed:
    directory/shared/trunk/ldap/model/src/test/java/org/apache/directory/shared/ldap/model/name/DnUtilsTest.java
Modified:
    directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/partition/DefaultPartitionNexus.java
    directory/shared/trunk/ldap/extras/aci/src/main/antlr/ACIItem.g
    directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/name/DnUtils.java
    directory/shared/trunk/util/src/test/java/org/apache/directory/shared/util/StringsTest.java

Modified: directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/partition/DefaultPartitionNexus.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/partition/DefaultPartitionNexus.java?rev=1084289&r1=1084288&r2=1084289&view=diff
==============================================================================
--- directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/partition/DefaultPartitionNexus.java (original)
+++ directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/partition/DefaultPartitionNexus.java Tue Mar 22 18:36:29 2011
@@ -317,8 +317,8 @@ public class DefaultPartitionNexus exten
             systemEntry.put( SchemaConstants.CREATE_TIMESTAMP_AT, DateUtils.getGeneralizedTime() );
             systemEntry.add( SchemaConstants.ENTRY_CSN_AT, directoryService.getCSN().toString() );
             systemEntry.add( SchemaConstants.ENTRY_UUID_AT, UUID.randomUUID().toString() );
-            systemEntry.put( DnUtils.getRdnAttribute(ServerDNConstants.SYSTEM_DN), DnUtils
-                .getRdnValue(ServerDNConstants.SYSTEM_DN) );
+            systemEntry.put( DnUtils.getRdnAttributeType( ServerDNConstants.SYSTEM_DN ), DnUtils
+                .getRdnValue( ServerDNConstants.SYSTEM_DN ) );
             
             AddOperationContext addOperationContext = new AddOperationContext( adminSession, systemEntry );
             system.add( addOperationContext );

Modified: directory/shared/trunk/ldap/extras/aci/src/main/antlr/ACIItem.g
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/extras/aci/src/main/antlr/ACIItem.g?rev=1084289&r1=1084288&r2=1084289&view=diff
==============================================================================
--- directory/shared/trunk/ldap/extras/aci/src/main/antlr/ACIItem.g (original)
+++ directory/shared/trunk/ldap/extras/aci/src/main/antlr/ACIItem.g Tue Mar 22 18:36:29 2011
@@ -505,7 +505,7 @@ attributeValue
         for ( Rdn rdn : attributeTypeAndValueSetAsDn )
         {
             attributeTypeAndValue = rdn.getNormName();
-            attributeType = DnUtils.getRdnAttribute( attributeTypeAndValue );
+            attributeType = DnUtils.getRdnAttributeType( attributeTypeAndValue );
             attributeValue = DnUtils.getRdnValue( attributeTypeAndValue );
             
             attributeSet.add( new DefaultEntryAttribute( attributeType, attributeValue ) );

Modified: directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/name/DnUtils.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/name/DnUtils.java?rev=1084289&r1=1084288&r2=1084289&view=diff
==============================================================================
--- directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/name/DnUtils.java (original)
+++ directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/name/DnUtils.java Tue Mar 22 18:36:29 2011
@@ -20,807 +20,37 @@
 package org.apache.directory.shared.ldap.model.name;
 
 
-import java.util.ArrayList;
-import java.util.List;
-
-import org.apache.directory.shared.i18n.I18n;
-import org.apache.directory.shared.ldap.model.exception.LdapInvalidDnException;
-import org.apache.directory.shared.util.Chars;
-import org.apache.directory.shared.util.Hex;
-import org.apache.directory.shared.util.Position;
-import org.apache.directory.shared.util.Unicode;
 
 /**
- * Utility class used by the Dn Parser.
+ * Utility class used to manipulate Dn or Rdn elements.
  * 
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  */
 public final class DnUtils
 {
-    /** A value if we got an error while parsing */
-    public static final int PARSING_ERROR = -1;
-
-    /** A value if we got a correct parsing */
-    public static final int PARSING_OK = 0;
-
-    /** If an hex pair contains only one char, this value is returned */
-    public static final int BAD_HEX_PAIR = -2;
-
-    /** A constant representing one char length */
-    public static final int ONE_CHAR = 1;
-
-    /** A constant representing two chars length */
-    public static final int TWO_CHARS = 2;
-
-    /** A constant representing one byte length */
-    public static final int ONE_BYTE = 1;
-
-    /** A constant representing two bytes length */
-    public static final int TWO_BYTES = 2;
-
-   /**
-     * &lt;safe-init-char&gt; ::= [0x01-0x09] | 0x0B | 0x0C | [0x0E-0x1F] |
-     * [0x21-0x39] | 0x3B | [0x3D-0x7F]
-     */
-    private static final boolean[] SAFE_INIT_CHAR =
-        { 
-            false, true,  true,  true,  true,  true,  true,  true, 
-            true,  true,  false, true,  true,  false, true,  true, 
-            true,  true,  true,  true,  true,  true,  true,  true, 
-            true,  true,  true,  true,  true,  true,  true,  true, 
-            false, true,  true,  true,  true,  true,  true,  true, 
-            true,  true,  true,  true,  true,  true,  true,  true, 
-            true,  true,  true,  true,  true,  true,  true,  true, 
-            true,  true,  false, true,  false, true,  true,  true, 
-            true,  true,  true,  true,  true,  true,  true,  true, 
-            true,  true,  true,  true,  true,  true,  true,  true, 
-            true,  true,  true,  true,  true,  true,  true,  true, 
-            true,  true,  true,  true,  true,  true,  true,  true, 
-            true,  true,  true,  true,  true,  true,  true,  true, 
-            true,  true,  true,  true,  true,  true,  true,  true, 
-            true,  true,  true,  true,  true,  true,  true,  true, 
-            true,  true,  true,  true,  true,  true,  true,  true 
-        };
-
-    /** &lt;safe-char&gt; ::= [0x01-0x09] | 0x0B | 0x0C | [0x0E-0x7F] */
-    private static final boolean[] SAFE_CHAR =
-        { 
-            false, true,  true,  true,  true,  true,  true,  true, 
-            true,  true,  false, true,  true,  false, true,  true, 
-            true,  true,  true,  true,  true,  true,  true,  true, 
-            true,  true,  true,  true,  true,  true,  true,  true, 
-            true,  true,  true,  true,  true,  true,  true,  true, 
-            true,  true,  true,  true,  true,  true,  true,  true, 
-            true,  true,  true,  true,  true,  true,  true,  true, 
-            true,  true,  true,  true,  true,  true,  true,  true, 
-            true,  true,  true,  true,  true,  true,  true,  true, 
-            true,  true,  true,  true,  true,  true,  true,  true, 
-            true,  true,  true,  true,  true,  true,  true,  true, 
-            true,  true,  true,  true,  true,  true,  true,  true, 
-            true,  true,  true,  true,  true,  true,  true,  true, 
-            true,  true,  true,  true,  true,  true,  true,  true, 
-            true,  true,  true,  true,  true,  true,  true,  true, 
-            true,  true,  true,  true,  true,  true,  true,  true, 
-        };
-
-    /**
-     * &lt;base64-char&gt; ::= 0x2B | 0x2F | [0x30-0x39] | 0x3D | [0x41-0x5A] |
-     * [0x61-0x7A]
-     */
-    private static final boolean[] BASE64_CHAR =
-        { 
-            false, false, false, false, false, false, false, false, 
-            false, false, false, false, false, false, false, false, 
-            false, false, false, false, false, false, false, false, 
-            false, false, false, false, false, false, false, false, 
-            false, false, false, false, false, false, false, false, 
-            false, false, false, true,  false, false, false, true, 
-            true,  true,  true,  true,  true,  true,  true,  true, 
-            true,  true,  false, false, false, true,  false, false, 
-            false, true,  true,  true,  true,  true,  true,  true, 
-            true,  true,  true,  true,  true,  true,  true,  true, 
-            true,  true,  true,  true,  true,  true,  true,  true, 
-            true,  true,  true,  false, false, false, false, false,
-            false, true,  true,  true,  true,  true,  true,  true, 
-            true,  true,  true,  true,  true,  true,  true,  true, 
-            true,  true,  true,  true,  true,  true,  true,  true, 
-            true,  true,  true,  false, false, false, false, false 
-        };
-
-    /**
-     * ' ' | '"' | '#' | '+' | ',' | [0-9] | ';' | '<' | '=' | '>' | [A-F] | '\' | [a-f]
-     * 0x22 | 0x23 | 0x2B | 0x2C | [0x30-0x39] | 0x3B | 0x3C | 0x3D | 0x3E |
-     * [0x41-0x46] | 0x5C | [0x61-0x66]
-     */
-    private static final boolean[] PAIR_CHAR =
-        { 
-            false, false, false, false, false, false, false, false, // 00 -> 07
-            false, false, false, false, false, false, false, false, // 08 -> 0F
-            false, false, false, false, false, false, false, false, // 10 -> 17
-            false, false, false, false, false, false, false, false, // 18 -> 1F
-            true,  false, true,  true,  false, false, false, false, // 20 -> 27 ( ' ', '"', '#' )
-            false, false, false, true,  true,  false, false, false, // 28 -> 2F ( '+', ',' )
-            true,  true,  true,  true,  true,  true,  true,  true,  // 30 -> 37 ( '0'..'7' )
-            true,  true,  false, true,  true,  true,  true,  false, // 38 -> 3F ( '8', '9', ';', '<', '=', '>' ) 
-            false, true,  true,  true,  true,  true,  true,  false, // 40 -> 47 ( 'A', 'B', 'C', 'D', 'E', 'F' )
-            false, false, false, false, false, false, false, false, // 48 -> 4F
-            false, false, false, false, false, false, false, false, // 50 -> 57
-            false, false, false, false, true,  false, false, false, // 58 -> 5F ( '\' )
-            false, true,  true,  true,  true,  true,  true,  false, // 60 -> 67 ( 'a', 'b', 'c', 'd', 'e', 'f' )
-            false, false, false, false, false, false, false, false, // 68 -> 6F
-            false, false, false, false, false, false, false, false, // 70 -> 77
-            false, false, false, false, false, false, false, false  // 78 -> 7F
-        };
-
-
-    /**
-     * [0x01-0x1F] | 0x21 | [0x24-0x2A] | [0x2D-0x3A] | 0x3D | [0x3F-0x5B] | [0x5D-0x7F]
-     */
-    private static final boolean[] LUTF1 =
-        { 
-            false, true,  true,  true,  true,  true,  true,  true, // 00 -> 07 '\0'
-            true,  true,  true,  true,  true,  true,  true,  true, // 08 -> 0F
-            true,  true,  true,  true,  true,  true,  true,  true, // 10 -> 17
-            true,  true,  true,  true,  true,  true,  true,  true, // 18 -> 1F
-            false, true,  false, false, true,  true,  true,  true, // 20 -> 27 ( ' ', '"', '#' )
-            true,  true,  true,  false, false, true,  true,  true, // 28 -> 2F ( '+', ',' )
-            true,  true,  true,  true,  true,  true,  true,  true, // 30 -> 37 
-            true,  true,  true,  false, false, true,  false, true, // 38 -> 3F ( ';', '<', '>' ) 
-            true,  true,  true,  true,  true,  true,  true,  true, // 40 -> 47 
-            true,  true,  true,  true,  true,  true,  true,  true, // 48 -> 4F
-            true,  true,  true,  true,  true,  true,  true,  true, // 50 -> 57
-            true,  true,  true,  true,  false, true,  true,  true, // 58 -> 5F ( '\' )
-            true,  true,  true,  true,  true,  true,  true,  true, // 60 -> 67 
-            true,  true,  true,  true,  true,  true,  true,  true, // 68 -> 6F
-            true,  true,  true,  true,  true,  true,  true,  true, // 70 -> 77
-            true,  true,  true,  true,  true,  true,  true,  true  // 78 -> 7F
-        };
-
-
-    /**
-     * [0x01-0x21] | [0x23-0x2A] | [0x2D-0x3A] | 0x3D | [0x3F-0x5B] | [0x5D-0x7F]
-     */
-    private static final boolean[] SUTF1 =
-        { 
-            false, true,  true,  true,  true,  true,  true,  true, // 00 -> 07 '\0'
-            true,  true,  true,  true,  true,  true,  true,  true, // 08 -> 0F
-            true,  true,  true,  true,  true,  true,  true,  true, // 10 -> 17
-            true,  true,  true,  true,  true,  true,  true,  true, // 18 -> 1F
-            true,  true,  false, true,  true,  true,  true,  true, // 20 -> 27 ( '"' )
-            true,  true,  true,  false, false, true,  true,  true, // 28 -> 2F ( '+', ',' )
-            true,  true,  true,  true,  true,  true,  true,  true, // 30 -> 37 
-            true,  true,  true,  false, false, true,  false, true, // 38 -> 3F ( ';', '<', '>' ) 
-            true,  true,  true,  true,  true,  true,  true,  true, // 40 -> 47 
-            true,  true,  true,  true,  true,  true,  true,  true, // 48 -> 4F
-            true,  true,  true,  true,  true,  true,  true,  true, // 50 -> 57
-            true,  true,  true,  true,  false, true,  true,  true, // 58 -> 5F ( '\' )
-            true,  true,  true,  true,  true,  true,  true,  true, // 60 -> 67 
-            true,  true,  true,  true,  true,  true,  true,  true, // 68 -> 6F
-            true,  true,  true,  true,  true,  true,  true,  true, // 70 -> 77
-            true,  true,  true,  true,  true,  true,  true,  true  // 78 -> 7F
-        };
-
-
-    /**
-     * ' ' | '"' | '#' | '+' | ',' | ';' | '<' | '=' | '>' | '\' |
-     * 0x22 | 0x23 | 0x2B | 0x2C | 0x3B | 0x3C | 0x3D | 0x3E | 0x5C
-     */
-    private static final boolean[] PAIR_CHAR_ONLY =
-        { 
-            false, false, false, false, false, false, false, false, // 00 -> 07
-            false, false, false, false, false, false, false, false, // 08 -> 0F
-            false, false, false, false, false, false, false, false, // 10 -> 17
-            false, false, false, false, false, false, false, false, // 18 -> 1F
-            true,  false, true,  true,  false, false, false, false, // 20 -> 27 ( ' ', '"', '#' )
-            false, false, false, true,  true,  false, false, false, // 28 -> 2F ( '+', ',' )
-            false, false, false, false, false, false, false, false, // 30 -> 37
-            false, false, false, true,  true,  true,  true,  false, // 38 -> 3F ( ';', '<', '=', '>' ) 
-            false, false, false, false, false, false, false, false, // 40 -> 47
-            false, false, false, false, false, false, false, false, // 48 -> 4F
-            false, false, false, false, false, false, false, false, // 50 -> 57
-            false, false, false, false, true,  false, false, false, // 58 -> 5F ( '\' )
-            false, false, false, false, false, false, false, false, // 60 -> 67
-            false, false, false, false, false, false, false, false, // 68 -> 6F
-            false, false, false, false, false, false, false, false, // 70 -> 77
-            false, false, false, false, false, false, false, false  // 78 -> 7F
-        };
-
-    /**
-     * '"' | '#' | '+' | ',' | [0-9] | ';' | '<' | '=' | '>' | [A-F] | '\' |
-     * [a-f] 0x22 | 0x23 | 0x2B | 0x2C | [0x30-0x39] | 0x3B | 0x3C | 0x3D | 0x3E |
-     * [0x41-0x46] | 0x5C | [0x61-0x66]
-     */
-    private static final int[] STRING_CHAR =
-        { 
-            ONE_CHAR,      ONE_CHAR,      ONE_CHAR,      ONE_CHAR,     // 00 -> 03
-            ONE_CHAR,      ONE_CHAR,      ONE_CHAR,      ONE_CHAR,     // 04 -> 07
-            ONE_CHAR,      ONE_CHAR,      PARSING_ERROR, ONE_CHAR,     // 08 -> 0B
-            ONE_CHAR,      PARSING_ERROR, ONE_CHAR,      ONE_CHAR,     // 0C -> 0F
-            ONE_CHAR,      ONE_CHAR,      ONE_CHAR,      ONE_CHAR,     // 10 -> 13
-            ONE_CHAR,      ONE_CHAR,      ONE_CHAR,      ONE_CHAR,     // 14 -> 17
-            ONE_CHAR,      ONE_CHAR,      ONE_CHAR,      ONE_CHAR,     // 18 -> 1B
-            ONE_CHAR,      ONE_CHAR,      ONE_CHAR,      ONE_CHAR,     // 1C -> 1F
-            ONE_CHAR,      ONE_CHAR,      PARSING_ERROR, ONE_CHAR,     // 20 -> 23
-            ONE_CHAR,      ONE_CHAR,      ONE_CHAR,      ONE_CHAR,     // 24 -> 27
-            ONE_CHAR,      ONE_CHAR,      ONE_CHAR,      PARSING_ERROR,// 28 -> 2B
-            PARSING_ERROR, ONE_CHAR,      ONE_CHAR,      ONE_CHAR,     // 2C -> 2F
-            ONE_CHAR,      ONE_CHAR,      ONE_CHAR,      ONE_CHAR,     // 30 -> 33
-            ONE_CHAR,      ONE_CHAR,      ONE_CHAR,      ONE_CHAR,     // 34 -> 37
-            ONE_CHAR,      ONE_CHAR,      ONE_CHAR,      PARSING_ERROR,// 38 -> 3B
-            PARSING_ERROR, ONE_CHAR,      PARSING_ERROR, ONE_CHAR      // 3C -> 3F
-        };
-
-    /** "oid." static */
-    public static final String OID_LOWER = "oid.";
-
-    /** "OID." static */
-    public static final String OID_UPPER = "OID.";
-    public static final String[] EMPTY_STRING_ARRAY = new String[0];
-
-
-    /**
-     * Private constructor.
-     */
-    private DnUtils()
-    {
-    }
-
-
-    // ~ Methods
-    // ------------------------------------------------------------------------------------
-
-    /**
-     * Walk the buffer while characters are Safe String characters :
-     * &lt;safe-string&gt; ::= &lt;safe-init-char&gt; &lt;safe-chars&gt; &lt;safe-init-char&gt; ::=
-     * [0x01-0x09] | 0x0B | 0x0C | [0x0E-0x1F] | [0x21-0x39] | 0x3B |
-     * [0x3D-0x7F] &lt;safe-chars&gt; ::= &lt;safe-char&gt; &lt;safe-chars&gt; | &lt;safe-char&gt; ::=
-     * [0x01-0x09] | 0x0B | 0x0C | [0x0E-0x7F]
-     * 
-     * @param bytes The buffer which contains the data
-     * @param index Current position in the buffer
-     * @return The position of the first character which is not a Safe Char
-     */
-    public static int parseSafeString( byte[] bytes, int index )
-    {
-        if ( ( bytes == null ) || ( bytes.length == 0 ) || ( index < 0 ) || ( index >= bytes.length ) )
-        {
-            return -1;
-        }
-        else
-        {
-            byte c = bytes[index];
-
-            if ( ( ( c | 0x7F ) != 0x7F ) || ( !SAFE_INIT_CHAR[c] ) )
-            {
-                return -1;
-            }
-
-            index++;
-
-            while ( index < bytes.length )
-            {
-                c = bytes[index];
-
-                if ( ( ( c | 0x7F ) != 0x7F ) || ( !SAFE_CHAR[c] ) )
-                {
-                    break;
-                }
-
-                index++;
-            }
-
-            return index;
-        }
-    }
-
-
-    /**
-     * Walk the buffer while characters are Alpha characters : &lt;alpha&gt; ::=
-     * [0x41-0x5A] | [0x61-0x7A]
-     * 
-     * @param bytes The buffer which contains the data
-     * @param index Current position in the buffer
-     * @return The position of the first character which is not an Alpha Char
-     */
-    public static int parseAlphaASCII( byte[] bytes, int index )
-    {
-        if ( ( bytes == null ) || ( bytes.length == 0 ) || ( index < 0 ) || ( index >= bytes.length ) )
-        {
-            return -1;
-        }
-        else
-        {
-            byte b = bytes[index++];
-
-            if ( Chars.isAlpha(b) )
-            {
-                return index-1;
-            }
-            else
-            {
-                return -1;
-            }
-        }
-    }
-    
-    
-    /**
-     * Check if the current character is a LUTF1 (Lead UTF ascii char)<br/> 
-     * &lt;LUTF1&gt; ::= 0x01-1F | 0x21 | 0x24-2A | 0x2D-3A | 0x3D | 0x3F-5B | 0x5D-7F
-     * 
-     * @param bytes The buffer containing the data
-     * @param index Current position in the buffer
-     * @return <code>true</code> if the current character is a LUTF1
-     */
-    public static boolean isLUTF1( byte[] bytes, int index )
-    {
-        if ( ( bytes == null ) || ( bytes.length == 0 ) || ( index < 0 ) || ( index >= bytes.length ) )
-        {
-            return false;
-        }
-
-        byte c = bytes[index];
-        return ( ( ( c | 0x7F ) == 0x7F ) && LUTF1[c & 0x7f] );
-    }
-
-    
-    /**
-     * Check if the current character is a SUTF1 (Stringchar UTF ascii char)<br/> 
-     * &lt;LUTF1&gt; ::= 0x01-20 | 0x23-2A | 0x2D-3A | 0x3D | 0x3F-5B | 0x5D-7F
-     * 
-     * @param bytes The buffer containing the data
-     * @param index Current position in the buffer
-     * @return <code>true</code> if the current character is a SUTF1
-     */
-    public static boolean isSUTF1( byte[] bytes, int index )
-    {
-        if ( ( bytes == null ) || ( bytes.length == 0 ) || ( index < 0 ) || ( index >= bytes.length ) )
-        {
-            return false;
-        }
-
-        byte c = bytes[index];
-        return ( ( ( c | 0x7F ) == 0x7F ) && SUTF1[c & 0x7f] );
-    }
-
-    
-    /**
-     * Check if the given char is a pair char only
-     * &lt;pairCharOnly&gt; ::= ' ' | ',' | '=' | '+' | '<' | '>' | '#' | ';' | '\' | '"'
-     *
-     * @param c the char we want to test
-     * @return true if the char is a pair char only
-     */
-    public static boolean isPairCharOnly( char c )
-    {
-        return ( ( ( c | 0x7F ) == 0x7F ) && PAIR_CHAR_ONLY[c & 0x7f] );
-    }
-
-
-    /**
-     * Check if the current character is a Pair Char 
-     * &lt;pairchar&gt; ::= ' ' | ',' | '=' | '+' | '<' | '>' | '#' | ';' | '\' | '"' | [0-9a-fA-F] [0-9a-fA-F]
-     * 
-     * @param bytes The buffer which contains the data
-     * @param index Current position in the buffer
-     * @return <code>true</code> if the current character is a Pair Char
-     */
-    public static boolean isPairChar( byte[] bytes, int index )
-    {
-        if ( ( bytes == null ) || ( bytes.length == 0 ) || ( index < 0 ) || ( index >= bytes.length ) )
-        {
-            return false;
-        }
-        else
-        {
-            byte c = bytes[index];
-
-            if ( ( ( c | 0x7F ) != 0x7F )  || ( !PAIR_CHAR[c] ) )
-            {
-                return false;
-            }
-            else
-            {
-                if ( PAIR_CHAR_ONLY[c] )
-                {
-                    return true;
-                }
-                else if ( Chars.isHex(bytes, index++) )
-                {
-                    return Chars.isHex(bytes, index);
-                }
-                else
-                {
-                    return false;
-                }
-            }
-        }
-    }
-
-
-    /**
-     * Check if the current character is a Pair Char 
-     * 
-     * &lt;pairchar&gt; ::= ' ' | ',' | '=' | '+' | '<' | '>' | '#' | ';' | 
-     *                  '\' | '"' | [0-9a-fA-F] [0-9a-fA-F]
-     * 
-     * @param bytes The byte array which contains the data
-     * @param index Current position in the byte array
-     * @return <code>true</code> if the current byte is a Pair Char
-     */
-    public static int countPairChar( byte[] bytes, int index )
-    {
-        if ( bytes == null )
-        {
-            return PARSING_ERROR;
-        }
-
-        int length = bytes.length;
-        
-        if ( ( length == 0 ) || ( index < 0 ) || ( index >= length ) )
-        {
-            return PARSING_ERROR;
-        }
-        else
-        {
-            byte c = bytes[index];
-
-            if ( ( ( c | 0x7F ) != 0x7F )  || ( !PAIR_CHAR[c] ) )
-            {
-                return PARSING_ERROR;
-            }
-            else
-            {
-                if ( PAIR_CHAR_ONLY[c] )
-                {
-                    return 1;
-                }
-                else if ( Chars.isHex(bytes, index++) )
-                {
-                    return Chars.isHex(bytes, index) ? 2 : PARSING_ERROR;
-                }
-                else
-                {
-                    return PARSING_ERROR;
-                }
-            }
-        }
-    }
-
-
-    /**
-     * Check if the current character is a String Char. Chars are Unicode, not
-     * ASCII. &lt;stringchar&gt; ::= [0x00-0xFFFF] - [,=+<>#;\"\n\r]
-     * 
-     * @param bytes The buffer which contains the data
-     * @param index Current position in the buffer
-     * @return The current char if it is a String Char, or '#' (this is simpler
-     *         than throwing an exception :)
-     */
-    public static int isStringChar( byte[] bytes, int index )
-    {
-        if ( ( bytes == null ) || ( bytes.length == 0 ) || ( index < 0 ) || ( index >= bytes.length ) )
-        {
-            return -1;
-        }
-        else
-        {
-            byte c = bytes[index];
-
-            if ( ( c | 0x3F ) == 0x3F )
-            {
-                return STRING_CHAR[ c ];
-            }
-            else
-            {
-                return Unicode.countBytesPerChar(bytes, index);
-            }
-        }
-    }
-
-
-    /**
-     * Check if the current character is an ascii String Char.<br/>
-     * <p> 
-     * &lt;asciistringchar&gt; ::= [0x00-0x7F] - [,=+<>#;\"\n\r]
-     * </p>
-     * 
-     * @param bytes The buffer which contains the data
-     * @param index Current position in the buffer
-     * @return The current char if it is a String Char, or '#' (this is simpler
-     *         than throwing an exception :)
-     */
-    public static int isAciiStringChar( byte[] bytes, int index )
-    {
-        if ( ( bytes == null ) || ( bytes.length == 0 ) || ( index < 0 ) || ( index >= bytes.length ) )
-        {
-            return -1;
-        }
-        else
-        {
-            byte c = bytes[index];
-
-            if ( ( c | 0x3F ) == 0x3F )
-            {
-                return STRING_CHAR[ c ];
-            }
-            else
-            {
-                return Unicode.countBytesPerChar(bytes, index);
-            }
-        }
-    }
-
-
-    /**
-     * Check if the current character is a Quote Char We are testing Unicode
-     * chars &lt;quotechar&gt; ::= [0x00-0xFFFF] - [\"]
-     * 
-     * @param bytes The buffer which contains the data
-     * @param index Current position in the buffer
-     *
-     * @return <code>true</code> if the current character is a Quote Char
-     */
-    public static int isQuoteChar( byte[] bytes, int index )
-    {
-        if ( ( bytes == null ) || ( bytes.length == 0 ) || ( index < 0 ) || ( index >= bytes.length ) )
-        {
-            return -1;
-        }
-        else
-        {
-            byte c = bytes[index];
-
-            if ( ( c == '\\' ) || ( c == '"' ) )
-            {
-                return -1;
-            }
-            else
-            {
-                return Unicode.countBytesPerChar(bytes, index);
-            }
-        }
-    }
-
-
-    /**
-     * Parse an hex pair &lt;hexpair&gt; ::= &lt;hex&gt; &lt;hex&gt;
-     * 
-     * @param bytes The buffer which contains the data
-     * @param index Current position in the buffer
-     * @return The new position, -1 if the buffer does not contain an HexPair,
-     *         -2 if the buffer contains an hex byte but not two.
-     */
-    public static int parseHexPair( byte[] bytes, int index )
-    {
-        if ( Chars.isHex(bytes, index) )
-        {
-            if ( Chars.isHex(bytes, index + 1) )
-            {
-                return index + 2;
-            }
-            else
-            {
-                return -2;
-            }
-        }
-        else
-        {
-            return -1;
-        }
-    }
-
-
-    /**
-     * Parse an hex pair &lt;hexpair&gt; ::= &lt;hex&gt; &lt;hex&gt;
-     * 
-     * @param bytes The byte array which contains the data
-     * @param index Current position in the byte array
-     * @return The new position, -1 if the byte array does not contain an HexPair,
-     *         -2 if the byte array contains an hex byte but not two.
-     */
-    private static byte getHexPair( byte[] bytes, int index )
-    {
-        return Hex.getHexValue(bytes[index], bytes[index + 1]);
-    }
-
-    
     /**
-     * Parse an hex string, which is a list of hex pairs &lt;hexstring&gt; ::=
-     * &lt;hexpair&gt; &lt;hexpairs&gt; &lt;hexpairs&gt; ::= &lt;hexpair&gt; &lt;hexpairs&gt; | e
-     * 
-     * @param bytes The buffer which contains the data
-     * @param index Current position in the buffer
-     * @return Return the first position which is not an hex pair, or -1 if
-     *         there is no hexpair at the beginning or if an hexpair is invalid
-     *         (if we have only one hex instead of 2)
-     */
-    public static int parseHexString( byte[] bytes, int index )
-    {
-        int result = parseHexPair( bytes, index );
-
-        if ( result < 0 )
-        {
-            return -1;
-        }
-        else
-        {
-            index += 2;
-        }
-
-        while ( ( result = parseHexPair( bytes, index ) ) >= 0 )
-        {
-            index += 2;
-        }
-
-        return ( ( result == -2 ) ? -1 : index );
-    }
-
-
-    /**
-     * Parse an hex string, which is a list of hex pairs &lt;hexstring&gt; ::=
-     * &lt;hexpair&gt; &lt;hexpairs&gt; &lt;hexpairs&gt; ::= &lt;hexpair&gt; &lt;hexpairs&gt; | e
-     * 
-     * @param bytes The byte array which contains the data
-     * @param hex The result as a byte array
-     * @param pos Current position in the string
-     * @return Return the first position which is not an hex pair, or -1 if
-     *         there is no hexpair at the beginning or if an hexpair is invalid
-     *         (if we have only one hex instead of 2)
-     */
-    public static int parseHexString( byte[] bytes, byte[] hex, Position pos )
-    {
-        int i = 0;
-        pos.end = pos.start;
-        int result = parseHexPair( bytes, pos.start );
-
-        if ( result < 0 )
-        {
-            return PARSING_ERROR;
-        }
-        else
-        {
-            hex[i++] = getHexPair( bytes, pos.end );
-            pos.end += TWO_CHARS;
-        }
-
-        while ( ( result = parseHexPair( bytes, pos.end ) ) >= 0 )
-        {
-            hex[i++] = getHexPair( bytes, pos.end );
-            pos.end += TWO_CHARS;
-        }
-
-        return ( ( result == BAD_HEX_PAIR ) ? PARSING_ERROR : PARSING_OK );
-    }
-
-    
-    /**
-     * Walk the buffer while characters are Base64 characters : &lt;base64-string&gt;
-     * ::= &lt;base64-char&gt; &lt;base64-chars&gt; &lt;base64-chars&gt; ::= &lt;base64-char&gt;
-     * &lt;base64-chars&gt; | &lt;base64-char&gt; ::= 0x2B | 0x2F | [0x30-0x39] | 0x3D |
-     * [0x41-0x5A] | [0x61-0x7A]
-     * 
-     * @param bytes The buffer which contains the data
-     * @param index Current position in the buffer
-     * @return The position of the first character which is not a Base64 Char
-     */
-    public static int parseBase64String( byte[] bytes, int index )
-    {
-        if ( ( bytes == null ) || ( bytes.length == 0 ) || ( index < 0 ) || ( index >= bytes.length ) )
-        {
-            return -1;
-        }
-        else
-        {
-            byte c = bytes[index];
-
-            if ( ( ( c | 0x7F ) != 0x7F )  || ( !BASE64_CHAR[c] ) )
-            {
-                return -1;
-            }
-
-            index++;
-
-            while ( index < bytes.length )
-            {
-                c = bytes[index];
-
-                if ( ( ( c | 0x7F ) != 0x7F )  || ( !BASE64_CHAR[c] ) )
-                {
-                    break;
-                }
-
-                index++;
-            }
-
-            return index;
-        }
-    }
-
-    /**
-     * Gets the attribute of a single attribute rdn or name component.
+     * Gets the attributeType of a RDN (the left part of the RDN). The RDN is supposed
+     * to contain only one AVA.
      *
-     * @param rdn the name component
-     * @return the attribute name TODO the name rdn is misused rename refactor
-     *         this method
+     * @param rdn the RDN
+     * @return the attributeType 
      */
-    public static String getRdnAttribute( String rdn )
+    public static String getRdnAttributeType( String rdn )
     {
         int index = rdn.indexOf( '=' );
         return rdn.substring( 0, index );
     }
 
     /**
-     * Gets the value of a single name component of a distinguished name.
+     * Gets the value of a RDN ( the right part of the RDN). The RDN is supposed
+     * to contain only one AVA.
      *
-     * @param rdn the name component to get the value from
-     * @return the value of the single name component TODO the name rdn is
-     *         misused rename refactor this method
+     * @param rdn the RDN
+     * @return the value of tpart of the RDN
      */
     public static String getRdnValue( String rdn )
     {
         int index = rdn.indexOf( '=' );
         return rdn.substring( index + 1, rdn.length() );
     }
-
-
-    /**
-     * Gets the '+' appended components of a composite name component.
-     *
-     * @param compositeNameComponent a single name component not a whole name
-     * @return the components of the complex name component in order
-     * @throws org.apache.directory.shared.ldap.model.exception.LdapInvalidDnException
-     *             if nameComponent is invalid (starts with a +)
-     */
-    public static String[] getCompositeComponents( String compositeNameComponent ) throws LdapInvalidDnException
-    {
-        int lastIndex = compositeNameComponent.length() - 1;
-        List<String> comps = new ArrayList<String>();
-
-        for ( int ii = compositeNameComponent.length() - 1; ii >= 0; ii-- )
-        {
-            if ( compositeNameComponent.charAt( ii ) == '+' )
-            {
-                if ( ii == 0 )
-                {
-                    throw new LdapInvalidDnException( I18n.err( I18n.ERR_04418, compositeNameComponent ) );
-                }
-
-                if ( compositeNameComponent.charAt( ii - 1 ) != '\\' )
-                {
-                    if ( lastIndex == compositeNameComponent.length() - 1 )
-                    {
-                        comps.add( 0, compositeNameComponent.substring( ii + 1, lastIndex + 1 ) );
-                    }
-                    else
-                    {
-                        comps.add( 0, compositeNameComponent.substring( ii + 1, lastIndex ) );
-                    }
-
-                    lastIndex = ii;
-                }
-            }
-
-            if ( ii == 0 )
-            {
-                if ( lastIndex == compositeNameComponent.length() - 1 )
-                {
-                    comps.add( 0, compositeNameComponent );
-                }
-                else
-                {
-                    comps.add( 0, compositeNameComponent.substring( ii, lastIndex ) );
-                }
-
-                lastIndex = 0;
-            }
-        }
-
-        if ( comps.size() == 0 )
-        {
-            comps.add( compositeNameComponent );
-        }
-
-        return comps.toArray( EMPTY_STRING_ARRAY );
-    }
 }

Modified: directory/shared/trunk/util/src/test/java/org/apache/directory/shared/util/StringsTest.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/util/src/test/java/org/apache/directory/shared/util/StringsTest.java?rev=1084289&r1=1084288&r2=1084289&view=diff
==============================================================================
--- directory/shared/trunk/util/src/test/java/org/apache/directory/shared/util/StringsTest.java (original)
+++ directory/shared/trunk/util/src/test/java/org/apache/directory/shared/util/StringsTest.java Tue Mar 22 18:36:29 2011
@@ -29,14 +29,15 @@ import java.util.List;
 import java.util.Map;
 import java.util.UUID;
 
-import com.mycila.junit.concurrent.Concurrency;
-import com.mycila.junit.concurrent.ConcurrentJunitRunner;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 
+import com.mycila.junit.concurrent.Concurrency;
+import com.mycila.junit.concurrent.ConcurrentJunitRunner;
+
 
 /**
- * Tests the StringTools class methods.
+ * Tests the Strings class methods.
  * 
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  */
@@ -198,4 +199,128 @@ public class StringsTest
         String string = Strings.uuidToString(bytes);
         assertEquals( uuid.toString(), string );
     }
+    /**
+     * Test the DnUtils AreEquals method
+     */
+    @Test
+    public void testAreEqualsFull()
+    {
+        // Full compare
+        assertEquals( 6, Strings.areEquals("azerty".getBytes(), 0, "azerty") );
+    }
+
+
+    /**
+     * Test the DnUtils AreEquals method
+     */
+    @Test
+    public void testAreEqualsDiff()
+    {
+        // First character is !=
+        assertEquals( -1, Strings.areEquals( "azerty".getBytes(), 0, "Azerty" ) );
+    }
+
+
+    /**
+     * Test the DnUtils AreEquals method
+     */
+    @Test
+    public void testAreEqualsEmpty()
+    {
+        // Compare to an empty string
+        assertEquals( -1, Strings.areEquals( "azerty".getBytes(), 0, "" ) );
+    }
+
+
+    /**
+     * Test the DnUtils AreEquals method
+     */
+    @Test
+    public void testAreEqualsFirstCharDiff()
+    {
+        // First character is !=
+        assertEquals( -1, Strings.areEquals( "azerty".getBytes(), 0, "Azerty" ) );
+    }
+
+
+    /**
+     * Test the DnUtils AreEquals method
+     */
+    @Test
+    public void testAreEqualsMiddleCharDiff()
+    {
+        // First character is !=
+        assertEquals( -1, Strings.areEquals( "azerty".getBytes(), 0, "azeRty" ) );
+    }
+
+
+    /**
+     * Test the DnUtils AreEquals method
+     */
+    @Test
+    public void testAreEqualsLastCharDiff()
+    {
+        // First character is !=
+        assertEquals( -1, Strings.areEquals( "azerty".getBytes(), 0, "azertY" ) );
+    }
+
+
+    /**
+     * Test the DnUtils AreEquals method
+     */
+    @Test
+    public void testAreEqualsCharByChar()
+    {
+        // Index must be incremented after each comparison
+        assertEquals( 1, Strings.areEquals( "azerty".getBytes(), 0, "a" ) );
+        assertEquals( 2, Strings.areEquals( "azerty".getBytes(), 1, "z" ) );
+        assertEquals( 3, Strings.areEquals( "azerty".getBytes(), 2, "e" ) );
+        assertEquals( 4, Strings.areEquals( "azerty".getBytes(), 3, "r" ) );
+        assertEquals( 5, Strings.areEquals( "azerty".getBytes(), 4, "t" ) );
+        assertEquals( 6, Strings.areEquals( "azerty".getBytes(), 5, "y" ) );
+    }
+
+
+    /**
+     * Test the DnUtils AreEquals method
+     */
+    @Test
+    public void testAreEqualsTooShort()
+    {
+        // length too short
+        assertEquals( -1, Strings.areEquals( "azerty".getBytes(), 0, "azertyiop" ) );
+    }
+
+
+    /**
+     * Test the DnUtils AreEquals method
+     */
+    @Test
+    public void testAreEqualsTooShortMiddle()
+    {
+        // length too short
+        assertEquals( -1, Strings.areEquals( "azerty".getBytes(), 0, "ertyiop" ) );
+    }
+
+
+    /**
+     * Test the DnUtils AreEquals method
+     */
+    @Test
+    public void testAreEqualsLastChar()
+    {
+        // last character
+        assertEquals( 6, Strings.areEquals( "azerty".getBytes(), 5, "y" ) );
+    }
+
+
+    /**
+     * Test the DnUtils AreEquals method
+     */
+    @Test
+    public void testAreEqualsMiddle()
+    {
+        // In the middle
+        assertEquals( 4, Strings.areEquals( "azerty".getBytes(), 2, "er" ) );
+    }
 }