directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kayyag...@apache.org
Subject svn commit: r1379424 - in /directory/shared/trunk/dsml/parser/src: main/java/org/apache/directory/shared/dsmlv2/ main/java/org/apache/directory/shared/dsmlv2/request/ test/java/org/apache/directory/shared/dsmlv2/searchRequest/ test/resources/org/apache...
Date Fri, 31 Aug 2012 12:01:34 GMT
Author: kayyagari
Date: Fri Aug 31 12:01:33 2012
New Revision: 1379424

URL: http://svn.apache.org/viewvc?rev=1379424&view=rev
Log:
fixes for DIRSHARED-137 and DIRSHARED-138

Added:
    directory/shared/trunk/dsml/parser/src/test/resources/org/apache/directory/shared/dsmlv2/searchRequest/filters/request_with_nested_connector_nodes.xml
Modified:
    directory/shared/trunk/dsml/parser/src/main/java/org/apache/directory/shared/dsmlv2/ParserUtils.java
    directory/shared/trunk/dsml/parser/src/main/java/org/apache/directory/shared/dsmlv2/request/Dsmlv2Grammar.java
    directory/shared/trunk/dsml/parser/src/main/java/org/apache/directory/shared/dsmlv2/request/SearchRequestDsml.java
    directory/shared/trunk/dsml/parser/src/test/java/org/apache/directory/shared/dsmlv2/searchRequest/SearchRequestTest.java

Modified: directory/shared/trunk/dsml/parser/src/main/java/org/apache/directory/shared/dsmlv2/ParserUtils.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/dsml/parser/src/main/java/org/apache/directory/shared/dsmlv2/ParserUtils.java?rev=1379424&r1=1379423&r2=1379424&view=diff
==============================================================================
--- directory/shared/trunk/dsml/parser/src/main/java/org/apache/directory/shared/dsmlv2/ParserUtils.java
(original)
+++ directory/shared/trunk/dsml/parser/src/main/java/org/apache/directory/shared/dsmlv2/ParserUtils.java
Fri Aug 31 12:01:33 2012
@@ -36,6 +36,8 @@ import org.apache.directory.shared.dsmlv
 import org.apache.directory.shared.i18n.I18n;
 import org.apache.directory.shared.ldap.codec.api.CodecControl;
 import org.apache.directory.shared.ldap.codec.api.LdapApiService;
+import org.apache.directory.shared.ldap.model.entry.BinaryValue;
+import org.apache.directory.shared.ldap.model.entry.StringValue;
 import org.apache.directory.shared.ldap.model.ldif.LdifUtils;
 import org.apache.directory.shared.ldap.model.message.Control;
 import org.apache.directory.shared.util.Base64;
@@ -139,7 +141,15 @@ public final class ParserUtils
      */
     public static boolean needsBase64Encoding( Object value )
     {
-        if ( value instanceof byte[] )
+        if( value instanceof StringValue )
+        {
+            return false;
+        }
+        else if( value instanceof BinaryValue )
+        {
+            return false;
+        } 
+        else if ( value instanceof byte[] )
         {
             return true;
         }

Modified: directory/shared/trunk/dsml/parser/src/main/java/org/apache/directory/shared/dsmlv2/request/Dsmlv2Grammar.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/dsml/parser/src/main/java/org/apache/directory/shared/dsmlv2/request/Dsmlv2Grammar.java?rev=1379424&r1=1379423&r2=1379424&view=diff
==============================================================================
--- directory/shared/trunk/dsml/parser/src/main/java/org/apache/directory/shared/dsmlv2/request/Dsmlv2Grammar.java
(original)
+++ directory/shared/trunk/dsml/parser/src/main/java/org/apache/directory/shared/dsmlv2/request/Dsmlv2Grammar.java
Fri Aug 31 12:01:33 2012
@@ -2452,9 +2452,7 @@ public final class Dsmlv2Grammar extends
             SearchRequestDsml searchRequestDecorator = ( SearchRequestDsml )
                 container.getBatchRequest().getCurrentRequest();
 
-            Filter filter = searchRequestDecorator.getCurrentFilter();
-
-            searchRequestDecorator.setCurrentFilter( filter );
+            searchRequestDecorator.endCurrentConnectorFilter();
         }
     };
 

