You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by el...@apache.org on 2005/09/24 19:43:40 UTC

svn commit: r291328 - in /directory/shared/ldap/trunk/apache2-provider/src/java/main/org/apache/asn1new/ldap/codec/primitives: LdapDN.java LdapString.java LdapURL.java RelativeLdapDN.java

Author: elecharny
Date: Sat Sep 24 10:43:33 2005
New Revision: 291328

URL: http://svn.apache.org/viewcvs?rev=291328&view=rev
Log:
Modified all the "new String( byte[] )" by "new String( byte[], "UTF-8" )

Modified:
    directory/shared/ldap/trunk/apache2-provider/src/java/main/org/apache/asn1new/ldap/codec/primitives/LdapDN.java
    directory/shared/ldap/trunk/apache2-provider/src/java/main/org/apache/asn1new/ldap/codec/primitives/LdapString.java
    directory/shared/ldap/trunk/apache2-provider/src/java/main/org/apache/asn1new/ldap/codec/primitives/LdapURL.java
    directory/shared/ldap/trunk/apache2-provider/src/java/main/org/apache/asn1new/ldap/codec/primitives/RelativeLdapDN.java

Modified: directory/shared/ldap/trunk/apache2-provider/src/java/main/org/apache/asn1new/ldap/codec/primitives/LdapDN.java
URL: http://svn.apache.org/viewcvs/directory/shared/ldap/trunk/apache2-provider/src/java/main/org/apache/asn1new/ldap/codec/primitives/LdapDN.java?rev=291328&r1=291327&r2=291328&view=diff
==============================================================================
--- directory/shared/ldap/trunk/apache2-provider/src/java/main/org/apache/asn1new/ldap/codec/primitives/LdapDN.java (original)
+++ directory/shared/ldap/trunk/apache2-provider/src/java/main/org/apache/asn1new/ldap/codec/primitives/LdapDN.java Sat Sep 24 10:43:33 2005
@@ -16,6 +16,8 @@
  */
 package org.apache.asn1new.ldap.codec.primitives;
 
+import java.io.UnsupportedEncodingException;
+
 import org.apache.asn1.codec.DecoderException;
 import org.apache.asn1new.util.StringUtils;
 
@@ -111,7 +113,15 @@
         }
         else
         {
-            throw new DecoderException( "Bad DN : " + new String( bytes) );
+            try 
+            {
+                throw new DecoderException( "Bad DN : " + new String( bytes, "UTF-8" ) );
+            }
+            catch ( UnsupportedEncodingException uee )
+            {
+                throw new DecoderException( "Bad DN : " + StringUtils.dumpBytes( bytes ) );
+            }
+            
         }
 
         setData(bytes);

Modified: directory/shared/ldap/trunk/apache2-provider/src/java/main/org/apache/asn1new/ldap/codec/primitives/LdapString.java
URL: http://svn.apache.org/viewcvs/directory/shared/ldap/trunk/apache2-provider/src/java/main/org/apache/asn1new/ldap/codec/primitives/LdapString.java?rev=291328&r1=291327&r2=291328&view=diff
==============================================================================
--- directory/shared/ldap/trunk/apache2-provider/src/java/main/org/apache/asn1new/ldap/codec/primitives/LdapString.java (original)
+++ directory/shared/ldap/trunk/apache2-provider/src/java/main/org/apache/asn1new/ldap/codec/primitives/LdapString.java Sat Sep 24 10:43:33 2005
@@ -53,6 +53,11 @@
      */
     public LdapString( byte[] bytes ) throws DecoderException
     {
+        init( bytes );
+    }
+    
+    protected void init( byte[] bytes ) throws DecoderException
+    {
         if ( bytes == null )
         {
             return;

Modified: directory/shared/ldap/trunk/apache2-provider/src/java/main/org/apache/asn1new/ldap/codec/primitives/LdapURL.java
URL: http://svn.apache.org/viewcvs/directory/shared/ldap/trunk/apache2-provider/src/java/main/org/apache/asn1new/ldap/codec/primitives/LdapURL.java?rev=291328&r1=291327&r2=291328&view=diff
==============================================================================
--- directory/shared/ldap/trunk/apache2-provider/src/java/main/org/apache/asn1new/ldap/codec/primitives/LdapURL.java (original)
+++ directory/shared/ldap/trunk/apache2-provider/src/java/main/org/apache/asn1new/ldap/codec/primitives/LdapURL.java Sat Sep 24 10:43:33 2005
@@ -25,6 +25,7 @@
 import org.apache.ldap.common.filter.FilterParserImpl;
 
 import java.io.IOException;
+import java.io.UnsupportedEncodingException;
 
 import java.text.ParseException;
 
@@ -112,31 +113,11 @@
         extensions         = new HashMap();
         criticalExtensions = new HashMap();
     }
-
-    /**
-     * Create a new LdapURL from a String after having parsed it.
-     * 
-     * @param string TheString that contains the LDAPURL
-     * @return A MutableString containing the LDAPURL
-     * 
-     * @throws DecoderException If the String does not comply with RFC 2255
-     */
-    public LdapURL( String string ) throws DecoderException
-    {
-    	this( string.getBytes() );
-    }
     
-    /**
-     * Create a new LdapURL after having parsed it.
-     * 
-     * @param bytes The byte buffer that contains the LDAPURL
-     * @return A MutableString containing the LDAPURL
-     * 
-     * @throws DecoderException If the byte array does not comply with RFC 2255
-     */
-    public LdapURL(  byte[] bytes ) throws DecoderException
+    protected void init( byte[] bytes) throws DecoderException
     {
-        super(bytes);
+        super.init( bytes );
+        
         host               = null;
         port               = -1;
         dn                 = null;
@@ -287,6 +268,39 @@
         }
     }
 
