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 2006/12/13 19:06:40 UTC

svn commit: r486780 - in /directory/branches/shared/0.9.5/ldap/src: main/java/org/apache/directory/shared/ldap/name/ main/java/org/apache/directory/shared/ldap/util/ test/java/org/apache/directory/shared/ldap/name/

Author: elecharny
Date: Wed Dec 13 10:06:39 2006
New Revision: 486780

URL: http://svn.apache.org/viewvc?view=rev&rev=486780
Log:
Commited the fix for DIRSERVER-796 which was applied to 1.5-trunks, after having removed java 1.5 constructions

Modified:
    directory/branches/shared/0.9.5/ldap/src/main/java/org/apache/directory/shared/ldap/name/AttributeTypeAndValue.java
    directory/branches/shared/0.9.5/ldap/src/main/java/org/apache/directory/shared/ldap/name/LdapDN.java
    directory/branches/shared/0.9.5/ldap/src/main/java/org/apache/directory/shared/ldap/name/Rdn.java
    directory/branches/shared/0.9.5/ldap/src/main/java/org/apache/directory/shared/ldap/name/RdnParser.java
    directory/branches/shared/0.9.5/ldap/src/main/java/org/apache/directory/shared/ldap/util/DNUtils.java
    directory/branches/shared/0.9.5/ldap/src/test/java/org/apache/directory/shared/ldap/name/DnParserDIRSERVER_584_Test.java
    directory/branches/shared/0.9.5/ldap/src/test/java/org/apache/directory/shared/ldap/name/LdapDNTest.java
    directory/branches/shared/0.9.5/ldap/src/test/java/org/apache/directory/shared/ldap/name/LdapDnParserTest.java
    directory/branches/shared/0.9.5/ldap/src/test/java/org/apache/directory/shared/ldap/name/RdnTest.java

