directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r1237815 - in /directory: apacheds/trunk/ldap-client-test/src/test/java/org/apache/directory/shared/client/api/operations/search/ shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/entry/ shared/trunk/ldap/model/sr...
Date Mon, 30 Jan 2012 17:31:22 GMT
Author: elecharny
Date: Mon Jan 30 17:31:21 2012
New Revision: 1237815

URL: http://svn.apache.org/viewvc?rev=1237815&view=rev
Log:
o Fixed the test with Unicode chars in the filter
o Fix for DIRAPI-71 (the filter is first translated to an UTF-8 byte[] before being parsed)

Modified:
    directory/apacheds/trunk/ldap-client-test/src/test/java/org/apache/directory/shared/client/api/operations/search/ClientSearchRequestTest.java
    directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/entry/AttributeUtils.java
    directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/filter/FilterParser.java
    directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/message/SearchRequestImpl.java
    directory/shared/trunk/ldap/model/src/test/java/org/apache/directory/shared/ldap/model/filter/FilterParserTest.java
    directory/shared/trunk/util/src/main/java/org/apache/directory/shared/util/Chars.java
    directory/shared/trunk/util/src/main/java/org/apache/directory/shared/util/Strings.java
    directory/shared/trunk/util/src/main/java/org/apache/directory/shared/util/Unicode.java

Modified: directory/apacheds/trunk/ldap-client-test/src/test/java/org/apache/directory/shared/client/api/operations/search/ClientSearchRequestTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/ldap-client-test/src/test/java/org/apache/directory/shared/client/api/operations/search/ClientSearchRequestTest.java?rev=1237815&r1=1237814&r2=1237815&view=diff
==============================================================================
--- directory/apacheds/trunk/ldap-client-test/src/test/java/org/apache/directory/shared/client/api/operations/search/ClientSearchRequestTest.java
(original)
+++ directory/apacheds/trunk/ldap-client-test/src/test/java/org/apache/directory/shared/client/api/operations/search/ClientSearchRequestTest.java
Mon Jan 30 17:31:21 2012
@@ -24,8 +24,6 @@ package org.apache.directory.shared.clie
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.assertFalse;
-
 import java.util.concurrent.TimeUnit;
 
 import org.apache.directory.ldap.client.api.LdapNetworkConnection;
@@ -286,7 +284,12 @@ public class ClientSearchRequestTest ext
     {
         EntryCursor cursor = connection.search( "ou=users,ou=system", "(sn=Emmanuel L\u00E9charny)",
SearchScope.ONELEVEL, "*", "+" );
 
-        assertFalse (cursor.next() );
+        assertTrue(cursor.next() );
+        
+        Entry entry = cursor.get();
+        assertNotNull( entry );
+        assertTrue( entry.contains( "cn", "elecharny" ) );
+        assertTrue( entry.contains( "sn", "Emmanuel L\u00E9charny" ) );
         
         cursor.close();
     }

Modified: directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/entry/AttributeUtils.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/entry/AttributeUtils.java?rev=1237815&r1=1237814&r2=1237815&view=diff
==============================================================================
--- directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/entry/AttributeUtils.java
(original)
+++ directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/entry/AttributeUtils.java
Mon Jan 30 17:31:21 2012
@@ -6,16 +6,16 @@
  *  to you under the Apache License, Version 2.0 (the
  *  "License"); you may not use this file except in compliance
  *  with the License.  You may obtain a copy of the License at
- *  
+ * 
  *    http://www.apache.org/licenses/LICENSE-2.0
- *  
+ * 
  *  Unless required by applicable law or agreed to in writing,
  *  software distributed under the License is distributed on an
  *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  *  KIND, either express or implied.  See the License for the
  *  specific language governing permissions and limitations
- *  under the License. 
- *  
+ *  under the License.
+ * 
  */
 package org.apache.directory.shared.ldap.model.entry;
 
@@ -165,7 +165,7 @@ public final class AttributeUtils
      * option = 1*keychar
      * keychar = 'a'-z' | 'A'-'Z' / '0'-'9' / '-'
      */