+    /**
+     * Create a new LdapURL from a String after having parsed it.
+     * 
+     * @param string TheString that contains the LDAPURL
+     * @return A MutableString containing the LDAPURL
+     * 
+     * @throws DecoderException If the String does not comply with RFC 2255
+     */
+    public LdapURL( String string ) throws DecoderException
+    {
+        try 
+        {
+            init( string.getBytes( "UTF-8" ) );
+        }
+        catch ( UnsupportedEncodingException uee )
+        {
+            throw new DecoderException( "Bad Ldap URL : " + string );
+        }
+    }
+    
+    /**
+     * Create a new LdapURL after having parsed it.
+     * 
+     * @param bytes The byte buffer that contains the LDAPURL
+     * @return A MutableString containing the LDAPURL
+     * 
+     * @throws DecoderException If the byte array does not comply with RFC 2255
+     */
+    public LdapURL(  byte[] bytes ) throws DecoderException
+    {
+        init( bytes );
+    }
+
     //~ Methods ------------------------------------------------------------------------------------
 
     /**
@@ -439,7 +453,15 @@
             return -1;
         }
 
-        host = new String( bytes, start, pos - start );
+        try 
+        {
+            host = new String( bytes, start, pos - start, "UTF-8" );
+        }
+        catch (UnsupportedEncodingException uee)
+        {
+            
+        }
+        
         return pos;
     }
 
@@ -563,7 +585,7 @@
      * @param pos the starting position
      * @return -1 if the bytes array does not contains attributes 
      */
