directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r1745848 - in /directory/shared/branches/shared-value/ldap/model/src/main/java/org/apache/directory/api/ldap/model/filter: FilterParser.java SimpleNode.java SubstringNode.java
Date Sat, 28 May 2016 08:06:23 GMT
Author: elecharny
Date: Sat May 28 08:06:23 2016
New Revision: 1745848

URL: http://svn.apache.org/viewvc?rev=1745848&view=rev
Log:
o Fixed the Substring regexp generation, using the normalized form for the Inital, Any and
Final assertionValues
o Fixed the value used in the SimpleNode getEscapedValue()
o Numerous fixes in the FilterParser

Modified:
    directory/shared/branches/shared-value/ldap/model/src/main/java/org/apache/directory/api/ldap/model/filter/FilterParser.java
    directory/shared/branches/shared-value/ldap/model/src/main/java/org/apache/directory/api/ldap/model/filter/SimpleNode.java
    directory/shared/branches/shared-value/ldap/model/src/main/java/org/apache/directory/api/ldap/model/filter/SubstringNode.java

Modified: directory/shared/branches/shared-value/ldap/model/src/main/java/org/apache/directory/api/ldap/model/filter/FilterParser.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-value/ldap/model/src/main/java/org/apache/directory/api/ldap/model/filter/FilterParser.java?rev=1745848&r1=1745847&r2=1745848&view=diff
==============================================================================
--- directory/shared/branches/shared-value/ldap/model/src/main/java/org/apache/directory/api/ldap/model/filter/FilterParser.java
(original)
+++ directory/shared/branches/shared-value/ldap/model/src/main/java/org/apache/directory/api/ldap/model/filter/FilterParser.java
Sat May 28 08:06:23 2016
@@ -360,7 +360,7 @@ public final class FilterParser
             b = Strings.byteAt( filterBytes, pos.start );
         }
         while ( b != '\0' );
-
+        
         if ( current != 0 )
         {
             if ( schemaManager != null )
@@ -378,10 +378,10 @@ public final class FilterParser
                 }
                 else
                 {
-                    byte[] bytes = new byte[value.length];
+                    byte[] bytes = new byte[current];
                     System.arraycopy( value, 0, bytes, 0, current );
                     
-                    return new Value( attributeType, Strings.utf8ToString( bytes ) );
+                    return new Value( attributeType, bytes );
                 }
             }
             else