Modified: directory/branches/shared/0.9.5/ldap/src/main/java/org/apache/directory/shared/ldap/name/AttributeTypeAndValue.java
URL: http://svn.apache.org/viewvc/directory/branches/shared/0.9.5/ldap/src/main/java/org/apache/directory/shared/ldap/name/AttributeTypeAndValue.java?view=diff&rev=486780&r1=486779&r2=486780
==============================================================================
--- directory/branches/shared/0.9.5/ldap/src/main/java/org/apache/directory/shared/ldap/name/AttributeTypeAndValue.java (original)
+++ directory/branches/shared/0.9.5/ldap/src/main/java/org/apache/directory/shared/ldap/name/AttributeTypeAndValue.java Wed Dec 13 10:06:39 2006
@@ -47,463 +47,536 @@
  */
 public class AttributeTypeAndValue implements Cloneable, Comparable, Serializable
 {
-   /**
-    * Declares the Serial Version Uid.
-    *
-    * @see <a
-    *      href="http://c2.com/cgi/wiki?AlwaysDeclareSerialVersionUid">Always
-    *      Declare Serial Version Uid</a>
-    */
-   private static final long serialVersionUID = 1L;
-
-   /** The LoggerFactory used by this class */
-   private static Logger log = LoggerFactory.getLogger( AttributeTypeAndValue.class );
-
-   /** The Name type */
-   private String type;
-
-   /** The name value. It can be a String or a byte array */
-   private Object value;
-
-   /** The user provided atav */
-   private String upName;
-
-   /** The starting position of this atav in the given string from which
-    * we have extracted the upName */
-   private int start;
-
-   /** The length of this atav upName */
-   private int length;
-
-   /** Two values used for comparizon */
-   private static final boolean CASE_SENSITIVE = true;
-
-   private static final boolean CASE_INSENSITIVE = false;
-
-
-   /**
-    * Construct an empty AttributeTypeAndValue
-    */
-   public AttributeTypeAndValue()
-   {
-       type = null;
-       value = null;
-       upName = "";
-       start = -1;
-       length = 0;
-   }
-
-
-   /**
-    * Construct an AttributeTypeAndValue. The type and value are normalized :
-    * - the type is trimmed and lowercased
-    * - the value is trimmed
-    *
-    * @param type
-    *            The type
-    * @param value
-    *            the value
-    */
-   public AttributeTypeAndValue(String type, Object value) throws InvalidNameException
-   {
-       if ( StringTools.isEmpty( type ) || StringTools.isEmpty( type.trim() ) )
-       {
-           log.error( "The type cannot be empty or null" );
-           throw new InvalidNameException( "Null or empty type is not allowed" );
-       }
-
-       this.type = type.trim().toLowerCase();
-
-       if ( value instanceof String )
-       {
-               this.value =  StringTools.isEmpty( (String)value ) ? "" : value;
-       }
-       else
-       {
-               this.value = value;
-       }
-
-       upName = type + '=' + value;
-       start = 0;
-       length = upName.length();
-   }
-
-   /**
-    * Construct an AttributeTypeAndValue. The type and value are normalized :
-    * - the type is trimmed and lowercased
-    * - the value is trimmed
-    *
-    * @param type
-    *            The type
-    * @param value
-    *            the value
-    */
-   /*public AttributeTypeAndValue(String dn, int start, int length ) throws InvalidNameException
-   {
-       if ( StringTools.isEmpty( dn ) || StringTools.isEmpty( dn.trim() ) )
-       {
-           log.error( "The atav cannot be empty or null" );
-           throw new InvalidNameException( "Null or empty atav is not allowed" );
-       }
-
-       String atav = dn.substring( start, start + length );
-       String type = atav.substring( 0, atav.indexOf( '=' ) );
-       String value = dn.substring( start + type.length() + 1, start + length );
-
-       this.type = type.trim().toLowerCase();
-       this.value = StringTools.isEmpty( value ) ? "" : value.trim();
-       upName = atav;
-       this.start = start;
-       this.length = length;
-   }*/
-
-   /**
-    * Get the type of a AttributeTypeAndValue
-    *
-    * @return The type
-    */
-   public String getType()
-   {
-       return type;
-   }
-
-
-   /**
-    * Store the type
-    *
-    * @param type
-    *            The AttributeTypeAndValue type
-    */
-   public void setType( String type ) throws InvalidNameException
-   {
-       if ( StringTools.isEmpty( type ) || StringTools.isEmpty( type.trim() ) )
-       {
-           log.error( "The type cannot be empty or null" );
-           throw new InvalidNameException( "The AttributeTypeAndValue type cannot be null or empty " );
-       }
-
-       this.type = type.trim().toLowerCase();
-       upName = type + upName.substring( upName.indexOf( '=' ) );
-       start = -1;
-       length = upName.length();
-   }
-
-
-   /**
-    * Store the type, after having trimmed and lowercased it.
-    *
-    * @param type
-    *            The AttributeTypeAndValue type
-    */
-   public void setTypeNormalized( String type ) throws InvalidNameException
-   {
-       if ( StringTools.isEmpty( type ) || StringTools.isEmpty( type.trim() ) )
-       {
-           log.error( "The type cannot be empty or null" );
-           throw new InvalidNameException( "The AttributeTypeAndValue type cannot be null or empty " );
-       }
-
-       this.type = type.trim().toLowerCase();
-       upName = type + upName.substring( upName.indexOf( '=' ) );
-       start = -1;
-       length = upName.length();
-   }
-
-
-   /**
-    * Get the Value of a AttributeTypeAndValue
-    *
-    * @return The value
-    */
-   public Object getValue()
-   {
-       return value;
-   }
-
-
-   /**
-    * Store the value of a AttributeTypeAndValue.
-    *
-    * @param value
-    *            The value of the AttributeTypeAndValue
-    */
-   public void setValue( Object value )
-   {
-       if ( value instanceof String )
-       {
-               this.value = StringTools.isEmpty( (String)value ) ? "" : (String)value;
-       }
-       else
-       {
-               this.value = value;
-       }
-
-       upName = upName.substring( 0, upName.indexOf( '=' ) + 1 ) + value;
-       start = -1;
-       length = upName.length();
-   }
-
-   /**
-    * Get the upName length
-    *
-    * @return the upName length
-    */
-       public int getLength() {
-               return length;
-       }
-
-       /**
-        * get the position in the original upName where this atav starts.
-        *
-        * @return The starting position of this atav
-        */
-       public int getStart() {
-               return start;
-       }
-
-
-       /**
-        * Get the user provided form of this attribute type and value
-        *
-        * @return The user provided form of this atav
-        */
-       public String getUpName() {
-               return upName;
-       }
-
-   /**
-    * Store the value of a AttributeTypeAndValue, after having trimmed it.
-    *
-    * @param value
-    *            The value of the AttributeTypeAndValue
-    */
-   public void setValueNormalized( String value )
-   {
-       String newValue = StringTools.trim( value );
-
-       if ( StringTools.isEmpty( newValue ) )
-       {
-           this.value = "";
-       }
-       else
-       {
-           this.value = newValue;
-       }
-
-       upName = upName.substring( 0, upName.indexOf( '=' ) + 1 ) + value;
-       start = -1;
-       length = upName.length();
-   }
-
-
-   /**
-    * Implements the cloning.
-    *
-    * @return a clone of this object
-    */
-   public Object clone()
-   {
-       try
-       {
-           return super.clone();
-       }
-       catch ( CloneNotSupportedException cnse )
-       {
-           throw new Error( "Assertion failure" );
-       }
-   }
-
-
-   /**
-    * Compares two NameComponents. They are equals if : - types are equals,
-    * case insensitive, - values are equals, case sensitive
-    *
-    * @param object
-    * @return 0 if both NC are equals, otherwise a positive value if the
-    *         original NC is superior to the second one, a negative value if
-    *         the second NC is superior.
-    */
-   public int compareTo( Object object )
-   {
-       if ( object instanceof AttributeTypeAndValue )
-       {
-           AttributeTypeAndValue nc = ( AttributeTypeAndValue ) object;
-
-           int res = compareType( type, nc.type );
-
-           if ( res != 0 )
-           {
-               return res;
-           }
-           else
-           {
-               return compareValue( value, nc.value, CASE_SENSITIVE);
-           }
-       }
-       else
-       {
-           return 1;
-       }
-   }
-
-
-   /**
-    * Compares two NameComponents. They are equals if : - types are equals,
-    * case insensitive, - values are equals, case insensitive
-    *
-    * @param object
-    * @return 0 if both NC are equals, otherwise a positive value if the
-    *         original NC is superior to the second one, a negative value if
-    *         the second NC is superior.
-    */
-   public int compareToIgnoreCase( Object object )
-   {
-       if ( object instanceof AttributeTypeAndValue )
-       {
-           AttributeTypeAndValue nc = ( AttributeTypeAndValue ) object;
-
-           int res = compareType( type, nc.type );
-
-           if ( res != 0 )
-           {
-               return res;
-           }
-           else
-           {
-               return compareValue( value, nc.value, CASE_INSENSITIVE );
-           }
-       }
-       else
-       {
-           return 1;
-       }
-   }
-
-
-   /**
-    * Compare two types, trimed and case insensitive
-    *
-    * @param val1
-    *            First String
-    * @param val2
-    *            Second String
-    * @return true if both strings are equals or null.
-    */
-   private int compareType( String val1, String val2 )
-   {
-       if ( StringTools.isEmpty( val1 ) )
-       {
-           return StringTools.isEmpty( val2 ) ? 0 : -1;
-       }
-       else if ( StringTools.isEmpty( val2 ) )
-       {
-           return 1;
-       }
-       else
-       {
-           return ( StringTools.trim( val1 ) ).compareToIgnoreCase( StringTools.trim( val2 ) );
-       }
-   }
-
-
-   /**
-    * Compare two values
-    *
-    * @param val1
-    *            First String
-    * @param val2
-    *            Second String
-    * @return true if both strings are equals or null.
-    */
-   private int compareValue( Object val1, Object val2, boolean sensitivity )
-   {
-       if ( val1 instanceof String )
-       {
-               if ( val2 instanceof String )
-               {
-                       int val =  ( sensitivity == CASE_SENSITIVE ) ?
-                                               ((String)val1).compareTo( (String)val2 ) :
-                                               ((String)val1).compareToIgnoreCase( (String)val2 );
-
-                       return ( val < 0 ? -1 : ( val > 0 ? 1 : val ) );
-               }
-               else
-               {
-                       return 1;
-               }
-       }
-       else if ( val1 instanceof byte[] )
-       {
-               if ( Arrays.equals( (byte[])val1, (byte[])val2 ) )
-               {
-                       return 0;
-               }
-               else
-               {
-                       return 1;
-               }
-       }
-       else
-       {
-               return 1;
-       }
-   }
-
-
-   /**
-    * A Normalized String representation of a AttributeTypeAndValue : - type is
-    * trimed and lowercased - value is trimed and lowercased
-    *
-    * @return A normalized string representing a AttributeTypeAndValue
-    */
-   public String normalize()
-   {
-       if ( value instanceof String )
-       {
-               return StringTools.lowerCase( StringTools.trim( type ) ) + '=' + StringTools.trim( (String)value );
-       }
-       else
-       {
-               return StringTools.lowerCase( StringTools.trim( type ) ) + "=#" + StringTools.dumpHexPairs( (byte[])value );
-       }
-   }
-
-   /**
-    * Gets the hashcode of this object.
-    *
-    * @see java.lang.Object#hashCode()
-    */
-   public int hashCode()
-   {
-       int result = 17;
-
-       result = result * 37 + ( type != null ? type.hashCode() : 0 );
-       result = result * 37 + ( value != null ? type.hashCode() : 0 );
-
-       return result;
-   }
-
-   /**
-    * A String representation of a AttributeTypeAndValue.
-    *
-    * @return A string representing a AttributeTypeAndValue
-    */
-   public String toString()
-   {
-       StringBuffer sb = new StringBuffer();
-
-       if ( StringTools.isEmpty( type ) || StringTools.isEmpty( type.trim() ) )
-       {
-           return "";
-       }
-
-       sb.append( type ).append( "=" );
-
-       if ( value != null )
-       {
-           sb.append( value );
-       }
+    /**
+     * Declares the Serial Version Uid.
+     *
+     * @see <a
+     *      href="http://c2.com/cgi/wiki?AlwaysDeclareSerialVersionUid">Always
+     *      Declare Serial Version Uid</a>
+     */
+    private static final long serialVersionUID = 1L;
+
+    /** The LoggerFactory used by this class */
+    private static Logger log = LoggerFactory.getLogger( AttributeTypeAndValue.class );
+
+    /** The Name type */
+    private String type;
+
+    /** The name value. It can be a String or a byte array */
+    private Object value;
+
+    /** The user provided atav */
+    private String upName;
+
+    /** The starting position of this atav in the given string from which
+     * we have extracted the upName */
+    private int start;
+
+    /** The length of this atav upName */
+    private int length;
+
+    /** Two values used for comparizon */
+    private static final boolean CASE_SENSITIVE = true;
+
+    private static final boolean CASE_INSENSITIVE = false;
+
+
+    /**
+     * Construct an empty AttributeTypeAndValue
+     */
+    public AttributeTypeAndValue()
+    {
+        type = null;
+        value = null;
+        upName = "";
+        start = -1;
+        length = 0;
+    }
+
+
+    /**
+     * Construct an AttributeTypeAndValue. The type and value are normalized :
+     * - the type is trimmed and lowercased
+     * - the value is trimmed
+     *
+     * @param type
+     *            The type
+     * @param value
+     *            the value
+     */
+    public AttributeTypeAndValue( String type, Object value ) throws InvalidNameException
+    {
+        if ( StringTools.isEmpty( type ) || StringTools.isEmpty( type.trim() ) )
+        {
+            log.error( "The type cannot be empty or null" );
+            throw new InvalidNameException( "Null or empty type is not allowed" );
+        }
+
+        this.type = type.trim().toLowerCase();
+
+        if ( value instanceof String )
+        {
+            this.value = StringTools.isEmpty( ( String ) value ) ? "" : value;
+        }
+        else
+        {
+            this.value = value;
+        }
+
+        upName = type + '=' + value;
+        start = 0;
+        length = upName.length();
+    }
+
+
+    /**
+     * Get the type of a AttributeTypeAndValue
+     *
+     * @return The type
+     */
+    public String getType()
+    {
+        return type;
+    }
+
+
+    /**
+     * Store the type
+     *
+     * @param type
+     *            The AttributeTypeAndValue type
+     */
+    public void setType( String type ) throws InvalidNameException
+    {
+        if ( StringTools.isEmpty( type ) || StringTools.isEmpty( type.trim() ) )
+        {
+            log.error( "The type cannot be empty or null" );
+            throw new InvalidNameException( "The AttributeTypeAndValue type cannot be null or empty " );
+        }
+
+        this.type = type.trim().toLowerCase();
+        upName = type + upName.substring( upName.indexOf( '=' ) );
+        start = -1;
+        length = upName.length();
+    }
+
+
+    /**
+     * Store the type, after having trimmed and lowercased it.
+     *
+     * @param type
+     *            The AttributeTypeAndValue type
+     */
+    public void setTypeNormalized( String type ) throws InvalidNameException
+    {
+        if ( StringTools.isEmpty( type ) || StringTools.isEmpty( type.trim() ) )
+        {
+            log.error( "The type cannot be empty or null" );
+            throw new InvalidNameException( "The AttributeTypeAndValue type cannot be null or empty " );
+        }
+
+        this.type = type.trim().toLowerCase();
+        upName = type + upName.substring( upName.indexOf( '=' ) );
+        start = -1;
+        length = upName.length();
+    }
+
+
+    /**
+     * Get the Value of a AttributeTypeAndValue
+     *
+     * @return The value
+     */
+    public Object getValue()
+    {
+        return value;
+    }
+
+    /**
+     * Get the normalized Value of a AttributeTypeAndValue
+     *
+     * @return The value
+     */
+    public String getNormalizedValue()
+    {
+        return normalize();
+    }
+
+
+    /**
+     * Store the value of a AttributeTypeAndValue.
+     *
+     * @param value
+     *            The value of the AttributeTypeAndValue
+     */
+    public void setValue( Object value )
+    {
+        if ( value instanceof String )
+        {
+            this.value = StringTools.isEmpty( ( String ) value ) ? "" : ( String ) value;
+        }
+        else
+        {
+            this.value = value;
+        }
+
+        upName = upName.substring( 0, upName.indexOf( '=' ) + 1 ) + value;
+        start = -1;
+        length = upName.length();
+    }
+
+
+    /**
+     * Get the upName length
+     *
+     * @return the upName length
+     */
+    public int getLength()
+    {
+        return length;
+    }
+
+
+    /**
+     * get the position in the original upName where this atav starts.
+     *
+     * @return The starting position of this atav
+     */
+    public int getStart()
+    {
+        return start;
+    }
+
+
+    /**
+     * Get the user provided form of this attribute type and value
+     *
+     * @return The user provided form of this atav
+     */
+    public String getUpName()
+    {
+        return upName;
+    }
+
+
+    /**
+     * Store the value of a AttributeTypeAndValue, after having trimmed it.
+     *
+     * @param value
+     *            The value of the AttributeTypeAndValue
+     */
+    public void setValueNormalized( String value )
+    {
+        String newValue = StringTools.trim( value );
+
+        if ( StringTools.isEmpty( newValue ) )
+        {
+            this.value = "";
+        }
+        else
+        {
+            this.value = newValue;
+        }
+
+        upName = upName.substring( 0, upName.indexOf( '=' ) + 1 ) + value;
+        start = -1;
+        length = upName.length();
+    }
+
+
+    /**
+     * Implements the cloning.
+     *
+     * @return a clone of this object
+     */
+    public Object clone()
+    {
+        try
+        {
+            return super.clone();
+        }
+        catch ( CloneNotSupportedException cnse )
+        {
+            throw new Error( "Assertion failure" );
+        }
+    }
+
+
+    /**
+     * Compares two NameComponents. They are equals if : - types are equals,
+     * case insensitive, - values are equals, case sensitive
+     *
+     * @param object
+     * @return 0 if both NC are equals, otherwise a positive value if the
+     *         original NC is superior to the second one, a negative value if
+     *         the second NC is superior.
+     */
+    public int compareTo( Object object )
+    {
+        if ( object instanceof AttributeTypeAndValue )
+        {
+            AttributeTypeAndValue nc = ( AttributeTypeAndValue ) object;
+
+            int res = compareType( type, nc.type );
+
+            if ( res != 0 )
+            {
+                return res;
+            }
+            else
+            {
+                return compareValue( value, nc.value, CASE_SENSITIVE );
+            }
+        }
+        else
+        {
+            return 1;
+        }
+    }
+
+
+    /**
+     * Compares two NameComponents. They are equals if : - types are equals,
+     * case insensitive, - values are equals, case insensitive
+     *
+     * @param object
+     * @return 0 if both NC are equals, otherwise a positive value if the
+     *         original NC is superior to the second one, a negative value if
+     *         the second NC is superior.
+     */
+    public int compareToIgnoreCase( Object object )
+    {
+        if ( object instanceof AttributeTypeAndValue )
+        {
+            AttributeTypeAndValue nc = ( AttributeTypeAndValue ) object;
+
+            int res = compareType( type, nc.type );
+
+            if ( res != 0 )
+            {
+                return res;
+            }
+            else
+            {
+                return compareValue( value, nc.value, CASE_INSENSITIVE );
+            }
+        }
+        else
+        {
+            return 1;
+        }
+    }
+
+
+    /**
+     * Compare two types, trimed and case insensitive
+     *
+     * @param val1
+     *            First String
+     * @param val2
+     *            Second String
+     * @return true if both strings are equals or null.
+     */
+    private int compareType( String val1, String val2 )
+    {
+        if ( StringTools.isEmpty( val1 ) )
+        {
+            return StringTools.isEmpty( val2 ) ? 0 : -1;
+        }
+        else if ( StringTools.isEmpty( val2 ) )
+        {
+            return 1;
+        }
+        else
+        {
+            return ( StringTools.trim( val1 ) ).compareToIgnoreCase( StringTools.trim( val2 ) );
+        }
+    }
+
+
+    /**
+     * Compare two values
+     *
+     * @param val1
+     *            First String
+     * @param val2
+     *            Second String
+     * @return true if both strings are equals or null.
+     */
+    private int compareValue( Object val1, Object val2, boolean sensitivity )
+    {
+        if ( val1 instanceof String )
+        {
+            if ( val2 instanceof String )
+            {
+                int val = ( sensitivity == CASE_SENSITIVE ) ? ( ( String ) val1 ).compareTo( ( String ) val2 )
+                    : ( ( String ) val1 ).compareToIgnoreCase( ( String ) val2 );
+
+                return ( val < 0 ? -1 : ( val > 0 ? 1 : val ) );
+            }
+            else
+            {
+                return 1;
+            }
+        }
+        else if ( val1 instanceof byte[] )
+        {
+            if ( Arrays.equals( ( byte[] ) val1, ( byte[] ) val2 ) )
+            {
+                return 0;
+            }
+            else
+            {
+                return 1;
+            }
+        }
+        else
+        {
+            return 1;
+        }
+    }
+
+    private static final boolean[] DN_ESCAPED_CHARS = new boolean[]
+        {
+        true,  true,  true,  true,  true,  true,  true,  true,  // 0x00 -> 0x07
+        true,  true,  true,  true,  true,  true,  true,  true,  // 0x08 -> 0x0F
+        true,  true,  true,  true,  true,  true,  true,  true,  // 0x10 -> 0x17
+        true,  true,  true,  true,  true,  true,  true,  true,  // 0x18 -> 0x1F
+        true,  false, true,  true,  false, false, false, false, // 0x20 -> 0x27 ' ', '"', '#'
+        false, false, false, true,  true,  false, false, false, // 0x28 -> 0x2F '+', ','
+        false, false, false, false, false, false, false, false, // 0x30 -> 0x37 
+        false, false, false, true,  true,  false, true,  false, // 0x38 -> 0x3F ';', '<', '>'
+        false, false, false, false, false, false, false, false, // 0x40 -> 0x47
+        false, false, false, false, false, false, false, false, // 0x48 -> 0x4F
+        false, false, false, false, false, false, false, false, // 0x50 -> 0x57
+        false, false, false, false, true,  false, false, false, // 0x58 -> 0x5F
+        false, false, false, false, false, false, false, false, // 0x60 -> 0x67
+        false, false, false, false, false, false, false, false, // 0x68 -> 0x6F
+        false, false, false, false, false, false, false, false, // 0x70 -> 0x77
+        false, false, false, false, false, false, false, false, // 0x78 -> 0x7F
+        };
+
+    /**
+     * A Normalized String representation of a AttributeTypeAndValue : - type is
+     * trimed and lowercased - value is trimed and lowercased, and special characters
+     * are escaped if needed.
+     *
+     * @return A normalized string representing a AttributeTypeAndValue
+     */
+    public String normalize()
+    {
+        if ( value instanceof String )
+        {
+            StringBuilder sb = new StringBuilder();
+            sb.append( StringTools.lowerCase( StringTools.trim( type ) ) ).append( '=' );
+            String normalizedValue =  ( String ) value;
+            int valueLength = normalizedValue.length();
+            
+            if ( normalizedValue.length() > 0 )
+            {
+                for ( int i = 0; i < valueLength; i++ )
+                {
+                    char c = normalizedValue.charAt( i );
+                    
+                    if ( ( c < 0) || ( c > 128 ) )
+                    {
+                        byte[] bb = StringTools.getBytesUtf8( normalizedValue.substring( i, i + 1 ) );
+                        
+                        for ( int j = 0; j < bb.length; j++ )
+                        {
+                            byte b = bb[j];
+                            
+                            sb.append( '\\' ).
+                                append( StringTools.dumpHex( (byte)(( b & 0x00F0 ) >> 4) ) ).
+                                append( StringTools.dumpHex( b ) );
+                        }
+                    }
+                    else if ( DN_ESCAPED_CHARS[ c ] ) 
+                    {
+                        if ( c == ' ' )
+                        {
+                            if ( ( i == 0 ) || ( i == valueLength - 1 ) )
+                            {
+                                sb.append( '\\' ).append(  c  );
+                            }
+                            else
+                            {
+                                sb.append( ' ' );
+                            }
+
+                            continue;
+                        }
+                        else if ( c == '#' )
+                        {
+                            if ( i == 0 )
+                            {
+                                sb.append( "\\#" );
+                                continue;
+                            }
+                            else
+                            {
+                                sb.append( '#' );
+                            }
+                            
+                            continue;
+                        }
+
+                        sb.append( '\\' ).append( c );
+                    }
+                    else
+                    {
+                        sb.append( c );
+                    }
+                 }
+            }
+            
+            return sb.toString();
+        }
+        else
+        {
+            return StringTools.lowerCase( StringTools.trim( type ) ) + "=#"
+                + StringTools.dumpHexPairs( ( byte[] ) value );
+        }
+    }
+
+
+    /**
+     * Gets the hashcode of this object.
+     *
+     * @see java.lang.Object#hashCode()
+     */
+    public int hashCode()
+    {
+        int result = 17;
+
+        result = result * 37 + ( type != null ? type.hashCode() : 0 );
+        result = result * 37 + ( value != null ? type.hashCode() : 0 );
+
+        return result;
+    }
+
+
+    /**
+     * A String representation of a AttributeTypeAndValue.
+     *
+     * @return A string representing a AttributeTypeAndValue
+     */
+    public String toString()
+    {
+        StringBuffer sb = new StringBuffer();
+
+        if ( StringTools.isEmpty( type ) || StringTools.isEmpty( type.trim() ) )
+        {
+            return "";
+        }
+
+        sb.append( type ).append( "=" );
+
+        if ( value != null )
+        {
+            sb.append( value );
+        }
 
-       return sb.toString();
-   }
+        return sb.toString();
+    }
 }