-    private static void parseOptions( String str, Position pos ) throws ParseException
+    private static void parseOptions( byte[] str, Position pos ) throws ParseException
     {
         while ( Strings.isCharASCII( str, pos.start, ';' ) )
         {
@@ -196,11 +196,11 @@ public final class AttributeUtils
      * 
      * @return true if a number has been found
      */
-    private static boolean parseNumber( String filter, Position pos )
+    private static boolean parseNumber( byte[] filter, Position pos )
     {
-        char c = Strings.charAt( filter, pos.start );
+        byte b = Strings.byteAt( filter, pos.start );
 
-        switch ( c )
+        switch ( b )
         {
             case '0':
                 // If we get a starting '0', we should get out
@@ -244,7 +244,7 @@ public final class AttributeUtils
      * @param pos The current position in the string
      * @throws ParseException If we don't have a valid OID
      */
-    private static void parseOID( String str, Position pos ) throws ParseException
+    private static void parseOID( byte[] str, Position pos ) throws ParseException
     {
         // We have an OID
         parseNumber( str, pos );
@@ -298,19 +298,19 @@ public final class AttributeUtils
      * @param pos The position of the attribute in the current string
      * @return The parsed attribute if valid
      */
-    public static String parseAttribute( String str, Position pos, boolean withOption ) throws
ParseException
+    public static String parseAttribute( byte[] str, Position pos, boolean withOption ) throws
ParseException
     {
         // We must have an OID or an DESCR first
-        char c = Strings.charAt( str, pos.start );
+        byte b = Strings.byteAt( str, pos.start );
 
-        if ( c == '\0' )
+        if ( b == '\0' )
         {
             throw new ParseException( I18n.err( I18n.ERR_04346 ), pos.start );
         }
 
         int start = pos.start;
 
-        if ( Chars.isAlpha( c ) )
+        if ( Chars.isAlpha( b ) )
         {
             // A DESCR
             pos.start++;
@@ -326,9 +326,9 @@ public final class AttributeUtils
                 parseOptions( str, pos );
             }
 
-            return str.substring( start, pos.start );
+            return Strings.getString( str, start, pos.start - start, "UTF-8" );
         }
-        else if ( Chars.isDigit( c ) )
+        else if ( Chars.isDigit( b ) )
         {
             // An OID
             pos.start++;
@@ -342,7 +342,7 @@ public final class AttributeUtils
                 parseOptions( str, pos );
             }
 
-            return str.substring( start, pos.start );
+            return Strings.getString( str,  start, pos.start - start, "UTF-8" );
         }
         else
         {
@@ -505,7 +505,7 @@ public final class AttributeUtils
             // Looping on attributes
             for ( Iterator<Attribute> attributeIterator = entry.iterator(); attributeIterator.hasNext();
)
             {
-                Attribute entryAttribute = ( Attribute ) attributeIterator.next();
+                Attribute entryAttribute = attributeIterator.next();
 
                 attributes.put( toJndiAttribute( entryAttribute ) );
             }

Modified: directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/filter/FilterParser.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/filter/FilterParser.java?rev=1237815&r1=1237814&r2=1237815&view=diff
==============================================================================
--- directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/filter/FilterParser.java
(original)
+++ directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/filter/FilterParser.java
Mon Jan 30 17:31:21 2012
@@ -6,16 +6,16 @@
  *  to you under the Apache License, Version 2.0 (the
  *  "License"); you may not use this file except in compliance
  *  with the License.  You may obtain a copy of the License at
- *  
+ * 
  *    http://www.apache.org/licenses/LICENSE-2.0
- *  
+ * 
  *  Unless required by applicable law or agreed to in writing,
  *  software distributed under the License is distributed on an
  *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  *  KIND, either express or implied.  See the License for the
  *  specific language governing permissions and limitations
- *  under the License. 
- *  
+ *  under the License.
+ * 
  */
 package org.apache.directory.shared.ldap.model.filter;
 
@@ -58,7 +58,7 @@ public class FilterParser
      *                  / ( [":dn"] ':' oid ":=" assertionvalue )
      * matchingrule   = ":" oid
      */
-    private static ExprNode parseExtensible( SchemaManager schemaManager, String attribute,
String filter, Position pos )
+    private static ExprNode parseExtensible( SchemaManager schemaManager, String attribute,
byte[] filter, Position pos )
         throws LdapException, ParseException
     {
         ExtensibleNode node = null;
@@ -84,7 +84,7 @@ public class FilterParser
         if ( attribute != null )
         {
             // First check if we have a ":dn"
-            if ( Strings.areEquals( filter, pos.start, "dn" ) )
+            if ( Strings.areEquals( filter, pos.start, "dn" ) >= 0 )
             {
                 // Set the dnAttributes flag and move forward in the string
                 node.setDnAttributes( true );
@@ -92,17 +92,17 @@ public class FilterParser
             }
             else
             {
-                // Push back the ':' 
+                // Push back the ':'
                 pos.start--;
             }
 
             // Do we have a MatchingRule ?
-            if ( Strings.charAt( filter, pos.start ) == ':' )
+            if ( Strings.byteAt( filter, pos.start ) == ':' )
             {
                 pos.start++;
                 int start = pos.start;
 
-                if ( Strings.charAt( filter, pos.start ) == '=' )
+                if ( Strings.byteAt( filter, pos.start ) == '=' )
                 {
                     pos.start++;
 
@@ -113,11 +113,11 @@ public class FilterParser
                 }
                 else
                 {
-                    AttributeUtils.parseAttribute( filter, pos, false );
+                    String matchingRuleId = AttributeUtils.parseAttribute( filter, pos, false
);
 
-                    node.setMatchingRuleId( filter.substring( start, pos.start ) );
+                    node.setMatchingRuleId( matchingRuleId );
 
-                    if ( Strings.areEquals( filter, pos.start, ":=" ) )
+                    if ( Strings.areEquals( filter, pos.start, ":=" ) >= 0 )
                     {
                         pos.start += 2;
 
@@ -142,7 +142,7 @@ public class FilterParser
             boolean oidRequested = false;
 
             // First check if we have a ":dn"
-            if ( Strings.areEquals( filter, pos.start, ":dn" ) )
+            if ( Strings.areEquals( filter, pos.start, ":dn" ) >= 0 )
             {
                 // Set the dnAttributes flag and move forward in the string
                 node.setDnAttributes( true );
@@ -154,12 +154,12 @@ public class FilterParser
             }
 
             // Do we have a MatchingRule ?
-            if ( Strings.charAt( filter, pos.start ) == ':' )
+            if ( Strings.byteAt( filter, pos.start ) == ':' )
             {
                 pos.start++;
                 int start = pos.start;
 
-                if ( Strings.charAt( filter, pos.start ) == '=' )
+                if ( Strings.byteAt( filter, pos.start ) == '=' )
                 {
                     if ( oidRequested )
                     {
@@ -175,11 +175,11 @@ public class FilterParser
                 }
                 else
                 {
-                    AttributeUtils.parseAttribute( filter, pos, false );
+                    String matchingRuleId = AttributeUtils.parseAttribute( filter, pos, false
);
 
-                    node.setMatchingRuleId( filter.substring( start, pos.start ) );
+                    node.setMatchingRuleId( matchingRuleId );
 
-                    if ( Strings.areEquals( filter, pos.start, ":=" ) )
+                    if ( Strings.areEquals( filter, pos.start, ":=" ) >= 0 )
                     {
                         pos.start += 2;
 
@@ -203,7 +203,7 @@ public class FilterParser
 
 
     /**
-     * An assertion value : 
+     * An assertion value :
      * assertionvalue = valueencoding
      * valueencoding  = 0*(normal / escaped)
      * normal         = UTF1SUBSET / UTFMB
@@ -223,9 +223,8 @@ public class FilterParser
      *    "0x29), "\" (ASCII 0x5c), and NUL (ASCII 0x00) are represented as a"
      *    "backslash "\" (ASCII 0x5c) followed by the two hexadecimal digits"
      *    "representing the value of the encoded octet."
-
      * 
-     * The incomming String is already transformed from UTF-8 to unicode, so we must assume
that the 
+     * The incoming String is already transformed from UTF-8 to unicode, so we must assume
that the
      * grammar we have to check is the following :
      * 
      * assertionvalue = valueencoding
@@ -235,24 +234,24 @@ public class FilterParser
      * HEX            = '0'-'9' / 'A'-'F' / 'a'-'f'
      * unicodeSubset     = %x01-27 / %x2B-5B / %x5D-FFFF
      */
-    private static Value<?> parseAssertionValue( String filter, Position pos ) throws
ParseException
+    private static Value<?> parseAssertionValue( byte[] filter, Position pos ) throws
ParseException
     {
-        char c = Strings.charAt( filter, pos.start );
+        byte b = Strings.byteAt( filter, pos.start );
 
         // Create a buffer big enough to contain the value once converted
-        byte[] value = new byte[filter.length() - pos.start];
+        byte[] value = new byte[filter.length - pos.start];
         int current = 0;
 
         do
         {
-            if ( Unicode.isUnicodeSubset( c ) )
+            if ( Unicode.isUnicodeSubset( b ) )
             {
-                value[current++] = ( byte ) c;
+                value[current++] = b;
                 pos.start++;
             }
             else if ( Strings.isCharASCII( filter, pos.start, '\\' ) )
             {
-                // Maybe an escaped 
+                // Maybe an escaped
                 pos.start++;
 
                 // First hex
@@ -268,7 +267,7 @@ public class FilterParser
                 // second hex
                 if ( Chars.isHex( filter, pos.start ) )
                 {
-                    value[current++] = Hex.getHexValue( filter.charAt( pos.start - 1 ), filter.charAt(
pos.start ) );
+                    value[current++] = Hex.getHexValue( filter[pos.start - 1], filter[pos.start]
);
                     pos.start++;
                 }
                 else
@@ -282,7 +281,7 @@ public class FilterParser
                 break;
             }
         }
-        while ( ( c = Strings.charAt( filter, pos.start ) ) != '\0' );
+        while ( ( b = Strings.byteAt( filter, pos.start ) ) != '\0' );
 
         if ( current != 0 )
         {
@@ -302,7 +301,7 @@ public class FilterParser
      * Parse a substring
      */
     private static ExprNode parseSubstring( SchemaManager schemaManager, String attribute,
Value<?> initial,
-        String filter, Position pos )
+        byte[] filter, Position pos )
         throws ParseException, LdapException
     {
         if ( Strings.isCharASCII( filter, pos.start, '*' ) )
@@ -338,7 +337,7 @@ public class FilterParser
 
             pos.start++;
 
-            // 
+            //
             while ( true )
             {
                 Value<?> assertionValue = parseAssertionValue( filter, pos );
@@ -359,7 +358,7 @@ public class FilterParser
                 else if ( Strings.isCharASCII( filter, pos.start, '*' ) )
                 {
                     // We have a '*' : it's an any
-                    // If the value is empty, that means we have more than 
+                    // If the value is empty, that means we have more than
                     // one consecutive '*' : do nothing in this case.
                     if ( !assertionValue.isNull() )
                     {
@@ -410,7 +409,7 @@ public class FilterParser
      */
     @SuppressWarnings(
         { "rawtypes", "unchecked" })
-    private static ExprNode parsePresenceEqOrSubstring( SchemaManager schemaManager, String
attribute, String filter,
+    private static ExprNode parsePresenceEqOrSubstring( SchemaManager schemaManager, String
attribute, byte[] filter,
         Position pos )
         throws ParseException, LdapException
     {
@@ -513,22 +512,22 @@ public class FilterParser
      * extensible     = ( attr [":dn"] [':' oid] ":=" assertionvalue )
      *                  / ( [":dn"] ':' oid ":=" assertionvalue )
      * matchingrule   = ":" oid
-     *                  
+     * 
      * An item starts with an attribute or a colon.
      */
     @SuppressWarnings(
         { "rawtypes", "unchecked" })
-    private static ExprNode parseItem( SchemaManager schemaManager, String filter, Position
pos, char c )
+    private static ExprNode parseItem( SchemaManager schemaManager, byte[] filter, Position
pos, byte b )
         throws ParseException, LdapException
     {
         String attribute = null;
 
-        if ( c == '\0' )
+        if ( b == '\0' )
         {
             throw new ParseException( I18n.err( I18n.ERR_04151 ), pos.start );
         }
 
-        if ( c == ':' )
+        if ( b == ':' )
         {
             // If we have a colon, then the item is an extensible one
             return parseExtensible( schemaManager, null, filter, pos );
@@ -539,9 +538,9 @@ public class FilterParser
             attribute = AttributeUtils.parseAttribute( filter, pos, true );
 
             // Now, we may have a present, substring, simple or an extensible
-            c = Strings.charAt( filter, pos.start );
+            b = Strings.byteAt( filter, pos.start );
 
-            switch ( c )
+            switch ( b )
             {
                 case '=':
                     // It can be a presence, an equal or a substring
@@ -664,7 +663,7 @@ public class FilterParser
      * 
      * @return
      */
-    private static ExprNode parseBranchNode( SchemaManager schemaManager, ExprNode node,
String filter, Position pos )
+    private static ExprNode parseBranchNode( SchemaManager schemaManager, ExprNode node,
byte[] filter, Position pos )
         throws ParseException, LdapException
     {
         BranchNode branchNode = ( BranchNode ) node;
@@ -730,7 +729,7 @@ public class FilterParser
      *                    / ( [dnattrs]
      *                         matchingrule COLON EQUALS assertionvalue )
      */
-    private static ExprNode parseFilterComp( SchemaManager schemaManager, String filter,
Position pos )
+    private static ExprNode parseFilterComp( SchemaManager schemaManager, byte[] filter,
Position pos )
         throws ParseException, LdapException
     {
         ExprNode node = null;
@@ -740,7 +739,7 @@ public class FilterParser
             throw new ParseException( I18n.err( I18n.ERR_04154 ), pos.start );
         }
 
-        char c = Strings.charAt( filter, pos.start );
+        byte c = Strings.byteAt( filter, pos.start );
 
         switch ( c )
         {
@@ -780,7 +779,7 @@ public class FilterParser
      * Pasre the grammar rule :
      * filter ::= '(' filterComp ')'
      */
-    private static ExprNode parseFilterInternal( SchemaManager schemaManager, String filter,
Position pos )
+    private static ExprNode parseFilterInternal( SchemaManager schemaManager, byte[] filter,
Position pos )
         throws ParseException, LdapException
     {
         // Check for the left '('
@@ -824,6 +823,15 @@ public class FilterParser
      */
     public static ExprNode parse( String filter ) throws ParseException
     {
+        return parse( null, Strings.getBytesUtf8( filter ) );
+    }
+
+
+    /**
+     * @see FilterParser#parse(String)
+     */
+    public static ExprNode parse( byte[] filter ) throws ParseException
+    {
         return parse( null, filter );
     }
 
@@ -833,6 +841,15 @@ public class FilterParser
      */
     public static ExprNode parse( SchemaManager schemaManager, String filter ) throws ParseException
     {
+        return parse( schemaManager, Strings.getBytesUtf8( filter ) );
+    }
+
+
+    /**
+     * @see FilterParser#parse(String)
+     */
+    public static ExprNode parse( SchemaManager schemaManager, byte[] filter ) throws ParseException
+    {
         // The filter must not be null. This is a defensive test
         if ( Strings.isEmpty( filter ) )
         {
@@ -842,7 +859,7 @@ public class FilterParser
         Position pos = new Position();
         pos.start = 0;
         pos.end = 0;
-        pos.length = filter.length();
+        pos.length = filter.length;
 
         try
         {
@@ -872,7 +889,7 @@ public class FilterParser
 
         try
         {
-            return parseFilterInternal( schemaManager, filter, pos );
+            return parseFilterInternal( schemaManager, Strings.getBytesUtf8( filter ), pos
);
         }
         catch ( LdapException le )
         {

Modified: directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/message/SearchRequestImpl.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/message/SearchRequestImpl.java?rev=1237815&r1=1237814&r2=1237815&view=diff
==============================================================================
--- directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/message/SearchRequestImpl.java
(original)
+++ directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/message/SearchRequestImpl.java
Mon Jan 30 17:31:21 2012
@@ -6,16 +6,16 @@
  *  to you under the Apache License, Version 2.0 (the
  *  "License"); you may not use this file except in compliance
  *  with the License.  You may obtain a copy of the License at
- *  
+ * 
  *    http://www.apache.org/licenses/LICENSE-2.0
- *  
+ * 
  *  Unless required by applicable law or agreed to in writing,
  *  software distributed under the License is distributed on an
  *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  *  KIND, either express or implied.  See the License for the
  *  specific language governing permissions and limitations
- *  under the License. 
- *  
+ *  under the License.
+ * 
  */
 package org.apache.directory.shared.ldap.model.message;
 
@@ -33,6 +33,7 @@ import org.apache.directory.shared.ldap.
 import org.apache.directory.shared.ldap.model.filter.ExprNode;
 import org.apache.directory.shared.ldap.model.filter.FilterParser;
 import org.apache.directory.shared.ldap.model.name.Dn;
+import org.apache.directory.shared.util.Strings;
 
 
 /**
@@ -166,7 +167,7 @@ public class SearchRequestImpl extends A
     {
         try
         {
-            filterNode = FilterParser.parse( filter );
+            filterNode = FilterParser.parse( Strings.getBytesUtf8( filter ) );
         }
         catch ( ParseException pe )
         {

Modified: directory/shared/trunk/ldap/model/src/test/java/org/apache/directory/shared/ldap/model/filter/FilterParserTest.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/model/src/test/java/org/apache/directory/shared/ldap/model/filter/FilterParserTest.java?rev=1237815&r1=1237814&r2=1237815&view=diff
==============================================================================
--- directory/shared/trunk/ldap/model/src/test/java/org/apache/directory/shared/ldap/model/filter/FilterParserTest.java
(original)
+++ directory/shared/trunk/ldap/model/src/test/java/org/apache/directory/shared/ldap/model/filter/FilterParserTest.java
Mon Jan 30 17:31:21 2012
@@ -6,16 +6,16 @@
  *  to you under the Apache License, Version 2.0 (the
  *  "License"); you may not use this file except in compliance
  *  with the License.  You may obtain a copy of the License at
- *  
+ * 
  *    http://www.apache.org/licenses/LICENSE-2.0
- *  
+ * 
  *  Unless required by applicable law or agreed to in writing,
  *  software distributed under the License is distributed on an
  *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  *  KIND, either express or implied.  See the License for the
  *  specific language governing permissions and limitations
- *  under the License. 
- *  
+ *  under the License.
+ * 
  */
 package org.apache.directory.shared.ldap.model.filter;
 
@@ -60,7 +60,7 @@ public class FilterParserTest
 
 
     /**
-     * Tests to avoid deadlocks for invalid filters. 
+     * Tests to avoid deadlocks for invalid filters.
      * 
      */
     @Test
@@ -487,7 +487,7 @@ public class FilterParserTest
     {
         try
         {
-            FilterParser.parse( null );
+            FilterParser.parse( (String)null );
             fail( "Should not reach this point " );
         }
         catch ( ParseException pe )
@@ -732,7 +732,7 @@ public class FilterParserTest
 
             assertEquals( "cn", node.getAttribute() );
             String val = node.getValue().getString();
-            assertEquals( "a2", Integer.toHexString( ( int ) val.charAt( 0 ) ) ); // char
is U+00A2
+            assertEquals( "a2", Integer.toHexString( val.charAt( 0 ) ) ); // char is U+00A2
             String str2 = node.toString();
             assertEquals( str, str2 );
         }
@@ -758,7 +758,7 @@ public class FilterParserTest
 
             assertEquals( "cn", node.getAttribute() );
             String val = node.getValue().getString();
-            assertEquals( "a2", Integer.toHexString( ( int ) val.charAt( 0 ) ) ); // char
is U+00A2
+            assertEquals( "a2", Integer.toHexString( val.charAt( 0 ) ) ); // char is U+00A2
             String str2 = node.toString();
             assertEquals( str, str2 );
         }
@@ -783,7 +783,7 @@ public class FilterParserTest
 
             assertEquals( "cn", node.getAttribute() );
             String val = node.getValue().getString();
-            assertEquals( "2260", Integer.toHexString( ( int ) val.charAt( 0 ) ) );
+            assertEquals( "2260", Integer.toHexString( val.charAt( 0 ) ) );
             String str2 = node.toString();
             assertEquals( str, str2 );
         }
@@ -809,7 +809,7 @@ public class FilterParserTest
 
             assertEquals( "cn", node.getAttribute() );
             String val = node.getValue().getString();
-            assertEquals( "2260", Integer.toHexString( ( int ) val.charAt( 0 ) ) );
+            assertEquals( "2260", Integer.toHexString( val.charAt( 0 ) ) );
             String str2 = node.toString();
             assertEquals( str, str2 );
         }
@@ -834,7 +834,7 @@ public class FilterParserTest
 
             assertEquals( "cn", node.getAttribute() );
             String val = node.getValue().getString();
-            assertEquals( "3059", Integer.toHexString( ( int ) val.charAt( 0 ) ) );
+            assertEquals( "3059", Integer.toHexString( val.charAt( 0 ) ) );
             String str2 = node.toString();
             assertEquals( str, str2 );
         }

Modified: directory/shared/trunk/util/src/main/java/org/apache/directory/shared/util/Chars.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/util/src/main/java/org/apache/directory/shared/util/Chars.java?rev=1237815&r1=1237814&r2=1237815&view=diff
==============================================================================
--- directory/shared/trunk/util/src/main/java/org/apache/directory/shared/util/Chars.java
(original)
+++ directory/shared/trunk/util/src/main/java/org/apache/directory/shared/util/Chars.java
Mon Jan 30 17:31:21 2012
@@ -686,6 +686,20 @@ public final class Chars
 
 
     /**
+     * Test if the current byte is a digit &lt;digit> ::= '0' | '1' | '2' |
+     * '3' | '4' | '5' | '6' | '7' | '8' | '9'
+     *
+     * @param car the byte to test
+     *
+     * @return <code>true</code> if the character is a Digit
+     */
+    public static boolean isDigit( byte car )
+    {
+        return ( car >= '0' ) && ( car <= '9' );
+    }
+
+
+    /**
      * Test if the current character is a digit &lt;digit> ::= '0' | '1' | '2' |
      * '3' | '4' | '5' | '6' | '7' | '8' | '9'
      *

Modified: directory/shared/trunk/util/src/main/java/org/apache/directory/shared/util/Strings.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/util/src/main/java/org/apache/directory/shared/util/Strings.java?rev=1237815&r1=1237814&r2=1237815&view=diff
==============================================================================
--- directory/shared/trunk/util/src/main/java/org/apache/directory/shared/util/Strings.java
(original)
+++ directory/shared/trunk/util/src/main/java/org/apache/directory/shared/util/Strings.java
Mon Jan 30 17:31:21 2012
@@ -1462,11 +1462,11 @@ public final class Strings
 
 
     /**
-     * Get the character at a given position in a string, checking fo limits
+     * Get the character at a given position in a string, checking for limits
      *
      * @param string The string which contains the data
      * @param index Current position in the string
-     * @return The character ar the given position, or '\0' if something went wrong
+     * @return The character at the given position, or '\0' if something went wrong
      */
     public static char charAt( String string, int index )
     {
@@ -1489,6 +1489,33 @@ public final class Strings
 
 
     /**
+     * Get the byte at a given position in a byte array, checking for limits
+     *
+     * @param bytes The byte[] which contains the data
+     * @param index Current position in the byte[]
+     * @return The byte at the given position, or '\0' if something went wrong
+     */
+    public static byte byteAt( byte[] bytes, int index )
+    {
+        if ( bytes == null )
+        {
+            return '\0';
+        }
+
+        int length = bytes.length;
+
+        if ( ( length == 0 ) || ( index < 0 ) || ( index >= length ) )
+        {
+            return '\0';
+        }
+        else
+        {
+            return bytes[index];
+        }
+    }
+
+
+    /**
      * Thansform an array of ASCII bytes to a string. the byte array should contains
      * only values in [0, 127].
      *

Modified: directory/shared/trunk/util/src/main/java/org/apache/directory/shared/util/Unicode.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/util/src/main/java/org/apache/directory/shared/util/Unicode.java?rev=1237815&r1=1237814&r2=1237815&view=diff
==============================================================================
--- directory/shared/trunk/util/src/main/java/org/apache/directory/shared/util/Unicode.java
(original)
+++ directory/shared/trunk/util/src/main/java/org/apache/directory/shared/util/Unicode.java
Mon Jan 30 17:31:21 2012
@@ -6,16 +6,16 @@
  *  to you under the Apache License, Version 2.0 (the
  *  "License"); you may not use this file except in compliance
  *  with the License.  You may obtain a copy of the License at
- *  
+ * 
  *    http://www.apache.org/licenses/LICENSE-2.0
- *  
+ * 
  *  Unless required by applicable law or agreed to in writing,
  *  software distributed under the License is distributed on an
  *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  *  KIND, either express or implied.  See the License for the
  *  specific language governing permissions and limitations
- *  under the License. 
- *  
+ *  under the License.
+ * 
  */
 package org.apache.directory.shared.util;
 
@@ -416,6 +416,19 @@ public final class Unicode
 
 
     /**
+     * Check if the current byte is in the unicodeSubset : all chars but
+     * '\0', '(', ')', '*' and '\'
+     *
+     * @param b The byte to check
+     * @return True if the current byte is in the unicode subset
+     */
+    public static boolean isUnicodeSubset( byte b )
+    {
+        return ( ( b < 0 ) || ( b > 127 ) || UnicodeConstants.UNICODE_SUBSET[b] );
+    }
+
+
+    /**
      *
      * Writes four bytes of length information to the output stream, followed by the modified
UTF-8 representation
      * of every character in the string str. If str is null, the string value 'null' is written
with a length of 0



Mime
View raw message