@@ -516,87 +516,89 @@ public final class FilterParser
     private static ExprNode parseSubstring( SchemaManager schemaManager, String attribute,
Value initial,
         byte[] filterBytes, Position pos ) throws ParseException, LdapException
     {
-        if ( Strings.isCharASCII( filterBytes, pos.start, '*' ) )
+        SubstringNode node;
+
+        if ( schemaManager != null )
         {
-            // We have found a '*' : this is a substring
-            SubstringNode node = null;
+            AttributeType attributeType = schemaManager.lookupAttributeTypeRegistry( attribute
);
 
-            if ( schemaManager != null )
+            if ( attributeType != null )
             {
-                AttributeType attributeType = schemaManager.lookupAttributeTypeRegistry(
attribute );
-
-                if ( attributeType != null )
-                {
-                    node = new SubstringNode( schemaManager.lookupAttributeTypeRegistry(
attribute ) );
-                }
-                else
-                {
-                    return null;
-                }
+                node = new SubstringNode( schemaManager.lookupAttributeTypeRegistry( attribute
) );
             }
             else
             {
-                node = new SubstringNode( attribute );
+                return null;
             }
+        }
+        else
+        {
+            node = new SubstringNode( attribute );
+        }
 
-            if ( ( initial != null ) && !initial.isNull() )
-            {
-                // We have a substring starting with a value : val*...
-                // Set the initial value. It must be a String
-                String initialStr = initial.getValue();
-                node.setInitial( initialStr );
-            }
+        if ( ( initial != null ) && !initial.isNull() )
+        {
+            // We have a substring starting with a value : val*...
+            // Set the initial value. It must be a String
+            String initialStr = initial.getValue();
+            node.setInitial( initialStr );
+        }
+
+        if ( Strings.isCharASCII( filterBytes, pos.start, ')' ) )
+        {
+            // No any or final, we are done
+            return node;
+        }
 
-            pos.start++;
+        //
+        while ( true )
+        {
+            Value assertionValue = parseAssertionValue( schemaManager, attribute, filterBytes,
pos );
 
+            // Is there anything else but a ')' after the value ?
             if ( Strings.isCharASCII( filterBytes, pos.start, ')' ) )
             {
-                // No any or final, we are done
+                // Nope : as we have had [initial] '*' (any '*' ) *,
+                // this is the final
+                if ( !assertionValue.isNull() )
+                {
+                    String finalStr = assertionValue.getValue();
+                    node.setFinal( finalStr );
+                }
+
                 return node;
             }
-
-            //
-            while ( true )
+            else if ( Strings.isCharASCII( filterBytes, pos.start, '*' ) )
             {
-                Value assertionValue = parseAssertionValue( schemaManager, attribute, filterBytes,
pos );
-
-                // Is there anything else but a ')' after the value ?
-                if ( Strings.isCharASCII( filterBytes, pos.start, ')' ) )
+                // We have a '*' : it's an any
+                // If the value is empty, that means we have more than
+                // one consecutive '*' : do nothing in this case.
+                if ( !assertionValue.isNull() )
                 {
-                    // Nope : as we have had [initial] '*' (any '*' ) *,
-                    // this is the final
-                    if ( !assertionValue.isNull() )
-                    {
-                        String finalStr = assertionValue.getValue();
-                        node.setFinal( finalStr );
-                    }
-
-                    return node;
+                    String anyStr = assertionValue.getValue();
+                    node.addAny( anyStr );
                 }
-                else if ( Strings.isCharASCII( filterBytes, pos.start, '*' ) )
-                {
-                    // We have a '*' : it's an any
-                    // If the value is empty, that means we have more than
-                    // one consecutive '*' : do nothing in this case.
-                    if ( !assertionValue.isNull() )
-                    {
-                        String anyStr = assertionValue.getValue();
-                        node.addAny( anyStr );
-                    }
 
+                pos.start++;
+
+                // Skip any following '*'
+                while ( Strings.isCharASCII( filterBytes, pos.start, '*' ) )
+                {
                     pos.start++;
                 }
-                else
+
+                // that may have been the closing '*'
+                if ( Strings.isCharASCII( filterBytes, pos.start, ')' ) )
                 {
-                    // This is an error
-                    throw new ParseException( I18n.err( I18n.ERR_04150 ), pos.start );
+                    return node;
                 }
+
+            }
+            else
+            {
+                // This is an error
+                throw new ParseException( I18n.err( I18n.ERR_04150 ), pos.start );
             }
-        }
-        else
-        {
-            // This is an error
-            throw new ParseException( I18n.err( I18n.ERR_04150 ), pos.start );
         }
     }
 
@@ -628,79 +630,52 @@ public final class FilterParser
     private static ExprNode parsePresenceEqOrSubstring( SchemaManager schemaManager, String
attribute, byte[] filterBytes,
         Position pos ) throws ParseException, LdapException
     {
-        if ( Strings.isCharASCII( filterBytes, pos.start, '*' ) )
-        {
-            // To be a present node, the next char should be a ')'
-            pos.start++;
+        byte b = Strings.byteAt( filterBytes, pos.start );
 
-            if ( Strings.isCharASCII( filterBytes, pos.start, ')' ) )
-            {
-                // This is a present node
-                if ( schemaManager != null )
+        switch ( b )
+        {
+            case '*' :
+                // To be a present node, the next char should be a ')'
+                pos.start++;
+    
+                if ( Strings.isCharASCII( filterBytes, pos.start, ')' ) )
                 {
-                    AttributeType attributeType = schemaManager.getAttributeType( attribute
);
-
-                    if ( attributeType != null )
+                    // This is a present node
+                    if ( schemaManager != null )
                     {
-                        return new PresenceNode( attributeType );
+                        AttributeType attributeType = schemaManager.getAttributeType( attribute
);
+    
+                        if ( attributeType != null )
+                        {
+                            return new PresenceNode( attributeType );
+                        }
+                        else
+                        {
+                            return null;
+                        }
                     }
                     else
                     {
-                        return null;
+                        return new PresenceNode( attribute );
                     }
                 }
                 else
                 {
-                    return new PresenceNode( attribute );
+                    // Definitively a substring with no initial or an error
+                    return parseSubstring( schemaManager, attribute, null, filterBytes, pos
);
                 }
-            }
-            else
-            {
-                // Definitively a substring with no initial or an error
-                // Push back the '*' on the string
-                pos.start--;
-                return parseSubstring( schemaManager, attribute, null, filterBytes, pos );
-            }
-        }
-        else if ( Strings.isCharASCII( filterBytes, pos.start, ')' ) )
-        {
-            // An empty equality Node
-            if ( schemaManager != null )
-            {
-                AttributeType attributeType = schemaManager.getAttributeType( attribute );
-
-                if ( attributeType != null )
-                {
-                    return new EqualityNode( attributeType, new Value( ( byte[] ) null )
);
-                }
-
-                else
-                {
-                    return null;
-                }
-            }
-            else
-            {
-                return new EqualityNode( attribute, ( byte[] ) null );
-            }
-        }
-        else
-        {
-            // A substring or an equality node
-            Value value = parseAssertionValue( schemaManager, attribute, filterBytes, pos
);
-
-            // Is there anything else but a ')' after the value ?
-            if ( Strings.isCharASCII( filterBytes, pos.start, ')' ) )
-            {
-                // This is an equality node
+                
+            case ')' :
+                // An empty equality Node
                 if ( schemaManager != null )
                 {
                     AttributeType attributeType = schemaManager.getAttributeType( attribute
);
-
+    
                     if ( attributeType != null )
                     {
-                        return new EqualityNode( attributeType, value );
+                        return new EqualityNode( attributeType, new Value( ( byte[] ) null
) );
                     }
+    
                     else
                     {
                         return null;
@@ -708,11 +683,48 @@ public final class FilterParser
                 }
                 else
                 {
-                    return new EqualityNode( attribute, value.getValue() );
+                    return new EqualityNode( attribute, ( byte[] ) null );
                 }
-            }
+                
+            default :
+                // A substring or an equality node
+                Value value = parseAssertionValue( schemaManager, attribute, filterBytes,
pos );
+    
+                // Is there anything else but a ')' after the value ?
+                b = Strings.byteAt( filterBytes, pos.start );
 
-            return parseSubstring( schemaManager, attribute, value, filterBytes, pos );
+                switch ( b )
+                {
+                    case ')' :
+                        // This is an equality node
+                        if ( schemaManager != null )
+                        {
+                            AttributeType attributeType = schemaManager.getAttributeType(
attribute );
+        
+                            if ( attributeType != null )
+                            {
+                                return new EqualityNode( attributeType, value );
+                            }
+                            else
+                            {
+                                return null;
+                            }
+                        }
+                        else
+                        {
+                            return new EqualityNode( attribute, value.getValue() );
+                        }
+                        
+                    case '*' :
+                        pos.start++;
+                        
+                        return parseSubstring( schemaManager, attribute, value, filterBytes,
pos );
+                        
+                        
+                    default :
+                        // This is an error
+                        throw new ParseException( I18n.err( I18n.ERR_04150 ), pos.start );
+                }
         }
     }
 
@@ -735,7 +747,7 @@ public final class FilterParser
     private static ExprNode parseItem( SchemaManager schemaManager, byte[] filterBytes, Position
pos, byte b,
         boolean relaxed ) throws ParseException, LdapException
     {
-        String attribute = null;
+        String attribute;
 
         if ( b == '\0' )
         {

Modified: directory/shared/branches/shared-value/ldap/model/src/main/java/org/apache/directory/api/ldap/model/filter/SimpleNode.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-value/ldap/model/src/main/java/org/apache/directory/api/ldap/model/filter/SimpleNode.java?rev=1745848&r1=1745847&r2=1745848&view=diff
==============================================================================
--- directory/shared/branches/shared-value/ldap/model/src/main/java/org/apache/directory/api/ldap/model/filter/SimpleNode.java
(original)
+++ directory/shared/branches/shared-value/ldap/model/src/main/java/org/apache/directory/api/ldap/model/filter/SimpleNode.java
Sat May 28 08:06:23 2016
@@ -194,7 +194,7 @@ public abstract class SimpleNode<T> exte
     {
         if ( value != null )
         {
-            return escapeFilterValue( value.getAttributeType(), bytes );
+            return escapeFilterValue( value.getAttributeType(), value.getBytes() );
         }
         else
         {

Modified: directory/shared/branches/shared-value/ldap/model/src/main/java/org/apache/directory/api/ldap/model/filter/SubstringNode.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-value/ldap/model/src/main/java/org/apache/directory/api/ldap/model/filter/SubstringNode.java?rev=1745848&r1=1745847&r2=1745848&view=diff
==============================================================================
--- directory/shared/branches/shared-value/ldap/model/src/main/java/org/apache/directory/api/ldap/model/filter/SubstringNode.java
(original)
+++ directory/shared/branches/shared-value/ldap/model/src/main/java/org/apache/directory/api/ldap/model/filter/SubstringNode.java
Sat May 28 08:06:23 2016
@@ -303,13 +303,13 @@ public class SubstringNode extends LeafN
      */
     public final Pattern getRegex( Normalizer normalizer ) throws LdapException
     {
-        if ( ( anyPattern != null ) && ( anyPattern.size() > 0 ) )
+        if ( ( anyPattern != null ) && ( !anyPattern.isEmpty() ) )
         {
             String[] any = new String[anyPattern.size()];
 
             for ( int i = 0; i < any.length; i++ )
             {
-                any[i] = ( String ) normalizer.normalize( anyPattern.get( i ), PrepareString.AssertionType.SUBSTRING_ANY
);
+                any[i] = normalizer.normalize( anyPattern.get( i ), PrepareString.AssertionType.SUBSTRING_ANY
);
 
                 if ( any[i].length() == 0 )
                 {
@@ -321,7 +321,7 @@ public class SubstringNode extends LeafN
 
             if ( initialPattern != null )
             {
-                initialStr = ( String ) normalizer.normalize( initialPattern, PrepareString.AssertionType.SUBSTRING_INITIAL
);
+                initialStr = normalizer.normalize( initialPattern, PrepareString.AssertionType.SUBSTRING_INITIAL
);
             }
 
             String finalStr = null;



Mime
View raw message