Modified: directory/branches/shared/0.9.5/ldap/src/main/java/org/apache/directory/shared/ldap/name/LdapDN.java
URL: http://svn.apache.org/viewvc/directory/branches/shared/0.9.5/ldap/src/main/java/org/apache/directory/shared/ldap/name/LdapDN.java?view=diff&rev=486780&r1=486779&r2=486780
==============================================================================
--- directory/branches/shared/0.9.5/ldap/src/main/java/org/apache/directory/shared/ldap/name/LdapDN.java (original)
+++ directory/branches/shared/0.9.5/ldap/src/main/java/org/apache/directory/shared/ldap/name/LdapDN.java Wed Dec 13 10:06:39 2006
@@ -176,7 +176,8 @@
     * &lt;spaces&gt; &lt;name-component&gt; &lt;name-components&gt; | e <br>
     * </p>
     *
-    * @param upName The String that contains the DN
+    * @param upName
+    *            The String that contains the DN
     * @exception InvalidNameException is thrown if the buffer does not
     *                contains a valid DN.
     */
@@ -254,8 +255,12 @@
            StringBuffer sb = new StringBuffer();
            boolean isFirst = true;
 
-           for ( int i = 0; i < rdns.size(); i++ )
+           Iterator rdnIter = rdns.iterator();
+           
+           while( rdnIter.hasNext() )
            {
+               Rdn rdn = (Rdn)rdnIter.next();
+               
                if ( isFirst )
                {
                    isFirst = false;
@@ -265,7 +270,7 @@
                    sb.append( ',' );
                }
 
-               sb.append( ( ( Rdn ) rdns.get( i ) ) );
+               sb.append( rdn );
            }
 
            String newNormName = sb.toString();