-    private int parseAttributes( byte[] bytes, int pos )
+    private int parseAttributes( byte[] bytes, int pos ) throws DecoderException
     {
 
         int     start       = pos;
@@ -589,9 +611,18 @@
                     }
                     else
                     {
+                        String attribute = null;
 
                         // get the attribute. It must not be blank
-                        String attribute = new String( bytes, start, end - start ).trim();
+                        try
+                        {
+                            attribute = new String( bytes, start, end - start, "UTF-8" ).trim();
+                        }
+                        catch ( UnsupportedEncodingException uee )
+                        {
+                            throw new DecoderException( "Bad Ldap URL : " + uee.getMessage() );
+                        }
+                        
 
                         if ( attribute.length() == 0 )
                         {
@@ -636,7 +667,16 @@
 
                 // Store the last attribute
                 // get the attribute. It must not be blank
-                String attribute = new String( bytes, start, end - start ).trim();
+                String attribute = null;
+
+                try
+                {
+                    attribute = new String( bytes, start, end - start, "UTF-8" ).trim();
+                }
+                catch (UnsupportedEncodingException uee)
+                {
+                    throw new DecoderException( "Bad Ldap URL : " + uee.getMessage() );
+                }
 
                 if ( attribute.length() == 0 )
                 {
@@ -680,7 +720,7 @@
 
         try
         {
-            filter       = URIUtil.decode( new String( bytes, pos, end - pos ) );
+            filter       = URIUtil.decode( new String( bytes, pos, end - pos, "UTF-8" ) );
             filterParser.parse( filter );
         }
         catch ( URIException ue )
@@ -796,7 +836,7 @@
      * @param pos the starting position
      * @return -1 if the bytes array does not contains valid extensions or critical extensions 
      */
-    private int parseExtensions( byte[] bytes, int pos )
+    private int parseExtensions( byte[] bytes, int pos ) throws DecoderException
     {
 
         int     start          = pos;
@@ -829,8 +869,15 @@
                     }
                     else
                     {
-                        value = new String( URIUtil.decode( new String( bytes, start, i - start ) ) )
-                            .trim();
+                        try
+                        {
+                            value = new String( URIUtil.decode( new String( bytes, start, i - start, "UTF-8" ) ) )
+                                .trim();
+                        }
+                        catch ( UnsupportedEncodingException uee )
+                        {
+                            throw new DecoderException( "Bad Ldap URL : " + uee.getMessage() );
+                        }
 
                         if ( value.length() == 0 )
                         {
@@ -865,8 +912,15 @@
                     }
 
                     // An optionnal value
-                    extension = new String( URIUtil.decode( new String( bytes, start, i - start ) ) )
-                        .trim();
+                    try
+                    {
+                        extension = new String( URIUtil.decode( new String( bytes, start, i - start, "UTF-8" ) ) )
+                            .trim();
+                    }
+                    catch ( UnsupportedEncodingException uee )
+                    {
+                        throw new DecoderException( "Bad Ldap URL : " + uee.getMessage() );
+                    }
 
                     if ( extension.length() == 0 )
                     {
@@ -896,13 +950,27 @@
 
             if ( extension == null )
             {
+                try
+                {
                 extension = new String( URIUtil.decode(
-                            new String( bytes, start, bytes.length - start ) ) ).trim();
+                            new String( bytes, start, bytes.length - start, "UTF-8" ) ) ).trim();
+                }
+                catch ( UnsupportedEncodingException uee )
+                {
+                    throw new DecoderException( "Bad Ldap URL : " + uee.getMessage() );
+                }
             }
             else
             {
+                try
+                {
                 value = new String( URIUtil.decode(
-                            new String( bytes, start, bytes.length - start ) ) ).trim();
+                            new String( bytes, start, bytes.length - start, "UTF-8" ) ) ).trim();
+                }
+                catch ( UnsupportedEncodingException uee )
+                {
+                    throw new DecoderException( "Bad value : " + uee.getMessage() );
+                }
             }
 
             if ( isCritical )

Modified: directory/shared/ldap/trunk/apache2-provider/src/java/main/org/apache/asn1new/ldap/codec/primitives/RelativeLdapDN.java
URL: http://svn.apache.org/viewcvs/directory/shared/ldap/trunk/apache2-provider/src/java/main/org/apache/asn1new/ldap/codec/primitives/RelativeLdapDN.java?rev=291328&r1=291327&r2=291328&view=diff
==============================================================================
--- directory/shared/ldap/trunk/apache2-provider/src/java/main/org/apache/asn1new/ldap/codec/primitives/RelativeLdapDN.java (original)
+++ directory/shared/ldap/trunk/apache2-provider/src/java/main/org/apache/asn1new/ldap/codec/primitives/RelativeLdapDN.java Sat Sep 24 10:43:33 2005
@@ -16,6 +16,8 @@
  */
 package org.apache.asn1new.ldap.codec.primitives;
 
+import java.io.UnsupportedEncodingException;
+
 import org.apache.asn1.codec.DecoderException;
 import org.apache.asn1new.util.MutableString;
 import org.apache.asn1new.util.StringUtils;
@@ -484,7 +486,14 @@
         // Parse the name component
         if ( ( pos = parseNameComponent( bytes, pos ) ) == -1 )
         {
-            throw new DecoderException( "Bad relative DN : " + new String( bytes) );
+            try
+            {
+                throw new DecoderException( "Bad relative DN : " + new String( bytes, "UTF-8" ) );
+            }
+            catch (UnsupportedEncodingException uee)
+            {
+                throw new DecoderException( "Bad relative DN : " + StringUtils.dumpBytes( bytes ) );
+            }
         }
         
         setData(bytes);