Modified: directory/shared/trunk/dsml/parser/src/main/java/org/apache/directory/shared/dsmlv2/request/SearchRequestDsml.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/dsml/parser/src/main/java/org/apache/directory/shared/dsmlv2/request/SearchRequestDsml.java?rev=1379424&r1=1379423&r2=1379424&view=diff
==============================================================================
--- directory/shared/trunk/dsml/parser/src/main/java/org/apache/directory/shared/dsmlv2/request/SearchRequestDsml.java
(original)
+++ directory/shared/trunk/dsml/parser/src/main/java/org/apache/directory/shared/dsmlv2/request/SearchRequestDsml.java
Fri Aug 31 12:01:33 2012
@@ -42,6 +42,7 @@ import org.apache.directory.shared.ldap.
 import org.apache.directory.shared.ldap.model.filter.NotNode;
 import org.apache.directory.shared.ldap.model.filter.OrNode;
 import org.apache.directory.shared.ldap.model.filter.PresenceNode;
+import org.apache.directory.shared.ldap.model.filter.SimpleNode;
 import org.apache.directory.shared.ldap.model.filter.SubstringNode;
 import org.apache.directory.shared.ldap.model.message.AliasDerefMode;
 import org.apache.directory.shared.ldap.model.message.Control;
@@ -96,12 +97,6 @@ public class SearchRequestDsml
     }
 
 
-    public Filter getCurrentFilter()
-    {
-        return currentFilter;
-    }
-
-
     /**
      * Gets the search filter associated with this search request.
      *
@@ -147,13 +142,11 @@ public class SearchRequestDsml
 
 
     /**
-     * Set the current filter
-     *
-     * @param filter The filter to set.
+     * set the currentFilter to its parent
      */
-    public void setCurrentFilter( Filter filter )
+    public void endCurrentConnectorFilter( )
     {
-        currentFilter = filter;
+        currentFilter = currentFilter.getParent();
     }
 
 
@@ -514,73 +507,65 @@ public class SearchRequestDsml
         }
 
         // APPROXMATCH, EQUALITYMATCH, GREATEROREQUALS & LESSOREQUAL FILTERS
-        else if ( filter instanceof AttributeValueAssertionFilter )
+        else if ( filter instanceof SimpleNode )
         {
-            AttributeValueAssertionFilter avaFilter = ( AttributeValueAssertionFilter ) filter;
-
             Element newElement = null;
-            int filterType = avaFilter.getFilterType();
-            if ( filterType == LdapConstants.APPROX_MATCH_FILTER )
+            if ( filter instanceof ApproximateNode )
             {
                 newElement = element.addElement( "approxMatch" );
             }
-            else if ( filterType == LdapConstants.EQUALITY_MATCH_FILTER )
+            else if ( filter instanceof EqualityNode )
             {
                 newElement = element.addElement( "equalityMatch" );
             }
-            else if ( filterType == LdapConstants.GREATER_OR_EQUAL_FILTER )
+            else if ( filter instanceof GreaterEqNode )
             {
                 newElement = element.addElement( "greaterOrEqual" );
             }
-            else if ( filterType == LdapConstants.LESS_OR_EQUAL_FILTER )
+            else if ( filter instanceof LessEqNode )
             {
                 newElement = element.addElement( "lessOrEqual" );
             }
 
-            AttributeValueAssertion assertion = avaFilter.getAssertion();
-            if ( assertion != null )
+            String attributeName = ( ( SimpleNode ) filter ).getAttribute();
+            newElement.addAttribute( "name", attributeName );
+            
+            Value<?> value = ( ( SimpleNode ) filter ).getValue();
+            if ( value != null )
             {
-                newElement.addAttribute( "name", assertion.getAttributeDesc() );
-
-                Value<?> value = assertion.getAssertionValue();
-                if ( value != null )
+                if ( ParserUtils.needsBase64Encoding( value ) )
                 {
-                    if ( ParserUtils.needsBase64Encoding( value ) )
-                    {
-                        Namespace xsdNamespace = new Namespace( "xsd", ParserUtils.XML_SCHEMA_URI
);
-                        Namespace xsiNamespace = new Namespace( "xsi", ParserUtils.XML_SCHEMA_INSTANCE_URI
);
-                        element.getDocument().getRootElement().add( xsdNamespace );
-                        element.getDocument().getRootElement().add( xsiNamespace );
-
-                        Element valueElement = newElement.addElement( "value" ).addText(
-                            ParserUtils.base64Encode( value ) );
-                        valueElement
-                            .addAttribute( new QName( "type", xsiNamespace ), "xsd:" + ParserUtils.BASE64BINARY
);
-                    }
-                    else
-                    {
-                        newElement.addElement( "value" ).setText( value.getString() );
-                    }
+                    Namespace xsdNamespace = new Namespace( "xsd", ParserUtils.XML_SCHEMA_URI
);
+                    Namespace xsiNamespace = new Namespace( "xsi", ParserUtils.XML_SCHEMA_INSTANCE_URI
);
+                    element.getDocument().getRootElement().add( xsdNamespace );
+                    element.getDocument().getRootElement().add( xsiNamespace );
+                    
+                    Element valueElement = newElement.addElement( "value" ).addText(
+                        ParserUtils.base64Encode( value ) );
+                    valueElement
+                    .addAttribute( new QName( "type", xsiNamespace ), "xsd:" + ParserUtils.BASE64BINARY
);
+                }
+                else
+                {
+                    newElement.addElement( "value" ).setText( value.getString() );
                 }
             }
         }
 
         // PRESENT FILTER