@@ -308,9 +313,13 @@
        {
            StringBuffer sb = new StringBuffer();
            boolean isFirst = true;
-
-           for ( int i = 0; i < rdns.size(); i++ )
+           
+           Iterator rdnIter = rdns.iterator();
+           
+           while( rdnIter.hasNext() )
            {
+               Rdn rdn = (Rdn)rdnIter.next();
+               
                if ( isFirst )
                {
                    isFirst = false;
@@ -320,7 +329,7 @@
                    sb.append( ',' );
                }
 
-               sb.append( ( ( Rdn ) rdns.get( i ) ).getUpName() );
+               sb.append( rdn.getUpName() );
            }
 
            upName = sb.toString();
@@ -378,7 +387,7 @@
                sb.append( ',' );
            }
 
-           sb.append( ( ( Rdn ) rdns.get( i ) ).getUpName() );
+           sb.append( ((Rdn)rdns.get( i )).getUpName() );
        }
 
        return sb.toString();
@@ -424,7 +433,7 @@
                sb.append( ',' );
            }
 
-           sb.append( ( ( Rdn ) rdns.get( i ) ).getUpName() );
+           sb.append( ((Rdn)rdns.get( i )).getUpName() );
        }
 
        return sb.toString();
@@ -442,10 +451,14 @@
 
        if ( ( rdns != null ) || ( rdns.size() == 0 ) )
        {
-               for ( Iterator rdnsIter = rdns.iterator(); rdnsIter.hasNext(); )
-               {
-                       result = result * 37 + rdnsIter.next().hashCode();
-               }
+           Iterator rdnIter = rdns.iterator();
+           
+           while( rdnIter.hasNext() )
+           {
+               Rdn rdn = (Rdn)rdnIter.next();
+               
+               result = result * 37 + rdn.hashCode();
+           }
        }
 
        return result;
@@ -543,8 +556,8 @@
 
            for ( int i = nameDN.size() - 1; i >= 0; i-- )
            {
-               Rdn nameRdn = ( Rdn ) ( nameDN.rdns.get( nameDN.rdns.size() - i - 1 ) );
-               Rdn ldapRdn = ( Rdn ) rdns.get( rdns.size() - i - 1 );
+               Rdn nameRdn = (Rdn)nameDN.rdns.get( nameDN.rdns.size() - i - 1 );
+               Rdn ldapRdn = (Rdn)rdns.get( rdns.size() - i - 1 );
 
                if ( nameRdn.compareTo( ldapRdn ) != 0 )
                {
@@ -572,8 +585,9 @@
 
            for ( int i = name.size() - 1; i >= 0; i-- )
            {
-               Rdn ldapRdn = ( Rdn ) rdns.get( rdns.size() - i - 1 );
+               Rdn ldapRdn = (Rdn)rdns.get( rdns.size() - i - 1 );
                Rdn nameRdn = null;
+               
                try
                {
                    nameRdn = new Rdn( ( String ) name.get( name.size() - i - 1 ) );
@@ -633,8 +647,8 @@
            // Ok, iterate through all the RDN of the name
            for ( int i = 0; i < nameDN.size(); i++ )
            {
-               Rdn nameRdn = ( Rdn ) ( nameDN.rdns.get( i ) );
-               Rdn ldapRdn = ( Rdn ) rdns.get( i );
+               Rdn nameRdn = (Rdn)nameDN.rdns.get( i );
+               Rdn ldapRdn = (Rdn)rdns.get( i );
 
                if ( nameRdn.compareTo( ldapRdn ) != 0 )
                {
@@ -682,7 +696,7 @@
        }
        else
        {
-           Rdn rdn = ( Rdn ) rdns.get( rdns.size() - posn - 1 );
+           Rdn rdn = (Rdn)rdns.get( rdns.size() - posn - 1 );
 
            return rdn.toString();
        }
@@ -707,7 +721,7 @@
        }
        else
        {
-           Rdn rdn = ( Rdn ) rdns.get( rdns.size() - posn - 1 );
+           Rdn rdn = (Rdn)rdns.get( rdns.size() - posn - 1 );
 
            return rdn;
        }
@@ -726,9 +740,7 @@
        }
        else
        {
-           Rdn rdn = ( Rdn ) rdns.get( 0 );
-
-           return rdn;
+           return (Rdn)rdns.get( 0 );
        }
    }
 
@@ -743,9 +755,13 @@
        List newRdns = new ArrayList();
 
        // We will clone the list, to avoid user modifications
-       for ( int i = 0; i < rdns.size(); i++ )
+       Iterator rdnIter = rdns.iterator();
+       
+       while( rdnIter.hasNext() )
        {
-           newRdns.add( i, ( ( Rdn ) rdns.get( i ) ).clone() );
+           Rdn rdn = (Rdn)rdnIter.next();
+
+           newRdns.add( (Rdn)rdn.clone() );
        }
 
        return newRdns;
@@ -786,9 +802,9 @@
                    throw new NoSuchElementException();
                }
 
-               Object obj = rdns.get( rdns.size() - pos - 1 );
+               Rdn rdn = (Rdn)rdns.get( rdns.size() - pos - 1 );
                pos++;
-               return obj.toString();
+               return rdn.toString();
            }
        };
    }
@@ -828,9 +844,9 @@
                    throw new NoSuchElementException();
                }
 
-               Object obj = rdns.get( rdns.size() - pos - 1 );
+               Rdn rdn = (Rdn)rdns.get( rdns.size() - pos - 1 );
                pos++;
-               return obj;
+               return rdn;
            }
        };
    }
@@ -868,7 +884,7 @@
        for ( int i = rdns.size() - posn; i < rdns.size(); i++ )
        {
            // Don't forget to clone the rdns !
-           newLdapDN.rdns.add( ( ( Rdn ) rdns.get( i ) ).clone() );
+           newLdapDN.rdns.add( (( Rdn ) rdns.get( i ) ).clone() );
        }
 
        newLdapDN.normName = newLdapDN.toNormName();
