directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r307426 - /directory/shared/ldap/trunk/apache2-provider/src/java/main/org/apache/asn1new/ldap/codec/primitives/LdapURL.java
Date Sun, 09 Oct 2005 13:44:54 GMT
Author: elecharny
Date: Sun Oct  9 06:44:49 2005
New Revision: 307426

URL: http://svn.apache.org/viewcvs?rev=307426&view=rev
Log:
* parse a LdapURL using char[] instead of bytes
* added a method to deal with the scheme
* throw a LdapURLException instead of a DecoderException

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

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=307426&r1=307425&r2=307426&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
Sun Oct  9 06:44:49 2005
@@ -34,6 +34,7 @@
 import java.util.HashSet;
 import java.util.Iterator;
 
+import javax.naming.InvalidNameException;
 import javax.naming.directory.SearchControls;
 
 
@@ -64,13 +65,16 @@
     //~ Static fields/initializers -----------------------------------------------------------------
 
     /** A null LdapURL */
-    public static final transient LdapURL EMPTY_STRING = new LdapURL();
+    public static final transient LdapURL EMPTY_URL = new LdapURL();
 
     /** The filter parser */
     private static FilterParserImpl filterParser = new FilterParserImpl();
 
     //~ Instance fields ----------------------------------------------------------------------------
 
+    /** The scheme */
+    private String scheme;
+    
     /** The host */
     private String host;
 
@@ -114,10 +118,8 @@
         criticalExtensions = new HashMap();
     }
     