-        else if ( filter instanceof PresentFilter )
+        else if ( filter instanceof PresenceNode )
         {
             Element newElement = element.addElement( "present" );
 
-            newElement.addAttribute( "name", ( ( PresentFilter ) filter ).getAttributeDescription()
);
+            newElement.addAttribute( "name", ( ( PresenceNode ) filter ).getAttribute() );
         }
 
         // EXTENSIBLEMATCH
-        else if ( filter instanceof ExtensibleMatchFilter )
+        else if ( filter instanceof ExtensibleNode )
         {
             Element newElement = element.addElement( "extensibleMatch" );
 
-            ExtensibleMatchFilter extensibleMatchFilter = ( ExtensibleMatchFilter ) filter;
-
-            Value<?> value = extensibleMatchFilter.getMatchValue();
+            Value<?> value = ( ( ExtensibleNode ) filter ).getValue();
             if ( value != null )
             {
                 if ( ParserUtils.needsBase64Encoding( value ) )
@@ -590,7 +575,7 @@ public class SearchRequestDsml
                     element.getDocument().getRootElement().add( xsdNamespace );
                     element.getDocument().getRootElement().add( xsiNamespace );
 
-                    Element valueElement = newElement.addElement( "value" ).addText( ParserUtils.base64Encode(
value ) );
+                    Element valueElement = newElement.addElement( "value" ).addText( ParserUtils.base64Encode(
value.getValue() ) );
                     valueElement.addAttribute( new QName( "type", xsiNamespace ), "xsd:"
+ ParserUtils.BASE64BINARY );
                 }
                 else
@@ -599,12 +584,12 @@ public class SearchRequestDsml
                 }
             }
 
-            if ( extensibleMatchFilter.isDnAttributes() )
+            if ( ( ( ExtensibleNode ) filter ).hasDnAttributes() )
             {
                 newElement.addAttribute( "dnAttributes", "true" );
             }
 