@@ -911,7 +927,7 @@
        for ( int i = 0; i < size() - posn; i++ )
        {
            // Don't forget to clone the rdns !
-           newLdapDN.rdns.add( ( ( Rdn ) rdns.get( i ) ).clone() );
+           newLdapDN.rdns.add( (( Rdn ) rdns.get( i )).clone() );
        }
 
        newLdapDN.normName = newLdapDN.toNormName();
@@ -982,14 +998,16 @@
                return this;
            }
 
-           for ( int ii = name.size() - 1; ii >= 0; ii-- )
+           for ( int i = name.size() - 1; i >= 0; i-- )
            {
-               Rdn rdn = new Rdn( name.get( ii ) );
+               Rdn rdn = new Rdn( name.get( i ) );
                rdns.add( size() - posn, rdn );
            }
+           
            normalizeInternal();
            toUpName();
        }
+       
        return this;
    }
 
@@ -1104,7 +1122,7 @@
        }
 
        int realPos = size() - posn - 1;
-       Rdn rdn = ( Rdn ) rdns.remove( realPos );
+       Rdn rdn = (Rdn)rdns.remove( realPos );
 
        normalizeInternal();
        toUpName();
@@ -1127,9 +1145,13 @@
            LdapDN dn = ( LdapDN ) super.clone();
            dn.rdns = new ArrayList();
 
-           for ( int i = 0; i < rdns.size(); i++ )
+           Iterator rdnIter = rdns.iterator();
+           
+           while( rdnIter.hasNext() )
            {
-               dn.rdns.add( i, ( ( Rdn ) rdns.get( i ) ).clone() );
+               Rdn rdn = (Rdn)rdnIter.next();
+
+               dn.rdns.add( ( Rdn ) rdn.clone() );
            }
 
            return dn;
@@ -1160,9 +1182,9 @@
                return false;
            }
 
-           for ( int i = 0; i < size(); i++ )
+           for ( int i = 0; i < this.size(); i++ )
            {
-               if ( ( ( Rdn ) name.rdns.get( i ) ).compareTo( rdns.get( i ) ) != 0 )
+               if ( ((Rdn)name.rdns.get( i ) ).compareTo( (Rdn)rdns.get( i ) ) != 0 )
                {
                    return false;
                }
@@ -1212,8 +1234,8 @@
 
            for ( int i = rdns.size(); i > 0; i-- )
            {
-               Rdn rdn1 = ( Rdn ) rdns.get( i - 1 );
-               Rdn rdn2 = ( Rdn ) ldapDN.rdns.get( i - 1 );
+               Rdn rdn1 = (Rdn)rdns.get( i - 1 );
+               Rdn rdn2 = (Rdn)ldapDN.rdns.get( i - 1 );
                int res = rdn1.compareTo( rdn2 );
 
                if ( res != 0 )
@@ -1387,10 +1409,10 @@
        // Loop on all RDNs
        while ( rdns.hasMoreElements() )
        {
-           Rdn rdn = ( Rdn ) rdns.nextElement();
+           Rdn rdn = (Rdn)rdns.nextElement();
            String upName = rdn.getUpName();
            rdnOidToName( rdn, oidsMap );
-           rdn.normalizeString();
+           rdn.normalize();
            rdn.setUpName( upName );
        }
 
@@ -1426,10 +1448,10 @@
        // Loop on all RDNs
        while ( rdns.hasMoreElements() )
        {
-           Rdn rdn = ( Rdn ) rdns.nextElement();
+           Rdn rdn = (Rdn)rdns.nextElement();
            String upName = rdn.getUpName();
            rdnOidToName( rdn, oidsMap );
-           rdn.normalizeString();
+           rdn.normalize();
            rdn.setUpName( upName );
        }
 

Modified: directory/branches/shared/0.9.5/ldap/src/main/java/org/apache/directory/shared/ldap/name/Rdn.java
URL: http://svn.apache.org/viewvc/directory/branches/shared/0.9.5/ldap/src/main/java/org/apache/directory/shared/ldap/name/Rdn.java?view=diff&rev=486780&r1=486779&r2=486780
==============================================================================
--- directory/branches/shared/0.9.5/ldap/src/main/java/org/apache/directory/shared/ldap/name/Rdn.java (original)
+++ directory/branches/shared/0.9.5/ldap/src/main/java/org/apache/directory/shared/ldap/name/Rdn.java Wed Dec 13 10:06:39 2006
@@ -24,6 +24,7 @@
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
+import java.util.Set;
 import java.util.TreeSet;
 
 import javax.naming.InvalidNameException;
@@ -115,7 +116,7 @@
    private String upName = null;
 
    /** The normalized RDN */
-   private String string = null;
+   private String normName = null;
 
    /** The starting position of this RDN in the given string from which
     * we have extracted the upName */
@@ -130,11 +131,13 @@
     * because we want the ATAVs to be sorted. An atav may contain more than one
     * value. In this case, the values are String stored in a List.
     */
-   private TreeSet atavs = null;
+   private Set atavs = null;
 
    /**
     * We also keep a set of types, in order to use manipulations. A type is
     * connected with the atav it represents.
+    * 
+    * Note : there is no Generic available classes in commons-collection...
     */
    private Map atavTypes = new MultiHashMap();
 
@@ -175,7 +178,7 @@
        // name-components in a RDN... So we won't initialize the Map and the
        // treeSet.
        upName = "";
-       string = "";
+       normName = "";
    }
 
 
@@ -198,15 +201,15 @@
 
            // create the internal normalized form
            // and store the user provided form
-           normalizeString();
+           normalize();
            upName = rdn;
-               length = rdn.length();
+           length = rdn.length();
        }
        else
        {
            upName = "";
-           string = "";
-               length = 0;
+           normName = "";
+           length = 0;
        }
    }
 
@@ -234,7 +237,7 @@
        start = 0;
        length = upName.length();
        // create the internal normalized form
-       normalizeString();
+       normalize();
    }
 
 
@@ -249,7 +252,7 @@
    {
        super();
        nbAtavs = rdn.getNbAtavs();
-       this.string = new String( rdn.string );
+       this.normName = new String( rdn.normName );
        this.upName = new String( rdn.getUpName() );
        this.start = rdn.start;
        this.length = rdn.length;
@@ -273,7 +276,7 @@
                while ( iter.hasNext() )
                {
                    AttributeTypeAndValue currentAtav = ( AttributeTypeAndValue ) iter.next();
-                   atavs.add( currentAtav.clone() );
+                   atavs.add( (AttributeTypeAndValue)currentAtav.clone() );
                    atavTypes.put( currentAtav.getType(), currentAtav );
                }
        }
@@ -288,13 +291,13 @@
    // WARNING : The protection level is left unspecified intentionnaly.
    // We need this method to be visible from the DnParser class, but not
    // from outside this package.
-   /* Unspecified protection */void normalizeString()
+   /* Unspecified protection */void normalize()
    {
        switch ( nbAtavs )
        {
            case 0:
                // An empty RDN
-               string = "";
+               normName = "";
                break;
 
            case 1:
@@ -302,11 +305,11 @@
                // We will trim and lowercase type and value.
                if ( atav.getValue() instanceof String )
                {
-                       string = atav.getType() + '=' + (String)atav.getValue();
+                   normName = atav.getNormalizedValue();
                }
                else
                {
-                       string = atav.getType() + "=#" + StringTools.dumpHexPairs( (byte[])atav.getValue() );
+                   normName = atav.getType() + "=#" + StringTools.dumpHexPairs( (byte[])atav.getValue() );
                }
 
                break;
@@ -315,13 +318,13 @@
                // We have more than one AttributeTypeAndValue
                StringBuffer sb = new StringBuffer();
 
-               Iterator elems = atavs.iterator();
                boolean isFirst = true;
 
-               while ( elems.hasNext() )
+               Iterator ataIter = atavs.iterator();
+               
+               while ( ataIter.hasNext() )
                {
-                   AttributeTypeAndValue ata = ( AttributeTypeAndValue ) elems.next();
-
+                   AttributeTypeAndValue ata = (AttributeTypeAndValue)ataIter.next(); 
                    if ( isFirst )
                    {
                        isFirst = false;
@@ -334,7 +337,7 @@
                    sb.append( ata.normalize() );
                }
 
-               string = sb.toString();
+               normName = sb.toString();
                break;
        }
    }
@@ -407,7 +410,7 @@
        atavType = null;
        atavTypes.clear();
        nbAtavs = 0;
-       string = "";
+       normName = "";
        upName = "";
        start = -1;
        length = 0;
@@ -553,7 +556,7 @@
 
                public Object next()
                {
-                   Object obj = atav;
+                   AttributeTypeAndValue obj = atav;
                    hasMoreElement = false;
                    return obj;
                }
@@ -598,12 +601,13 @@
                    rdn.atavTypes = new MultiHashMap();
                    rdn.atavs = new TreeSet();
 
-                   Iterator iter = this.atavs.iterator();
-
-                   while ( iter.hasNext() )
+                   Iterator ataIter = this.atavs.iterator();
+                   
+                   while ( ataIter.hasNext() )
                    {
-                       AttributeTypeAndValue currentAtav = ( AttributeTypeAndValue ) iter.next();
-                       rdn.atavs.add( currentAtav.clone() );
+                       AttributeTypeAndValue currentAtav = (AttributeTypeAndValue)ataIter.next();
+                       
+                       rdn.atavs.add( (AttributeTypeAndValue)currentAtav.clone() );
                        rdn.atavTypes.put( currentAtav.getType(), currentAtav );
                    }
 
@@ -660,11 +664,12 @@
                default:
                    // We have more than one value. We will
                    // go through all of them.
-                   Iterator keys = atavs.iterator();
 
-                   while ( keys.hasNext() )
+                   Iterator ataIter = atavs.iterator();
+               
+                   while( ataIter.hasNext() )
                    {
-                       AttributeTypeAndValue current = ( AttributeTypeAndValue ) keys.next();
+                       AttributeTypeAndValue current = (AttributeTypeAndValue)ataIter.next();
                        String type = current.getType();
 
                        if ( rdn.atavTypes.containsKey( type ) )
@@ -739,7 +744,7 @@
     */
    public String toString()
    {
-       return string;
+       return normName == null ? "" : normName;
    }
 
 
@@ -787,7 +792,7 @@
                return atav;
 
            default:
-               return ( AttributeTypeAndValue ) atavs.first();
+               return (AttributeTypeAndValue)((TreeSet)atavs).first();
        }
    }
 
