You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by er...@apache.org on 2007/01/07 14:02:27 UTC

svn commit: r493715 - in /directory/trunks/shared/ldap/src: main/antlr/subtree-specification.g test/java/org/apache/directory/shared/ldap/subtree/SubtreeSpecificationParserTest.java

Author: ersiner
Date: Sun Jan  7 05:02:26 2007
New Revision: 493715

URL: http://svn.apache.org/viewvc?view=rev&rev=493715
Log:
Adding Filter support (as an addition to Refinements) in subtreeSpecification grammar.
The specificationFilter element now can be followed by either a Refinement or a Filter.

Thanks Stefan Seelman for great Antlr trick!

Modified:
    directory/trunks/shared/ldap/src/main/antlr/subtree-specification.g
    directory/trunks/shared/ldap/src/test/java/org/apache/directory/shared/ldap/subtree/SubtreeSpecificationParserTest.java

Modified: directory/trunks/shared/ldap/src/main/antlr/subtree-specification.g
URL: http://svn.apache.org/viewvc/directory/trunks/shared/ldap/src/main/antlr/subtree-specification.g?view=diff&rev=493715&r1=493714&r2=493715
==============================================================================
--- directory/trunks/shared/ldap/src/main/antlr/subtree-specification.g (original)
+++ directory/trunks/shared/ldap/src/main/antlr/subtree-specification.g Sun Jan  7 05:02:26 2007
@@ -33,7 +33,9 @@
 import org.apache.directory.shared.ldap.filter.LeafNode;
 import org.apache.directory.shared.ldap.filter.SimpleNode;
 import org.apache.directory.shared.ldap.filter.BranchNode;
+import org.apache.directory.shared.ldap.filter.AbstractExprNode;
 import org.apache.directory.shared.ldap.filter.AssertionEnum;
+import org.apache.directory.shared.ldap.filter.FilterParserImpl;
 import org.apache.directory.shared.ldap.subtree.SubtreeSpecification;
 import org.apache.directory.shared.ldap.subtree.SubtreeSpecificationModifier;
 import org.apache.directory.shared.ldap.schema.NormalizerMappingResolver;
@@ -77,6 +79,8 @@
 {
     private static final Logger log = LoggerFactory.getLogger( AntlrSubtreeSpecificationParser.class );
     
+    private final FilterParserImpl filterParser = new FilterParserImpl();
+    
     private NormalizerMappingResolver resolver;
     
     private Set chopBeforeExclusions = new HashSet();
@@ -292,15 +296,32 @@
 ss_specificationFilter
 {
     log.debug( "entered ss_specificationFilter()" );
-    ExprNode theRefinement = null;
+    ExprNode filterExpr = null;
 }
     :
-    ID_specificationFilter ( SP )+ theRefinement=refinement
+    ID_specificationFilter 
+    ( SP )+ 
+    (
+        ( filterExpr=refinement )
+        |
+        ( filterExpr=filter )
+    )
+    { ssModifier.setRefinement( filterExpr ); }
+    ;
+    
+    
+filter returns [ ExprNode filterExpr = null; ]
+{
+	log.debug( "entered filter()" );
+}
+	:
+	( filterToken:FILTER { filterExpr=filterParser.parse( filterToken.getText() ); } )
+	;
+	exception
+    catch [Exception e]
     {
-    	// TODO need to normalize refinement filter
-        ssModifier.setRefinement( theRefinement );
+        throw new RecognitionException( "filterParser failed. " + e.getMessage() );
     }
-    ;
     
 distinguishedName returns [ LdapDN name ] 
 {
@@ -457,7 +478,7 @@
 
 options
 {
-    k = 2;
+    k = 5;
 
     charVocabulary = '\u0001'..'\u0127';
 }
@@ -545,3 +566,7 @@
     '\u3400'..'\u3d2d' |
     '\u4e00'..'\u9fff' |
     '\uf900'..'\ufaff' ;
+
+FILTER : '(' ( ( '&' (FILTER)+ ) | ( '|' (FILTER)+ ) | ( '!' FILTER ) | FILTER_VALUE ) ')' ;
+
+protected FILTER_VALUE : (options{greedy=true;}: ~( ')' | '(' | '&' | '|' | '!' ) ( ~(')') )* ) ;

Modified: directory/trunks/shared/ldap/src/test/java/org/apache/directory/shared/ldap/subtree/SubtreeSpecificationParserTest.java
URL: http://svn.apache.org/viewvc/directory/trunks/shared/ldap/src/test/java/org/apache/directory/shared/ldap/subtree/SubtreeSpecificationParserTest.java?view=diff&rev=493715&r1=493714&r2=493715
==============================================================================
--- directory/trunks/shared/ldap/src/test/java/org/apache/directory/shared/ldap/subtree/SubtreeSpecificationParserTest.java (original)
+++ directory/trunks/shared/ldap/src/test/java/org/apache/directory/shared/ldap/subtree/SubtreeSpecificationParserTest.java Sun Jan  7 05:02:26 2007
@@ -29,6 +29,8 @@
 
 import org.apache.directory.shared.ldap.filter.AssertionEnum;
 import org.apache.directory.shared.ldap.filter.BranchNode;
+import org.apache.directory.shared.ldap.filter.ExprNode;
+import org.apache.directory.shared.ldap.filter.FilterParserImpl;
 import org.apache.directory.shared.ldap.filter.SimpleNode;
 import org.apache.directory.shared.ldap.name.LdapDN;
 import org.apache.directory.shared.ldap.subtree.SubtreeSpecification;
@@ -90,6 +92,10 @@
     /** An invalid specification with completely unrelated content */
     private static final String INVALID_SILLY_THING = "How much wood would a wood chuck chuck if a wood chuck would chuck wood?";
     
+    /** A valid specification with filter expression */
+    private static final String SPEC_WITH_FILTER = "{ base \"ou=system\", specificationFilter (&(cn=test)(sn=test)) }";
+
+    
     /** the ss parser wrapper */
     SubtreeSpecificationParser parser;
 
@@ -334,6 +340,19 @@
         {
             assertNotNull( e );
         }
+    }
+    
+    
+    /**
+     * Tests the parser with a valid specification with refinement set.
+     */
+    public void testSpecWithFilter() throws Exception
+    {
+        SubtreeSpecification ss = parser.parse( SPEC_WITH_FILTER );
+
+        ExprNode filter = new FilterParserImpl().parse( "(&(cn=test)(sn=test))" );
+
+        assertEquals( filter, ss.getRefinement() );
     }