-            String matchingRule = extensibleMatchFilter.getMatchingRule();
+            String matchingRule = ( ( ExtensibleNode ) filter ).getMatchingRuleId();
             if ( ( matchingRule != null ) && ( "".equals( matchingRule ) ) )
             {
                 newElement.addAttribute( "matchingRule", matchingRule );

Modified: directory/shared/trunk/dsml/parser/src/test/java/org/apache/directory/shared/dsmlv2/searchRequest/SearchRequestTest.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/dsml/parser/src/test/java/org/apache/directory/shared/dsmlv2/searchRequest/SearchRequestTest.java?rev=1379424&r1=1379423&r2=1379424&view=diff
==============================================================================
--- directory/shared/trunk/dsml/parser/src/test/java/org/apache/directory/shared/dsmlv2/searchRequest/SearchRequestTest.java
(original)
+++ directory/shared/trunk/dsml/parser/src/test/java/org/apache/directory/shared/dsmlv2/searchRequest/SearchRequestTest.java
Fri Aug 31 12:01:33 2012
@@ -36,6 +36,7 @@ import com.mycila.junit.concurrent.Concu
 import org.apache.directory.shared.dsmlv2.AbstractTest;
 import org.apache.directory.shared.dsmlv2.DsmlControl;
 import org.apache.directory.shared.dsmlv2.Dsmlv2Parser;
+import org.apache.directory.shared.dsmlv2.request.SearchRequestDsml;
 import org.apache.directory.shared.ldap.model.exception.LdapException;
 import org.apache.directory.shared.ldap.model.filter.AndNode;
 import org.apache.directory.shared.ldap.model.filter.ApproximateNode;
@@ -53,6 +54,7 @@ import org.apache.directory.shared.ldap.
 import org.apache.directory.shared.ldap.model.message.SearchRequest;
 import org.apache.directory.shared.ldap.model.message.SearchScope;
 import org.apache.directory.shared.util.Strings;
+import org.dom4j.tree.DefaultElement;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 
@@ -2411,4 +2413,37 @@ public class SearchRequestTest extends A
     {
         testParsingFail( SearchRequestTest.class, "request_with_needed_requestID.xml" );
     }
+
+    
+    /**
+     * Test parsing of a request with a nested nodes DIRSHARED-137
+     */
+    @Test
+    public void testRequestWithNestedNodes()
+    {
+        Dsmlv2Parser parser = null;
+        try
+        {
+            parser = newParser();
+
+            parser.setInput( SearchRequestTest.class.getResource( "filters/request_with_nested_connector_nodes.xml"
)
+                .openStream(), "UTF-8" );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        SearchRequestDsml searchRequest = ( SearchRequestDsml ) parser.getBatchRequest().getCurrentRequest();
+
+        ExprNode filter = searchRequest.getFilter();
+
+        assertTrue( filter instanceof AndNode );
+
+        assertEquals( "(&(|(sn=*foo*)(cn=*foo*))(|(ou=*josopuram*)(o=*k*)))", filter.toString()
);
+        
+        System.out.println( searchRequest.toDsml( new DefaultElement( "root" ) ).asXML());
+    }
 }

Added: directory/shared/trunk/dsml/parser/src/test/resources/org/apache/directory/shared/dsmlv2/searchRequest/filters/request_with_nested_connector_nodes.xml
URL: http://svn.apache.org/viewvc/directory/shared/trunk/dsml/parser/src/test/resources/org/apache/directory/shared/dsmlv2/searchRequest/filters/request_with_nested_connector_nodes.xml?rev=1379424&view=auto
==============================================================================
--- directory/shared/trunk/dsml/parser/src/test/resources/org/apache/directory/shared/dsmlv2/searchRequest/filters/request_with_nested_connector_nodes.xml
(added)
+++ directory/shared/trunk/dsml/parser/src/test/resources/org/apache/directory/shared/dsmlv2/searchRequest/filters/request_with_nested_connector_nodes.xml
Fri Aug 31 12:01:33 2012
@@ -0,0 +1,36 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!-- Licensed to the Apache Software Foundation (ASF) under one or more contributor 
+	license agreements. See the NOTICE file distributed with this work for additional 
+	information regarding copyright ownership. The ASF licenses this file 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. -->
+<batchRequest xmlns="urn:oasis:names:tc:DSML:2.0:core">
+	<searchRequest dn="dc=example,dc=com"
+		scope="baseObject" derefAliases="neverDerefAliases">
+		<filter>
+			<and>
+				<or>
+					<substrings name="sn">
+						<any>foo</any>
+					</substrings>
+					<substrings name="cn">
+						<any>foo</any>
+					</substrings>
+				</or>
+				<or>
+					<substrings name="ou">
+						<any>josopuram</any>
+					</substrings>
+					<substrings name="o">
+						<any>k</any>
+					</substrings>
+				</or>
+			</and>
+		</filter>
+	</searchRequest>
+</batchRequest>
\ No newline at end of file



Mime
View raw message