@@ -808,7 +813,7 @@
                return atav.getType();
 
            default:
-               return ( ( AttributeTypeAndValue ) atavs.first() ).getType();
+               return ( ( AttributeTypeAndValue )((TreeSet)atavs).first() ).getType();
        }
    }
 
@@ -829,7 +834,7 @@
                return atav.getValue();
 
            default:
-               return ( ( AttributeTypeAndValue ) atavs.first() ).getValue();
+               return ( ( AttributeTypeAndValue )((TreeSet)atavs).first() ).getValue();
        }
    }
 
@@ -1183,9 +1188,11 @@
            default:
                // We have more than one AttributeTypeAndValue
 
-               for ( Iterator elems = atavs.iterator();elems.hasNext(); )
+               Iterator ataIter = atavs.iterator();
+           
+               while( ataIter.hasNext() )
                {
-                   AttributeTypeAndValue ata = ( AttributeTypeAndValue ) elems.next();
+                   AttributeTypeAndValue ata = (AttributeTypeAndValue)ataIter.next();
                    result = result * 37 + ata.hashCode();
                }
        }

Modified: directory/branches/shared/0.9.5/ldap/src/main/java/org/apache/directory/shared/ldap/name/RdnParser.java
URL: http://svn.apache.org/viewvc/directory/branches/shared/0.9.5/ldap/src/main/java/org/apache/directory/shared/ldap/name/RdnParser.java?view=diff&rev=486780&r1=486779&r2=486780
==============================================================================
--- directory/branches/shared/0.9.5/ldap/src/main/java/org/apache/directory/shared/ldap/name/RdnParser.java (original)
+++ directory/branches/shared/0.9.5/ldap/src/main/java/org/apache/directory/shared/ldap/name/RdnParser.java Wed Dec 13 10:06:39 2006
@@ -265,7 +265,6 @@
     private static Object parseAttributeValue( String string, Position pos )
     {
         StringBuffer sb = new StringBuffer();
-
         char c = StringTools.charAt( string, pos.start );
 
         if ( c == '#' )
@@ -482,7 +481,7 @@
             else
             {
                 // <attributeTypeAndValues> ::= e
-                rdn.normalizeString();
+                rdn.normalize();
                 return DNUtils.PARSING_OK;
             }
 
@@ -581,7 +580,6 @@
 
         pos.end = pos.start;
         pos.length = 0;
-
         if ( ( type = parseAttributeType( dn, pos ) ) == null )
         {
             return DNUtils.PARSING_ERROR;
@@ -615,14 +613,17 @@
         if ( rdn != null )
         {
             rdn.addAttributeTypeAndValue( type, value );
-            rdn.normalizeString();
+            rdn.normalize();
 
             pos.start = pos.end;
             pos.length = 0;
         }
 
-        parseNameComponents( dn, pos, rdn );
-
+        if ( parseNameComponents( dn, pos, rdn ) == DNUtils.PARSING_ERROR )
+        {
+            return DNUtils.PARSING_ERROR;
+        }
+        
         rdn.setUpName( dn.substring( start, pos.end ) );
         pos.start = pos.end;
         return DNUtils.PARSING_OK;
@@ -645,6 +646,6 @@
     public static void parse( String string, Rdn rdn ) throws InvalidNameException
     {
         parse( string, new Position(), rdn );
-        rdn.normalizeString();
+        rdn.normalize();
     }
 }

Modified: directory/branches/shared/0.9.5/ldap/src/main/java/org/apache/directory/shared/ldap/util/DNUtils.java
URL: http://svn.apache.org/viewvc/directory/branches/shared/0.9.5/ldap/src/main/java/org/apache/directory/shared/ldap/util/DNUtils.java?view=diff&rev=486780&r1=486779&r2=486780
==============================================================================
--- directory/branches/shared/0.9.5/ldap/src/main/java/org/apache/directory/shared/ldap/util/DNUtils.java (original)
+++ directory/branches/shared/0.9.5/ldap/src/main/java/org/apache/directory/shared/ldap/util/DNUtils.java Wed Dec 13 10:06:39 2006
@@ -148,8 +148,8 @@
         };
 
     /**
-     * '"' | '#' | '+' | ',' | [0-9] | ';' | '<' | '=' | '>' | [A-F] | '\' | [a-f] 
-     * 0x22 | 0x23 | 0x2B | 0x2C | [0x30-0x39] | 0x3B | 0x3C | 0x3D | 0x3E |
+     * '"' | '#' | '+' | ',' | [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 =
@@ -169,7 +169,7 @@
             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, PARSING_ERROR, PARSING_ERROR, ONE_CHAR      // 3C -> 3F
+            PARSING_ERROR, ONE_CHAR,      PARSING_ERROR, ONE_CHAR      // 3C -> 3F
         };
 
     /** "oid." static */
@@ -303,7 +303,7 @@
 
 
     /**
-     * Check if the current character is a Pair Char &lt;pairchar> ::= ',' | '=' |
+     * Check if the current character is a Pair Char &lt;pairchar&gt; ::= ',' | '=' |
      * '+' | '<' | '>' | '#' | ';' | '\' | '"' | [0-9a-fA-F] [0-9a-fA-F]
      * 
      * @param byteArray
@@ -717,8 +717,8 @@
      */
     private static byte getHexPair( String string, int index )
     {
-    	return (byte)((StringTools.HEX_VALUE[string.charAt( index )] << 4) | 
-    				(StringTools.HEX_VALUE[string.charAt( index + 1 )]) );
+        return (byte)((StringTools.HEX_VALUE[string.charAt( index )] << 4) | 
+                    (StringTools.HEX_VALUE[string.charAt( index + 1 )]) );
     }
 
     /**
@@ -835,7 +835,7 @@
      */
     public static int parseHexString( String string, byte[] hex, Position pos )
     {
-    	int i = 0;
+        int i = 0;
         pos.end = pos.start;
         int result = parseHexPair( string, pos.start );
 
@@ -845,13 +845,13 @@
         }
         else
         {
-        	hex[i++] = getHexPair( string, pos.end );
+            hex[i++] = getHexPair( string, pos.end );
             pos.end += TWO_CHARS;
         }
 
         while ( ( result = parseHexPair( string, pos.end ) ) >= 0 )
         {
-        	hex[i++] = getHexPair( string, pos.end );
+            hex[i++] = getHexPair( string, pos.end );
             pos.end += TWO_CHARS;
         }
 