-    protected void init( byte[] bytes) throws DecoderException
+    public void parse( char[] chars) throws LdapURLEncodingException
     {
-        super.init( bytes );
-        
         host               = null;
         port               = -1;
         dn                 = null;
@@ -127,7 +129,7 @@
         extensions         = new HashMap();
         criticalExtensions = new HashMap();
 
-        if ( ( bytes == null ) || ( bytes.length == 0 ) )
+        if ( ( chars == null ) || ( chars.length == 0 ) )
         {
             host = "";
             return;
@@ -141,130 +143,135 @@
         int pos = 0;
 
         // The scheme
-        if ( ( pos = StringUtils.areEquals( bytes, pos, "ldap://" ) ) == -1 )
+        if ( ( ( pos = StringUtils.areEquals( chars, 0, "ldap://" ) ) == StringUtils.NOT_EQUAL
)
+             && ( ( pos = StringUtils.areEquals( chars, 0, "ldaps://" ) ) == StringUtils.NOT_EQUAL
) )
+        {
+            throw new LdapURLEncodingException( "A LdapUrl must start with \"ldap://\" or
\"ldaps://\"" );
+        }
+        else
         {
-            throw new DecoderException( "A LdapUrl must start with \"ldap://\"" );
+            scheme = new String( chars, 0, pos );
         }
 
         // The hostport
-        if ( ( pos = parseHostPort( bytes, pos ) ) == -1 )
+        if ( ( pos = parseHostPort( chars, pos ) ) == -1 )
         {
-            throw new DecoderException( "The hostport is invalid" );
+            throw new LdapURLEncodingException( "The hostport is invalid" );
         }
 
-        if ( pos == bytes.length )
+        if ( pos == chars.length )
         {
             return;
         }
 
         // An optional '/'
-        if ( StringUtils.isCharASCII( bytes, pos, '/' ) == false )
+        if ( StringUtils.isCharASCII( chars, pos, '/' ) == false )
         {
-            throw new DecoderException( "Bad character, position " + pos + ", '" + bytes[pos]
+
+            throw new LdapURLEncodingException( "Bad character, position " + pos + ", '"
+ chars[pos] +
                 "', '/' expected" );
         }
 
         pos++;
 
-        if ( pos == bytes.length )
+        if ( pos == chars.length )
         {
             return;
         }
 
         // An optional DN
-        if ( ( pos = parseDN( bytes, pos ) ) == -1 )
+        if ( ( pos = parseDN( chars, pos ) ) == -1 )
         {
-            throw new DecoderException( "The DN is invalid" );
+            throw new LdapURLEncodingException( "The DN is invalid" );
         }
 
-        if ( pos == bytes.length )
+        if ( pos == chars.length )
         {
             return;
         }
 
         // Optionals attributes
-        if ( StringUtils.isCharASCII( bytes, pos, '?' ) == false )
+        if ( StringUtils.isCharASCII( chars, pos, '?' ) == false )
         {
-            throw new DecoderException( "Bad character, position " + pos + ", '" + bytes[pos]
+
+            throw new LdapURLEncodingException( "Bad character, position " + pos + ", '"
+ chars[pos] +
                 "', '?' expected" );
         }
 
         pos++;
 
-        if ( ( pos = parseAttributes( bytes, pos ) ) == -1 )
+        if ( ( pos = parseAttributes( chars, pos ) ) == -1 )
         {
-            throw new DecoderException( "Attributes are invalid" );
+            throw new LdapURLEncodingException( "Attributes are invalid" );
         }
 
-        if ( pos == bytes.length )
+        if ( pos == chars.length )
         {
             return;
         }
 
         // Optional scope
-        if ( StringUtils.isCharASCII( bytes, pos, '?' ) == false )
+        if ( StringUtils.isCharASCII( chars, pos, '?' ) == false )
         {
-            throw new DecoderException( "Bad character, position " + pos + ", '" + bytes[pos]
+
+            throw new LdapURLEncodingException( "Bad character, position " + pos + ", '"
+ chars[pos] +
                 "', '?' expected" );
         }
 
         pos++;
 
-        if ( ( pos = parseScope( bytes, pos ) ) == -1 )
+        if ( ( pos = parseScope( chars, pos ) ) == -1 )
         {
-            throw new DecoderException( "Scope is invalid" );
+            throw new LdapURLEncodingException( "Scope is invalid" );
         }
 
-        if ( pos == bytes.length )
+        if ( pos == chars.length )
         {
             return;
         }
 
         // Optional filter
-        if ( StringUtils.isCharASCII( bytes, pos, '?' ) == false )
+        if ( StringUtils.isCharASCII( chars, pos, '?' ) == false )
         {
-            throw new DecoderException( "Bad character, position " + pos + ", '" + bytes[pos]
+
+            throw new LdapURLEncodingException( "Bad character, position " + pos + ", '"
+ chars[pos] +
                 "', '?' expected" );
         }
 
         pos++;
 
-        if ( pos == bytes.length )
+        if ( pos == chars.length )
         {
             return;
         }
 
-        if ( ( pos = parseFilter( bytes, pos ) ) == -1 )
+        if ( ( pos = parseFilter( chars, pos ) ) == -1 )
         {
-            throw new DecoderException( "Filter is invalid" );
+            throw new LdapURLEncodingException( "Filter is invalid" );
         }
 
-        if ( pos == bytes.length )
+        if ( pos == chars.length )
         {
             return;
         }
 
         // Optional extensions
-        if ( StringUtils.isCharASCII( bytes, pos, '?' ) == false )
+        if ( StringUtils.isCharASCII( chars, pos, '?' ) == false )
         {
-            throw new DecoderException( "Bad character, position " + pos + ", '" + bytes[pos]
+
+            throw new LdapURLEncodingException( "Bad character, position " + pos + ", '"
+ chars[pos] +
                 "', '?' expected" );
         }
 
         pos++;
 
-        if ( ( pos = parseExtensions( bytes, pos ) ) == -1 )
+        if ( ( pos = parseExtensions( chars, pos ) ) == -1 )
         {
-            throw new DecoderException( "Extensions are invalid" );
+            throw new LdapURLEncodingException( "Extensions are invalid" );
         }
 
-        if ( pos == bytes.length )
+        if ( pos == chars.length )
         {
             return;
         }
         else
         {
-            throw new DecoderException( "Invalid character at the end of the ldapUrl" );
+            throw new LdapURLEncodingException( "Invalid character at the end of the ldapUrl"
);
         }
     }
 
@@ -276,15 +283,17 @@
      * 
      * @throws DecoderException If the String does not comply with RFC 2255
      */
-    public LdapURL( String string ) throws DecoderException
+    public LdapURL( String string ) throws LdapURLEncodingException
     {
         try 
         {
-            init( string.getBytes( "UTF-8" ) );
+            bytes = string.getBytes( "UTF-8" );
+            this.string = string; 
+            parse( string.toCharArray() );
         }
         catch ( UnsupportedEncodingException uee )
         {
-            throw new DecoderException( "Bad Ldap URL : " + string );
+            throw new LdapURLEncodingException( "Bad Ldap URL : " + string );
         }
     }
     
@@ -296,9 +305,19 @@
      * 
      * @throws DecoderException If the byte array does not comply with RFC 2255
      */
-    public LdapURL(  byte[] bytes ) throws DecoderException
+    public LdapURL(  byte[] bytes ) throws LdapURLEncodingException
     {
-        init( bytes );
+        try
+        {
+            string = new String( bytes, "UTF-8" );
+            this.bytes = bytes;
+        }
+        catch ( UnsupportedEncodingException uee )
+        {
+            throw new LdapURLEncodingException( "The byte array is not an UTF-8 encoded Unicode
String : " + uee.getMessage() );
+        }
+        
+        parse( string.toCharArray() );
     }
 
     //~ Methods ------------------------------------------------------------------------------------
@@ -313,13 +332,13 @@
      * <hostnumber>   ::= <digits> "." <digits>
"." <digits> "." <digits>
      * </p>
      * 
-     * @param bytes The buffer to parse
+     * @param chars The buffer to parse
      * @param pos The current position in the byte buffer
      * @return The new position in the byte buffer, or -1 if the rule does not apply to the
byte buffer
      * 
      * TODO check that the topLabel is valid (it must start with an alpha)
      */
-    private int parseHost( byte[] bytes, int pos )
+    private int parseHost( char[] chars, int pos )
     {
 
         int     start        = pos;
@@ -334,17 +353,17 @@
         // the end.
         // We will search the end of the host part, and we will check some
         // elements.
-        if ( StringUtils.isCharASCII( bytes, pos, '-' ) )
+        if ( StringUtils.isCharASCII( chars, pos, '-' ) )
         {
 
             // We can't have a '-' on first position
             return -1;
         }
 
-        while ( ( pos < bytes.length ) && ( bytes[pos] != ':' ) && ( bytes[pos]
!= '/' ) )
+        while ( ( pos < chars.length ) && ( chars[pos] != ':' ) && ( chars[pos]
!= '/' ) )
         {
 
-            if ( StringUtils.isCharASCII( bytes, pos, '.' ) )
+            if ( StringUtils.isCharASCII( chars, pos, '.' ) )
             {
 
                 if ( ( hadMinus ) || ( hadDot ) )
@@ -378,7 +397,7 @@
             else
             {
 
-                if ( hadDot && StringUtils.isCharASCII( bytes, pos, '-' ) )
+                if ( hadDot && StringUtils.isCharASCII( chars, pos, '-' ) )
                 {
 
                     // We can't have a '-' just after a '.'
@@ -388,12 +407,12 @@
                 hadDot = false;
             }
 
-            if ( StringUtils.isDigit( bytes, pos ) )
+            if ( StringUtils.isDigit( chars, pos ) )
             {
 
                 if ( isHostNumber && ( nbDots < 4 ) )
                 {
-                    ipElem[nbDots] = ( ipElem[nbDots] * 10 ) + ( bytes[pos] - '0' );
+                    ipElem[nbDots] = ( ipElem[nbDots] * 10 ) + ( chars[pos] - '0' );
 
                     if ( ipElem[nbDots] > 65535 )
                     {
@@ -403,11 +422,11 @@
 
                 hadMinus = false;
             }
-            else if ( StringUtils.isAlphaDigitMinus( bytes, pos ) )
+            else if ( StringUtils.isAlphaDigitMinus( chars, pos ) )
             {
                 isHostNumber = false;
 
-                if ( StringUtils.isCharASCII( bytes, pos, '-' ) )
+                if ( StringUtils.isCharASCII( chars, pos, '-' ) )
                 {
                     hadMinus = true;
                 }
@@ -453,14 +472,7 @@
             return -1;
         }
 
-        try 
-        {
-            host = new String( bytes, start, pos - start, "UTF-8" );
-        }
-        catch (UnsupportedEncodingException uee)
-        {
-            
-        }
+        host = new String( chars, start, pos - start );
         
         return pos;
     }
@@ -476,25 +488,25 @@
      * 
      * The port must be between 0 and 65535.
      * 
-     * @param bytes The buffer to parse
+     * @param chars The buffer to parse
      * @param pos The current position in the byte buffer
      * @return The new position in the byte buffer, or -1 if the rule does not apply to the
byte buffer
      */
-    private int parsePort( byte[] bytes, int pos )
+    private int parsePort( char[] chars, int pos )
     {
 
-        if ( StringUtils.isDigit( bytes, pos ) == false )
+        if ( StringUtils.isDigit( chars, pos ) == false )
         {
             return -1;
         }
 
-        port = bytes[pos] - '0';
+        port = chars[pos] - '0';
 
         pos++;
 
-        while ( StringUtils.isDigit( bytes, pos ) )
+        while ( StringUtils.isDigit( chars, pos ) )
         {
-            port = ( port * 10 ) + ( bytes[pos] - '0' );
+            port = ( port * 10 ) + ( chars[pos] - '0' );
 
             if ( port > 65535 )
             {
@@ -513,20 +525,20 @@
      * &lt;hostport&gt; ::= &lt;host&gt; ':' &lt;port&gt;
      * </p>
      * 
-     * @param bytes The buffer to parse
+     * @param chars The char array to parse
      * @param pos The current position in the byte buffer
      * @return The new position in the byte buffer, or -1 if the rule does not apply to the
byte buffer
      */
-    private int parseHostPort( byte[] bytes, int pos )
+    private int parseHostPort( char[] chars, int pos )
     {
 
-        if ( ( pos = parseHost( bytes, pos ) ) == -1 )
+        if ( ( pos = parseHost( chars, pos ) ) == -1 )
         {
             return -1;
         }
 
         // We may have a port.
-        if ( StringUtils.isCharASCII( bytes, pos, ':' ) )
+        if ( StringUtils.isCharASCII( chars, pos, ':' ) )
         {
             pos++;
         }
@@ -536,7 +548,7 @@
         }
 
         // As we have a ':', we must have a valid port (between 0 and 65535).
-        if ( ( pos = parsePort( bytes, pos ) ) == -1 )
+        if ( ( pos = parsePort( chars, pos ) ) == -1 )
         {
             return -1;
         }
@@ -548,29 +560,29 @@
      * Parse a string and check that it complies with RFC 2253.
      * Here, we will just call the LdapDN parser to do the job.
      * 
-     * @param bytes The bytes array to be checked
+     * @param chars The char array to be checked
      * @param pos the starting position
-     * @return -1 if the bytes array does not contains a DN 
+     * @return -1 if the char array does not contains a DN 
      */
-    private int parseDN( byte[] bytes, int pos )
+    private int parseDN( char[] chars, int pos )
     {
 
         int end = pos;
 
-        for ( int i = pos; ( i < bytes.length ) && ( bytes[i] != '?' ); i++ )
+        for ( int i = pos; ( i < chars.length ) && ( chars[i] != '?' ); i++ )
         {
             end++;
         }
 
         try
         {
-            dn = new LdapDN( URIUtil.decode( new String( bytes, pos, end - pos ) ).getBytes()
);
+            dn = new LdapDN( URIUtil.decode( new String( chars, pos, end - pos ) ) );
         }
         catch ( URIException ue )
         {
             return -1;
         }
-        catch ( DecoderException de )
+        catch (InvalidNameException de )
         {
             return -1;
         }
@@ -581,11 +593,11 @@
     /**
      * Parse the attributes part
      * 
-     * @param bytes The bytes array to be checked
+     * @param chars The char array to be checked
      * @param pos the starting position
-     * @return -1 if the bytes array does not contains attributes 
+     * @return -1 if the char array does not contains attributes 
      */
-    private int parseAttributes( byte[] bytes, int pos ) throws DecoderException
+    private int parseAttributes( char[] chars, int pos )
     {
 
         int     start       = pos;
@@ -596,10 +608,10 @@
         try
         {
 
-            for ( int i = pos; ( i < bytes.length ) && ( bytes[i] != '?' ); i++
)
+            for ( int i = pos; ( i < chars.length ) && ( chars[i] != '?' ); i++
)
             {
 
-                if ( StringUtils.isCharASCII( bytes, i, ',' ) )
+                if ( StringUtils.isCharASCII( chars, i, ',' ) )
                 {
                     hadComma = true;
 
@@ -614,14 +626,7 @@
                         String attribute = null;
 
                         // get the attribute. It must not be blank
-                        try
-                        {
-                            attribute = new String( bytes, start, end - start, "UTF-8" ).trim();
-                        }
-                        catch ( UnsupportedEncodingException uee )
-                        {
-                            throw new DecoderException( "Bad Ldap URL : " + uee.getMessage()
);
-                        }
+                        attribute = new String( chars, start, end - start ).trim();
                         
 
                         if ( attribute.length() == 0 )
@@ -669,14 +674,7 @@
                 // get the attribute. It must not be blank
                 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() );
-                }
+                attribute = new String( chars, start, end - start ).trim();
 
                 if ( attribute.length() == 0 )
                 {
@@ -704,23 +702,23 @@
     /**
      * Parse the filter part. We will use the FilterParserImpl class
      * 
-     * @param bytes The bytes array to be checked
+     * @param chars The char array to be checked
      * @param pos the starting position
-     * @return -1 if the bytes array does not contains a filter 
+     * @return -1 if the char array does not contains a filter 
      */
-    private int parseFilter( byte[] bytes, int pos )
+    private int parseFilter( char[] chars, int pos )
     {
 
         int end = pos;
 
-        for ( int i = pos; ( i < bytes.length ) && ( bytes[i] != '?' ); i++ )
+        for ( int i = pos; ( i < chars.length ) && ( chars[i] != '?' ); i++ )
         {
             end++;
         }
 
         try
         {
-            filter       = URIUtil.decode( new String( bytes, pos, end - pos, "UTF-8" ) );
+            filter       = URIUtil.decode( new String( chars, pos, end - pos ) );
             filterParser.parse( filter );
         }
         catch ( URIException ue )
@@ -742,30 +740,30 @@
     /**
      * Parse the scope part.
      * 
-     * @param bytes The bytes array to be checked
+     * @param chars The char array to be checked
      * @param pos the starting position
-     * @return -1 if the bytes array does not contains a scope 
+     * @return -1 if the char array does not contains a scope 
      */
-    private int parseScope( byte[] bytes, int pos )
+    private int parseScope( char[] chars, int pos )
     {
 
-        if ( StringUtils.isCharASCII( bytes, pos, 'b' ) ||
-                StringUtils.isCharASCII( bytes, pos, 'B' ) )
+        if ( StringUtils.isCharASCII( chars, pos, 'b' ) ||
+                StringUtils.isCharASCII( chars, pos, 'B' ) )
         {
             pos++;
 
-            if ( StringUtils.isCharASCII( bytes, pos, 'a' ) ||
-                    StringUtils.isCharASCII( bytes, pos, 'A' ) )
+            if ( StringUtils.isCharASCII( chars, pos, 'a' ) ||
+                    StringUtils.isCharASCII( chars, pos, 'A' ) )
             {
                 pos++;
 
-                if ( StringUtils.isCharASCII( bytes, pos, 's' ) ||
-                        StringUtils.isCharASCII( bytes, pos, 'S' ) )
+                if ( StringUtils.isCharASCII( chars, pos, 's' ) ||
+                        StringUtils.isCharASCII( chars, pos, 'S' ) )
                 {
                     pos++;
 
-                    if ( StringUtils.isCharASCII( bytes, pos, 'e' ) ||
-                            StringUtils.isCharASCII( bytes, pos, 'E' ) )
+                    if ( StringUtils.isCharASCII( chars, pos, 'e' ) ||
+                            StringUtils.isCharASCII( chars, pos, 'E' ) )
                     {
                         pos++;
                         scope = SearchControls.OBJECT_SCOPE;
@@ -774,18 +772,18 @@
                 }
             }
         }
-        else if ( StringUtils.isCharASCII( bytes, pos, 'o' ) ||
-                StringUtils.isCharASCII( bytes, pos, 'O' ) )
+        else if ( StringUtils.isCharASCII( chars, pos, 'o' ) ||
+                StringUtils.isCharASCII( chars, pos, 'O' ) )
         {
             pos++;
 
-            if ( StringUtils.isCharASCII( bytes, pos, 'n' ) ||
-                    StringUtils.isCharASCII( bytes, pos, 'N' ) )
+            if ( StringUtils.isCharASCII( chars, pos, 'n' ) ||
+                    StringUtils.isCharASCII( chars, pos, 'N' ) )
             {
                 pos++;
 
-                if ( StringUtils.isCharASCII( bytes, pos, 'e' ) ||
-                        StringUtils.isCharASCII( bytes, pos, 'E' ) )
+                if ( StringUtils.isCharASCII( chars, pos, 'e' ) ||
+                        StringUtils.isCharASCII( chars, pos, 'E' ) )
                 {
                     pos++;
 
@@ -794,18 +792,18 @@
                 }
             }
         }
-        else if ( StringUtils.isCharASCII( bytes, pos, 's' ) ||
-                StringUtils.isCharASCII( bytes, pos, 'S' ) )
+        else if ( StringUtils.isCharASCII( chars, pos, 's' ) ||
+                StringUtils.isCharASCII( chars, pos, 'S' ) )
         {
             pos++;
 
-            if ( StringUtils.isCharASCII( bytes, pos, 'u' ) ||
-                    StringUtils.isCharASCII( bytes, pos, 'U' ) )
+            if ( StringUtils.isCharASCII( chars, pos, 'u' ) ||
+                    StringUtils.isCharASCII( chars, pos, 'U' ) )
             {
                 pos++;
 
-                if ( StringUtils.isCharASCII( bytes, pos, 'b' ) ||
-                        StringUtils.isCharASCII( bytes, pos, 'B' ) )
+                if ( StringUtils.isCharASCII( chars, pos, 'b' ) ||
+                        StringUtils.isCharASCII( chars, pos, 'B' ) )
                 {
                     pos++;
 
@@ -814,7 +812,7 @@
                 }
             }
         }
-        else if ( StringUtils.isCharASCII( bytes, pos, '?' ) )
+        else if ( StringUtils.isCharASCII( chars, pos, '?' ) )
         {
 
             // An empty scope. This is valid
@@ -832,11 +830,11 @@
      * 
      * extensions ::= extension [ ',' extension ]*
      * extension  ::= [ '!' ] ( token | ( 'x-' | 'X-' ) token ) ) [ '=' exvalue ]  
-     * @param bytes The bytes array to be checked
+     * @param char The char array to be checked
      * @param pos the starting position
-     * @return -1 if the bytes array does not contains valid extensions or critical extensions

+     * @return -1 if the char array does not contains valid extensions or critical extensions

      */
-    private int parseExtensions( byte[] bytes, int pos ) throws DecoderException
+    private int parseExtensions( char[] chars, int pos )
     {
 
         int     start          = pos;
@@ -846,7 +844,7 @@
         String  extension      = null;
         String  value          = null;
 
-        if ( pos == bytes.length )
+        if ( pos == chars.length )
         {
             return pos;
         }
@@ -854,10 +852,10 @@
         try
         {
 
-            for ( int i = pos; ( i < bytes.length ); i++ )
+            for ( int i = pos; ( i < chars.length ); i++ )
             {
 
-                if ( StringUtils.isCharASCII( bytes, i, ',' ) )
+                if ( StringUtils.isCharASCII( chars, i, ',' ) )
                 {
 
                     if ( isNewExtension )
@@ -869,15 +867,7 @@
                     }
                     else
                     {
-                        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()
);
-                        }
+                        value = new String( URIUtil.decode( new String( chars, start, i -
start ) ) ).trim();
 
                         if ( value.length() == 0 )
                         {
@@ -901,7 +891,7 @@
                         value          = null;
                     }
                 }
-                else if ( StringUtils.isCharASCII( bytes, i, '=' ) )
+                else if ( StringUtils.isCharASCII( chars, i, '=' ) )
                 {
 
                     if ( hasValue )
@@ -912,15 +902,8 @@
                     }
 
                     // An optionnal value
-                    try
-                    {
-                        extension = new String( URIUtil.decode( new String( bytes, start,
i - start, "UTF-8" ) ) )
+                    extension = new String( URIUtil.decode( new String( chars, start, i -
start ) ) )
                             .trim();
-                    }
-                    catch ( UnsupportedEncodingException uee )
-                    {
-                        throw new DecoderException( "Bad Ldap URL : " + uee.getMessage()
);
-                    }
 
                     if ( extension.length() == 0 )
                     {
@@ -933,7 +916,7 @@
                     hasValue       = true;
                     start          = i + 1;
                 }
-                else if ( StringUtils.isCharASCII( bytes, i, '!' ) )
+                else if ( StringUtils.isCharASCII( chars, i, '!' ) )
                 {
 
                     if ( isNewExtension == false )
@@ -950,27 +933,13 @@
 
             if ( extension == null )
             {
-                try
-                {
                 extension = new String( URIUtil.decode(
-                            new String( bytes, start, bytes.length - start, "UTF-8" ) ) ).trim();
-                }
-                catch ( UnsupportedEncodingException uee )
-                {
-                    throw new DecoderException( "Bad Ldap URL : " + uee.getMessage() );
-                }
+                            new String( chars, start, chars.length - start ) ) ).trim();
             }
             else
             {
-                try
-                {
                 value = new String( URIUtil.decode(
-                            new String( bytes, start, bytes.length - start, "UTF-8" ) ) ).trim();
-                }
-                catch ( UnsupportedEncodingException uee )
-                {
-                    throw new DecoderException( "Bad value : " + uee.getMessage() );
-                }
+                            new String( chars, start, chars.length - start ) ) ).trim();
             }
 
             if ( isCritical )
@@ -982,7 +951,7 @@
                 extensions.put( extension, value );
             }
 
-            return bytes.length;
+            return chars.length;
         }
         catch ( URIException ue )
         {
@@ -1182,5 +1151,77 @@
         }
 
         return sb.toString();
+    }
+
+    /**
+     * @return Returns the attributes.
+     */
+    public ArrayList getAttributes()
+    {
+        return attributes;
+    }
+
+    /**
+     * @return Returns the criticalExtensions.
+     */
+    public HashMap getCriticalExtensions()
+    {
+        return criticalExtensions;
+    }
+
+    /**
+     * @return Returns the dn.
+     */
+    public LdapDN getDn()
+    {
+        return dn;
+    }
+
+    /**
+     * @return Returns the extensions.
+     */
+    public HashMap getExtensions()
+    {
+        return extensions;
+    }
+
+    /**
+     * @return Returns the filter.
+     */
+    public String getFilter()
+    {
+        return filter;
+    }
+
+    /**
+     * @return Returns the host.
+     */
+    public String getHost()
+    {
+        return host;
+    }
+
+    /**
+     * @return Returns the port.
+     */
+    public int getPort()
+    {
+        return port;
+    }
+
+    /**
+     * @return Returns the scope.
+     */
+    public int getScope()
+    {
+        return scope;
+    }
+
+    /**
+     * @return Returns the scheme.
+     */
+    public String getScheme()
+    {
+        return scheme;
     }
 }



Mime
View raw message