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/27 15:58:22 UTC

svn commit: r291941 - in /directory/shared/ldap/branches/shared-ldap-NameComponent/apache2-provider/src/java/main/org/apache/asn1new/ldap/codec/primitives: LdapRDN.java LdapString.java

Author: elecharny
Date: Tue Sep 27 06:58:18 2005
New Revision: 291941

URL: http://svn.apache.org/viewcvs?rev=291941&view=rev
Log:
Committed to be able to work at home

Modified:
    directory/shared/ldap/branches/shared-ldap-NameComponent/apache2-provider/src/java/main/org/apache/asn1new/ldap/codec/primitives/LdapRDN.java
    directory/shared/ldap/branches/shared-ldap-NameComponent/apache2-provider/src/java/main/org/apache/asn1new/ldap/codec/primitives/LdapString.java

Modified: directory/shared/ldap/branches/shared-ldap-NameComponent/apache2-provider/src/java/main/org/apache/asn1new/ldap/codec/primitives/LdapRDN.java
URL: http://svn.apache.org/viewcvs/directory/shared/ldap/branches/shared-ldap-NameComponent/apache2-provider/src/java/main/org/apache/asn1new/ldap/codec/primitives/LdapRDN.java?rev=291941&r1=291940&r2=291941&view=diff
==============================================================================
--- directory/shared/ldap/branches/shared-ldap-NameComponent/apache2-provider/src/java/main/org/apache/asn1new/ldap/codec/primitives/LdapRDN.java (original)
+++ directory/shared/ldap/branches/shared-ldap-NameComponent/apache2-provider/src/java/main/org/apache/asn1new/ldap/codec/primitives/LdapRDN.java Tue Sep 27 06:58:18 2005
@@ -269,7 +269,7 @@
     
     public int getLength()
     {
-        return 
+        return 0;
     }
     
     /**

Modified: directory/shared/ldap/branches/shared-ldap-NameComponent/apache2-provider/src/java/main/org/apache/asn1new/ldap/codec/primitives/LdapString.java
URL: http://svn.apache.org/viewcvs/directory/shared/ldap/branches/shared-ldap-NameComponent/apache2-provider/src/java/main/org/apache/asn1new/ldap/codec/primitives/LdapString.java?rev=291941&r1=291940&r2=291941&view=diff
==============================================================================
--- directory/shared/ldap/branches/shared-ldap-NameComponent/apache2-provider/src/java/main/org/apache/asn1new/ldap/codec/primitives/LdapString.java (original)
+++ directory/shared/ldap/branches/shared-ldap-NameComponent/apache2-provider/src/java/main/org/apache/asn1new/ldap/codec/primitives/LdapString.java Tue Sep 27 06:58:18 2005
@@ -20,8 +20,7 @@
 
 import javax.naming.InvalidNameException;
 
-import org.apache.asn1.codec.DecoderException;
-import org.apache.asn1new.util.MutableString;
+import org.apache.asn1new.util.StringUtils;
 
 /**
  * Decodes a LdapString, and checks that the character set used comply
@@ -30,8 +29,11 @@
  * 
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  */
-public class LdapString extends MutableString
+public class LdapString
 {
+	/** The internal representation of a LdapString */
+	private String ldapString;
+	
     /** A null LdapString */
     public transient static final LdapString EMPTY_STRING = new LdapString();
 
@@ -41,34 +43,55 @@
      */
     public LdapString()
     {
-        super( 0, false );
     }
     
     //~ Methods ------------------------------------------------------------------------------------
 
     /**
-     * Transform a byte array to a MutableString. The byte array contains
+     * Transform a byte array to a String. The byte array contains
      * an UTF-8 representation of a String
      * 
      * @param bytes The byte buffer that contains the LDAPSTRING
-     * @return A MutableString containing the LDAPSTRING
      * 
-     * @throws DecoderException If the byte array does not comply with RFC 2279
+     * @throws UnsupportedEncodingException If the byte array is not a valid UTF-8 String
      */
-    public LdapString( byte[] bytes ) throws DecoderException
+    public LdapString( byte[] bytes ) throws UnsupportedEncodingException
     {
         if ( bytes == null )
         {
             return;
         }
         
-        try
-        {
-            setData( bytes, 0, bytes.length );
-        }
-        catch ( UnsupportedEncodingException ine )
-        {
-            throw new DecoderException( "Incorrect LdapString given : " + ine.getMessage() );
-        }
+        ldapString = new String( bytes, "UTF-8" );
+    }
+    
+    /**
+     * Get the ldapString
+     * @return The LdapString
+     */
+    public String toString()
+    {
+    	return ldapString;
+    }
+ 
+    public byte[] getBytes() throws UnsupportedEncodingException
+    {
+        return ldapString.getBytes( "UTF-8" );
+    }
+    /**
+     * Get the number of bytes necessary to encode this LdapString
+     * 
+     * @return The number of bytes of the current LdapString
+     */
+    public int getLength()
+    {
+    	try 
+    	{
+    		return ( StringUtils.isEmpty( ldapString ) ? 0 : ldapString.getBytes( "UTF-8").length );
+    	}
+    	catch ( UnsupportedEncodingException ine )
+    	{
+    		return 0;
+    	}
     }
 }