Modified: directory/branches/shared/0.9.5/ldap/src/test/java/org/apache/directory/shared/ldap/name/DnParserDIRSERVER_584_Test.java
URL: http://svn.apache.org/viewvc/directory/branches/shared/0.9.5/ldap/src/test/java/org/apache/directory/shared/ldap/name/DnParserDIRSERVER_584_Test.java?view=diff&rev=486780&r1=486779&r2=486780
==============================================================================
--- directory/branches/shared/0.9.5/ldap/src/test/java/org/apache/directory/shared/ldap/name/DnParserDIRSERVER_584_Test.java (original)
+++ directory/branches/shared/0.9.5/ldap/src/test/java/org/apache/directory/shared/ldap/name/DnParserDIRSERVER_584_Test.java Wed Dec 13 10:06:39 2006
@@ -43,7 +43,7 @@
    {
        try
        {
-           LdapDnParser.parseInternal( "ou=test=testing", new ArrayList() );
+           LdapDnParser.parseInternal( "ou=test+testing", new ArrayList() );
            fail( "should never get here" );
        }
        catch ( InvalidNameException e )

Modified: directory/branches/shared/0.9.5/ldap/src/test/java/org/apache/directory/shared/ldap/name/LdapDNTest.java
URL: http://svn.apache.org/viewvc/directory/branches/shared/0.9.5/ldap/src/test/java/org/apache/directory/shared/ldap/name/LdapDNTest.java?view=diff&rev=486780&r1=486779&r2=486780
==============================================================================
--- directory/branches/shared/0.9.5/ldap/src/test/java/org/apache/directory/shared/ldap/name/LdapDNTest.java (original)
+++ directory/branches/shared/0.9.5/ldap/src/test/java/org/apache/directory/shared/ldap/name/LdapDNTest.java Wed Dec 13 10:06:39 2006
@@ -246,8 +246,7 @@
    {
        
        LdapDN dn = new LdapDN( "a = \\,\\=\\+\\<\\>\\#\\;\\\\\\\"\\C4\\8D" );
-       byte[] expected = new byte[] { 'a', '=', ',', '=', '+', '<', '>', '#', ';', '\\', '"', (byte)0xC4, (byte)0x8D}; 
-       Assert.assertEquals( StringTools.utf8ToString( expected ), dn.toString() );
+       Assert.assertEquals( "a=\\,=\\+\\<\\>#\\;\\\\\\\"\\C4\\8D", dn.toString() );
        Assert.assertEquals( "a = \\,\\=\\+\\<\\>\\#\\;\\\\\\\"\\C4\\8D", dn.getUpName() );
    }
 
@@ -258,7 +257,7 @@
    {
        LdapDN dn = new LdapDN( "SN=Lu\\C4\\8Di\\C4\\87" );
        byte[] lucic = new byte[] { 's', 'n', '=', 'L', 'u', (byte)0xC4, (byte)0x8D, 'i', (byte)0xC4, (byte)0x87}; 
-       Assert.assertEquals( StringTools.utf8ToString( lucic ), dn.toString() );
+       Assert.assertEquals( "sn=Lu\\C4\\8Di\\C4\\87", dn.toString() );
        Assert.assertEquals( "SN=Lu\\C4\\8Di\\C4\\87", dn.getUpName() );
    }
 
@@ -273,6 +272,16 @@
    }
 
    /**
+    * test a simple DN with a # on first position
+    */
+   public void testLdapDNSharpFirst() throws InvalidNameException
+   {
+       LdapDN dn = new LdapDN( "a = \\#this is a sharp" );
+       Assert.assertEquals( "a=\\#this is a sharp", dn.toString() );
+       Assert.assertEquals( "a = \\#this is a sharp", dn.getUpName() );
+   }
+
+   /**
     * test a simple DN with a wrong hexString attribute value : a = #0010Z0AAFF
     */
    public void testLdapDNWrongHexStringAttributeValue() throws InvalidNameException
@@ -310,7 +319,7 @@
    public void testLdapDNQuoteInAttributeValue() throws InvalidNameException
    {
        LdapDN dn = new LdapDN( "a = quoted \\\"value\\\"" );
-       Assert.assertEquals( "a=quoted \"value\"", dn.toString() );
+       Assert.assertEquals( "a=quoted \\\"value\\\"", dn.toString() );
        Assert.assertEquals( "a = quoted \\\"value\\\"", dn.getUpName() );
    }
 
@@ -320,7 +329,7 @@
    public void testLdapDNQuotedAttributeValue() throws InvalidNameException
    {
        LdapDN dn = new LdapDN( "a = \\\" quoted value \\\"" );
-       Assert.assertEquals( "a=\" quoted value \"", dn.toString() );
+       Assert.assertEquals( "a=\\\" quoted value \\\"", dn.toString() );
        Assert.assertEquals( "a = \\\" quoted value \\\"", dn.getUpName() );
    }
 
@@ -1279,13 +1288,10 @@
        String dn = StringTools.utf8ToString( new byte[]{'C', 'N', ' ', '=', ' ', 'E', 'm', 'm', 'a', 'n', 'u', 'e', 
            'l', ' ', ' ', 'L', (byte)0xc3, (byte)0xa9, 'c', 'h', 'a', 'r', 'n', 'y'} );
 
-       String expected = StringTools.utf8ToString( new byte[]{'c', 'n', '=','E', 'm', 'm', 'a', 'n', 'u', 'e', 
-           'l', ' ', ' ', 'L', (byte)0xc3, (byte)0xa9, 'c', 'h', 'a', 'r', 'n', 'y'} );
-
        Name name = LdapDnParser.getNameParser().parse( dn );
 
        Assert.assertEquals( dn, ( ( LdapDN ) name ).getUpName() );
-       Assert.assertEquals( expected, name.toString() );
+       Assert.assertEquals( "cn=Emmanuel  L\\C3\\A9charny", name.toString() );
    }
 
 
@@ -2099,11 +2105,11 @@
    public void testNameFrenchChars() throws Exception
    {
        String cn = new String( new byte[]
-           { 'c', 'n', '=', 0x4A, ( byte ) 0xC3, ( byte ) 0xA9, 0x72, ( byte ) 0xC3, ( byte ) 0xB4, 0x6D, 0x65 } );
+           { 'c', 'n', '=', 0x4A, ( byte ) 0xC3, ( byte ) 0xA9, 0x72, ( byte ) 0xC3, ( byte ) 0xB4, 0x6D, 0x65 }, "UTF-8" );
 
        Name name = new LdapDN( cn );
 
-       assertEquals( cn, name.toString() );
+       assertEquals( "cn=J\\C3\\A9r\\C3\\B4me", name.toString() );
    }
 
 
@@ -2116,7 +2122,7 @@
 
        Name name = new LdapDN( cn );
 
-       assertEquals( cn, name.toString() );
+       assertEquals( "cn=\\C3\\84\\C3\\96\\C3\\9C\\C3\\9F\\C3\\A4\\C3\\B6\\C3\\BC", name.toString() );
    }
 
 
@@ -2130,7 +2136,7 @@
 
        Name name = new LdapDN( cn );
 
-       assertEquals( cn, name.toString() );
+       assertEquals( "cn=\\C4\\B0\\C4\\B1\\C5\\9E\\C5\\9F\\C3\\96\\C3\\B6\\C3\\9C\\C3\\BC\\C4\\9E\\C4\\9F", name.toString() );
    }
 
 
@@ -2516,10 +2522,13 @@
     */
    public void testDoubleQuoteInNameDIRSERVER_642_1() throws NamingException
    {
+       LdapDN dn1 = new LdapDN( "cn= a " );
+       LdapDN dn2 = new LdapDN( "cn=\" a \"" );
+       LdapDN dn3 = new LdapDN( "cn= \" a \" " );
        LdapDN dn = new LdapDN( "cn=\" Kylie Minogue \",dc=example,dc=com" );
 
        Assert.assertEquals( "cn=\" Kylie Minogue \",dc=example,dc=com", dn.getUpName() );
-       Assert.assertEquals( "cn= Kylie Minogue ,dc=example,dc=com", dn.toString() );
+       Assert.assertEquals( "cn=\\ Kylie Minogue\\ ,dc=example,dc=com", dn.toString() );
    }
 
    /**
@@ -2530,7 +2539,7 @@
    {
        LdapDN name = new LdapDN( "dn= \\ four spaces leading and 3 trailing \\  " );
 
-       Assert.assertEquals( "dn= four spaces leading and 3 trailing  ", name.toString() );
+       Assert.assertEquals( "dn=\\ four spaces leading and 3 trailing \\ ", name.toString() );
        Assert.assertEquals( "dn= \\ four spaces leading and 3 trailing \\  ", name.getUpName() );
    }
 
@@ -2574,7 +2583,7 @@
    {
        LdapDN name = new LdapDN( "dn=\\# a leading pound" );
 
-       Assert.assertEquals( "dn=# a leading pound", name.toString() );
+       Assert.assertEquals( "dn=\\# a leading pound", name.toString() );
        Assert.assertEquals( "dn=\\# a leading pound", name.getUpName() );
    }
 
@@ -2638,7 +2647,7 @@
    {
        LdapDN name = new LdapDN( "cn=Bush\\, Kate,dc=example,dc=com" );
 
-       Assert.assertEquals( "cn=Bush, Kate,dc=example,dc=com", name.toString() );
+       Assert.assertEquals( "cn=Bush\\, Kate,dc=example,dc=com", name.toString() );
        Assert.assertEquals( "cn=Bush\\, Kate,dc=example,dc=com", name.getUpName() );
 
    }
@@ -2666,5 +2675,13 @@
        LdapDN dn = new LdapDN();
        dn.addAll( compoundName );
        System.out.println( dn.toString() );
+   }
+   
+   public void testDNEquals() throws NamingException
+   {
+       LdapDN dn1 = new LdapDN( "a=b,c=d,e=f" );
+       LdapDN dn2 = new LdapDN( "a=b\\,c\\=d,e=f" );
+       
+       assertFalse( dn1.toString().equals( dn2.toString() ) );
    }
 }

Modified: directory/branches/shared/0.9.5/ldap/src/test/java/org/apache/directory/shared/ldap/name/LdapDnParserTest.java
URL: http://svn.apache.org/viewvc/directory/branches/shared/0.9.5/ldap/src/test/java/org/apache/directory/shared/ldap/name/LdapDnParserTest.java?view=diff&rev=486780&r1=486779&r2=486780
==============================================================================
--- directory/branches/shared/0.9.5/ldap/src/test/java/org/apache/directory/shared/ldap/name/LdapDnParserTest.java (original)
+++ directory/branches/shared/0.9.5/ldap/src/test/java/org/apache/directory/shared/ldap/name/LdapDnParserTest.java Wed Dec 13 10:06:39 2006
@@ -193,9 +193,8 @@
    public void testLdapDNPairCharAttributeValue() throws NamingException
    {
        NameParser dnParser = LdapDnParser.getNameParser();
-       String expected = StringTools.utf8ToString( new byte[]{'a', '=', ',', '=', '+', '<', '>', '#', ';', '\\', '"', (byte)0xC3, (byte)0xA9});
        LdapDN dn = ( LdapDN ) dnParser.parse( "a = \\,\\=\\+\\<\\>\\#\\;\\\\\\\"\\C3\\A9" );
-       Assert.assertEquals( expected, dn.toString() );
+       Assert.assertEquals( "a=\\,=\\+\\<\\>#\\;\\\\\\\"\\C3\\A9", dn.toString() );
        Assert.assertEquals( "a = \\,\\=\\+\\<\\>\\#\\;\\\\\\\"\\C3\\A9", dn.getUpName() );
    }
 
@@ -219,7 +218,7 @@
    {
        NameParser dnParser = LdapDnParser.getNameParser();
        LdapDN dn = ( LdapDN ) dnParser.parse( "a = quoted \\\"value" );
-       Assert.assertEquals( "a=quoted \"value", dn.toString() );
+       Assert.assertEquals( "a=quoted \\\"value", dn.toString() );
        Assert.assertEquals( "a = quoted \\\"value", dn.getUpName() );
    }
 
@@ -244,14 +243,11 @@
        String dn = StringTools.utf8ToString( new byte[]{'C', 'N', ' ', '=', ' ', 'E', 'm', 'm', 'a', 'n', 'u', 'e', 
            'l', ' ', ' ', 'L', (byte)0xc3, (byte)0xa9, 'c', 'h', 'a', 'r', 'n', 'y'} );
 
-       String expected = StringTools.utf8ToString( new byte[]{'c', 'n', '=','E', 'm', 'm', 'a', 'n', 'u', 'e', 
-           'l', ' ', ' ', 'L', (byte)0xc3, (byte)0xa9, 'c', 'h', 'a', 'r', 'n', 'y'} );
-
        NameParser dnParser = LdapDnParser.getNameParser();
        LdapDN name = ( LdapDN ) dnParser.parse( dn );
 
        Assert.assertEquals( dn, name.getUpName() );
-       Assert.assertEquals( expected, name.toString() );
+       Assert.assertEquals( "cn=Emmanuel  L\\C3\\A9charny", name.toString() );
    }
 
 
@@ -387,7 +383,7 @@
 
        assertEquals( "RFC2253_3 : ", "CN=L. Eagle,   O=Sue\\, Grabbit and Runn, C=GB", ( ( LdapDN ) nameRFC2253_3 )
            .getUpName() );
-       assertEquals( "RFC2253_3 : ", "cn=L. Eagle,o=Sue, Grabbit and Runn,c=GB", nameRFC2253_3.toString() );
+       assertEquals( "RFC2253_3 : ", "cn=L. Eagle,o=Sue\\, Grabbit and Runn,c=GB", nameRFC2253_3.toString() );
    }
 
 
@@ -475,7 +471,7 @@
        NameParser parser = LdapDnParser.getNameParser();
        String input = "ou=some test\\,  something else";
        String result = parser.parse( input ).toString();
-       assertEquals( "ou=some test,  something else", result );
+       assertEquals( "ou=some test\\,  something else", result );
    }
 
 
@@ -486,19 +482,19 @@
        NameParser parser = LdapDnParser.getNameParser();
        Name result = parser.parse( path );
        assertEquals( path, ( ( LdapDN ) result ).getUpName() );
-       assertEquals( "windowsfilepath=C:\\cygwin", result.toString() );
+       assertEquals( "windowsfilepath=C:\\\\cygwin", result.toString() );
    }
 
 
    public void testNameFrenchChars() throws Exception
    {
        String cn = new String( new byte[]
-           { 'c', 'n', '=', 0x4A, ( byte ) 0xC3, ( byte ) 0xA9, 0x72, ( byte ) 0xC3, ( byte ) 0xB4, 0x6D, 0x65 } );
+           { 'c', 'n', '=', 0x4A, ( byte ) 0xC3, ( byte ) 0xA9, 0x72, ( byte ) 0xC3, ( byte ) 0xB4, 0x6D, 0x65 }, "UTF-8" );
 
        NameParser parser = LdapDnParser.getNameParser();
        String result = parser.parse( cn ).toString();
 
-       assertEquals( cn, result.toString() );
+       assertEquals( "cn=J\\C3\\A9r\\C3\\B4me", result.toString() );
 
    }
 
@@ -513,7 +509,7 @@
        NameParser parser = LdapDnParser.getNameParser();
        String result = parser.parse( cn ).toString();
 
-       assertEquals( cn, result.toString() );
+       assertEquals( "cn=\\C3\\84\\C3\\96\\C3\\9C\\C3\\9F\\C3\\A4\\C3\\B6\\C3\\BC", result.toString() );
    }
 
 
@@ -528,7 +524,7 @@
        NameParser parser = LdapDnParser.getNameParser();
        String result = parser.parse( cn ).toString();
 
-       assertEquals( cn, result.toString() );
+       assertEquals( "cn=\\C4\\B0\\C4\\B1\\C5\\9E\\C5\\9F\\C3\\96\\C3\\B6\\C3\\9C\\C3\\BC\\C4\\9E\\C4\\9F", result.toString() );
 
    }
 
@@ -542,11 +538,12 @@
    public final void testNonEscapedChars() throws NamingException
    {
        NameParser parser = LdapDnParser.getNameParser();
-       String input = "ou=ou=test";
+       String input = "ou=ou+test";
 
        try
        {
-           parser.parse( input ).toString();
+           String res = parser.parse( input ).toString();
+           System.out.println( res);
        }
        catch ( NamingException ne )
        {

Modified: directory/branches/shared/0.9.5/ldap/src/test/java/org/apache/directory/shared/ldap/name/RdnTest.java
URL: http://svn.apache.org/viewvc/directory/branches/shared/0.9.5/ldap/src/test/java/org/apache/directory/shared/ldap/name/RdnTest.java?view=diff&rev=486780&r1=486779&r2=486780
==============================================================================
--- directory/branches/shared/0.9.5/ldap/src/test/java/org/apache/directory/shared/ldap/name/RdnTest.java (original)
+++ directory/branches/shared/0.9.5/ldap/src/test/java/org/apache/directory/shared/ldap/name/RdnTest.java Wed Dec 13 10:06:39 2006
@@ -183,9 +183,10 @@
     */
    public void testRdnPairCharAttributeValue() throws InvalidNameException
    {
-       String rdn = StringTools.utf8ToString( new byte[]{'a', '=', ',', '=', '+', '<', '>', '#', ';', '\\', '"', (byte)0xC3, (byte)0xA9});
+       String rdn = StringTools.utf8ToString( new byte[]{'a', '=', '\\', ',', '=', '\\', '+', '\\', '<', 
+           '\\', '>', '#', '\\', ';', '\\', '\\', '\\', '"', '\\', 'C', '3', '\\', 'A', '9' });
        Assert.assertEquals( rdn, new Rdn(
-           "a = \\,\\=\\+\\<\\>\\#\\;\\\\\\\"\\C3\\A9" ).toString() );
+           "a = \\,=\\+\\<\\>#\\;\\\\\\\"\\C3\\A9" ).toString() );
    }
 
 
@@ -203,7 +204,7 @@
     */
    public void testRdnQuotedAttributeValue() throws InvalidNameException
    {
-       Assert.assertEquals( "a=quoted \"value", new Rdn( "a = quoted \\\"value" ).toString() );
+       Assert.assertEquals( "a=quoted \\\"value", new Rdn( "a = quoted \\\"value" ).toString() );
    }