directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From seelm...@apache.org
Subject svn commit: r602698 - in /directory/studio/trunk: studio-ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/filtereditor/ studio-ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/search...
Date Sun, 09 Dec 2007 17:15:07 GMT
Author: seelmann
Date: Sun Dec  9 09:15:01 2007
New Revision: 602698

URL: http://svn.apache.org/viewvc?rev=602698&view=rev
Log:
Fix for DIRSTUDIO-210: Improved filter parser

Added:
    directory/studio/trunk/studio-ldapbrowser-core/src/test/java/org/apache/directory/studio/ldapbrowser/core/model/LdapFilterParserErrorTolerantTest.java
  (with props)
Modified:
    directory/studio/trunk/studio-ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/filtereditor/FilterAutoEditStrategy.java
    directory/studio/trunk/studio-ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/filtereditor/FilterDamagerRepairer.java
    directory/studio/trunk/studio-ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/search/FilterWidgetAutoEditStrategyAdapter.java
    directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/filter/LdapFilter.java
    directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/filter/LdapFilterItemComponent.java
    directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/filter/parser/LdapFilterParser.java
    directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/filter/parser/LdapFilterScanner.java
    directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/filter/parser/LdapFilterToken.java
    directory/studio/trunk/studio-ldapbrowser-core/src/test/java/org/apache/directory/studio/ldapbrowser/core/model/LdapFilterParserTest.java

Modified: directory/studio/trunk/studio-ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/filtereditor/FilterAutoEditStrategy.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/filtereditor/FilterAutoEditStrategy.java?rev=602698&r1=602697&r2=602698&view=diff
==============================================================================
--- directory/studio/trunk/studio-ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/filtereditor/FilterAutoEditStrategy.java
(original)
+++ directory/studio/trunk/studio-ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/filtereditor/FilterAutoEditStrategy.java
Sun Dec  9 09:15:01 2007
@@ -105,19 +105,35 @@
         if ( aep.length > 0 && ( aep.text == null || "".equals( aep.text ) ) )
         {
             // delete surrounding parenthesis after deleting the last character
-            if ( filter.toString().length() - aep.length == 2 && filter.getStartToken()
!= null
+            if ( filter.toString().length() - aep.length == 2 
+                && filter.getStartToken() != null
                 && filter.getStopToken() != null
                 && aep.offset >= filter.getStartToken().getOffset() + filter.getStartToken().getLength()
                 && aep.offset + aep.length <= filter.getStopToken().getOffset()
)
             {
-                aep.offset -= 1;
-                aep.length += 2;
+                if ( filter.toString().length() - aep.length == 2 )
+                {
+                    aep.offset -= 1;
+                    aep.length += 2;
+                    aep.caretOffset = aep.offset;
+                    aep.shiftsCaret = false;
+                }
+            }
+            
+            // delete closing parenthesis after deleting the opening parenthesis
+            if ( filter.toString().length() - aep.length == 1
+                && filter.getStartToken() != null
+                && filter.getStopToken() != null
+                && aep.offset == filter.getStartToken().getOffset() )
+            {
+                aep.length += 1;
                 aep.caretOffset = aep.offset;
                 aep.shiftsCaret = false;
             }
+            
         }
 
-        if ( aep.length == 0 && aep.text != null && !"".equals( aep.text
) )
+        if ( (aep.length == 0 || aep.length==currentFilter.length()) && aep.text
!= null && !"".equals( aep.text ) )
         {
             boolean isNewFilter = aep.text.equals( "(" );
             boolean isNewNestedFilter = aep.text.equals( "&" ) || aep.text.equals( "|"
) || aep.text.equals( "!" );
@@ -125,11 +141,12 @@
             boolean isSurroundNested = false;
             boolean isSurroundBeforeOtherFilter = false;
             boolean isSurroundAfterOtherFilter = false;
-            if ( aep.text.matches( "[a-zA-Z0-9-\\.&|!:]+" ) && filter != null
)
+            if( !Character.isWhitespace( aep.text.charAt( 0 ) ) && !aep.text.startsWith(
"(" ) && !aep.text.endsWith( ")" ) )
             {
-                isSurroundNew = filter.getStartToken() == null && aep.offset == 0
&& !aep.text.startsWith( "(" )
-                    && !aep.text.endsWith( ")" );
+                // isSurroundNew
+                isSurroundNew = aep.offset == 0;
 
+                // isSurroundNested
                 if ( filter.getStartToken() != null
                     && filter.getFilterComponent() != null
                     && ( filter.getFilterComponent() instanceof LdapAndFilterComponent
@@ -172,14 +189,18 @@
                     }
                 }
 
+                // isSurroundBeforeOtherFilter
                 isSurroundBeforeOtherFilter = filter.getStartToken() != null
                     && aep.offset == filter.getStartToken().getOffset();
 
+                // isSurroundAfterOtherFilter
                 isSurroundAfterOtherFilter = filter.getStopToken() != null
                     && aep.offset == filter.getStopToken().getOffset()
                     && ( filter.getFilterComponent() instanceof LdapAndFilterComponent
                         || filter.getFilterComponent() instanceof LdapOrFilterComponent ||
filter.getFilterComponent() instanceof LdapNotFilterComponent );
             }
+            
+            System.out.println("isSurroundNew="+isSurroundNew+", isSurroundNested="+isSurroundNested+",
isSurroundAfterOtherFilter="+isSurroundAfterOtherFilter+", isSurroundBeforeOtherFilter="+isSurroundBeforeOtherFilter);
 
             // add opening parenthesis '('
             if ( isSurroundNew || isSurroundNested || isSurroundAfterOtherFilter || isSurroundBeforeOtherFilter
)
@@ -211,13 +232,16 @@
                     }
                 }
             }
-
+            
             // translate tab to IDENT_STRING
             if ( aep.text.equals( "\t" ) )
             {
                 aep.text = INDENT_STRING;
             }
         }
+        
+        System.out.println( "aep='"+aep.text+"',"+aep.offset+","+aep.length+","+aep.caretOffset+","+aep.shiftsCaret+";
balanced="+balanced+"; filter='"+filter.toString()+"'" );
+
     }
 
     /**

Modified: directory/studio/trunk/studio-ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/filtereditor/FilterDamagerRepairer.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/filtereditor/FilterDamagerRepairer.java?rev=602698&r1=602697&r2=602698&view=diff
==============================================================================
--- directory/studio/trunk/studio-ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/filtereditor/FilterDamagerRepairer.java
(original)
+++ directory/studio/trunk/studio-ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/filtereditor/FilterDamagerRepairer.java
Sun Dec  9 09:15:01 2007
@@ -131,6 +131,7 @@
                 case LdapFilterToken.LESS:
                 case LdapFilterToken.APROX:
                 case LdapFilterToken.PRESENT:
+                case LdapFilterToken.SUBSTRING:
                 case LdapFilterToken.EXTENSIBLE_DNATTR_COLON:
                 case LdapFilterToken.EXTENSIBLE_MATCHINGRULEOID_COLON:
                 case LdapFilterToken.EXTENSIBLE_EQUALS_COLON:

Modified: directory/studio/trunk/studio-ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/search/FilterWidgetAutoEditStrategyAdapter.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/search/FilterWidgetAutoEditStrategyAdapter.java?rev=602698&r1=602697&r2=602698&view=diff
==============================================================================
--- directory/studio/trunk/studio-ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/search/FilterWidgetAutoEditStrategyAdapter.java
(original)
+++ directory/studio/trunk/studio-ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/search/FilterWidgetAutoEditStrategyAdapter.java
Sun Dec  9 09:15:01 2007
@@ -106,6 +106,11 @@
             String oldText = combo.getText();
             //parser.parse( oldText );
 
+            if( !oldTexts.isEmpty() )
+            {
+                oldTexts.clear();
+                verifyEvents.clear();
+            }
             oldTexts.add( oldText );
             verifyEvents.add( e );
         }

Modified: directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/filter/LdapFilter.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/filter/LdapFilter.java?rev=602698&r1=602697&r2=602698&view=diff
==============================================================================
--- directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/filter/LdapFilter.java
(original)
+++ directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/filter/LdapFilter.java
Sun Dec  9 09:15:01 2007
@@ -206,7 +206,7 @@
      */
     public boolean isValid()
     {
-        return startToken != null && filterComponent != null && filterComponent.isValid()
&& stopToken != null;
+        return startToken != null && filterComponent != null && filterComponent.isValid()
&& stopToken != null && otherTokens.isEmpty();
     }
 
 
@@ -299,7 +299,17 @@
      */
     public String toString()
     {
-        return ( startToken != null ? "(" : "" ) + ( filterComponent != null ? filterComponent.toString()
: "" ) + ( stopToken != null ? ")" : "" ); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
//$NON-NLS-5$
+        StringBuffer sb = new StringBuffer();
+        LdapFilterToken[] tokens = getTokens();
+        for ( LdapFilterToken token : tokens )
+        {
+            sb.append( token.getValue() );
+        }
+        return sb.toString();
+//        return ( startToken != null ? "(" : "" ) + 
+//        ( filterComponent != null ? filterComponent.toString() : "" ) + 
+//        ( stopToken != null ? ")" : "" ); 
+//        //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
     }
 
 }

Modified: directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/filter/LdapFilterItemComponent.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/filter/LdapFilterItemComponent.java?rev=602698&r1=602697&r2=602698&view=diff
==============================================================================
--- directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/filter/LdapFilterItemComponent.java
(original)
+++ directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/filter/LdapFilterItemComponent.java
Sun Dec  9 09:15:01 2007
@@ -113,7 +113,9 @@
             && ( filtertypeToken.getType() == LdapFilterToken.EQUAL
                 || filtertypeToken.getType() == LdapFilterToken.GREATER
                 || filtertypeToken.getType() == LdapFilterToken.LESS
-                || filtertypeToken.getType() == LdapFilterToken.APROX || filtertypeToken.getType()
== LdapFilterToken.PRESENT ) )
+                || filtertypeToken.getType() == LdapFilterToken.APROX 
+                || filtertypeToken.getType() == LdapFilterToken.PRESENT
+                || filtertypeToken.getType() == LdapFilterToken.SUBSTRING ) )
         {
             this.filtertypeToken = filtertypeToken;
             return true;

Modified: directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/filter/parser/LdapFilterParser.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/filter/parser/LdapFilterParser.java?rev=602698&r1=602697&r2=602698&view=diff
==============================================================================
--- directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/filter/parser/LdapFilterParser.java
(original)
+++ directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/filter/parser/LdapFilterParser.java
Sun Dec  9 09:15:01 2007
@@ -195,6 +195,7 @@
                     case LdapFilterToken.LESS:
                     case LdapFilterToken.APROX:
                     case LdapFilterToken.PRESENT:
+                    case LdapFilterToken.SUBSTRING:
                     {
                         LdapFilter currentFilter = filterStack.peek();
                         LdapFilterComponent filterComponent = currentFilter.getFilterComponent();

Modified: directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/filter/parser/LdapFilterScanner.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/filter/parser/LdapFilterScanner.java?rev=602698&r1=602697&r2=602698&view=diff
==============================================================================
--- directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/filter/parser/LdapFilterScanner.java
(original)
+++ directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/filter/parser/LdapFilterScanner.java
Sun Dec  9 09:15:01 2007
@@ -224,8 +224,13 @@
                 this.lastTokenType = LdapFilterToken.LPAR;
                 return new LdapFilterToken( this.lastTokenType, "(", pos );
             case ')':
-                this.lastTokenType = LdapFilterToken.RPAR;
-                return new LdapFilterToken( this.lastTokenType, ")", pos );
+                if ( lastTokenType != LdapFilterToken.EQUAL && lastTokenType != LdapFilterToken.GREATER
+                    && lastTokenType != LdapFilterToken.LESS && lastTokenType
!= LdapFilterToken.APROX 
+                    && lastTokenType != LdapFilterToken.SUBSTRING )
+                {
+                    this.lastTokenType = LdapFilterToken.RPAR;
+                    return new LdapFilterToken( this.lastTokenType, ")", pos );
+                }
             case '&':
                 if ( lastTokenType == LdapFilterToken.LPAR )
                 {
@@ -281,13 +286,41 @@
                         {
                             prevChar();
                             prevChar();
-                            this.lastTokenType = LdapFilterToken.EQUAL;
-                            return new LdapFilterToken( this.lastTokenType, "=", pos );
                         }
                     }
                     else
                     {
                         prevChar();
+                    }
+                    
+                    // substring or equal
+                    // read till ) or eof, if we found an * we have an substring
+                    boolean asteriskFound = false;
+                    c = nextNonLinebreakChar();
+                    int count = 1;
+                    while ( c != ')' && c != '\u0000' )
+                    {
+                        if( c == '*' )
+                        {
+                            asteriskFound = true;
+                            break;
+                        }
+                        
+                        c = nextNonLinebreakChar();
+                        count++;
+                    }
+                    while( count > 0 )
+                    {
+                        prevNonLinebreakChar();
+                        count--;
+                    }
+                    if( asteriskFound )
+                    {
+                        this.lastTokenType = LdapFilterToken.SUBSTRING;
+                        return new LdapFilterToken( this.lastTokenType, "=", pos );
+                    }
+                    else
+                    {
                         this.lastTokenType = LdapFilterToken.EQUAL;
                         return new LdapFilterToken( this.lastTokenType, "=", pos );
                     }
@@ -418,17 +451,67 @@
         if ( lastTokenType == LdapFilterToken.EQUAL || lastTokenType == LdapFilterToken.GREATER
             || lastTokenType == LdapFilterToken.LESS || lastTokenType == LdapFilterToken.APROX
)
         {
+            boolean forbiddenCharFound = false;
+            StringBuffer sb = new StringBuffer();
+            c = nextNonLinebreakChar();
+            int count = 0;
+            while ( c != ')' && c != '\u0000' )
+            {
+                if ( c == '*' || c == '(' )
+                {
+                    forbiddenCharFound = true;
+                    break;
+                }
+
+                sb.append( c );
+                c = nextNonLinebreakChar();
+                count++;
+            }
+            prevNonLinebreakChar();
 
+            if ( forbiddenCharFound )
+            {
+                while ( count > 0 )
+                {
+                    prevNonLinebreakChar();
+                    count--;
+                }
+            }
+            else //if ( sb.length() > 0 )
+            {
+                this.lastTokenType = LdapFilterToken.VALUE;
+                return new LdapFilterToken( this.lastTokenType, sb.toString(), pos - sb.length()
+ 1 );
+            }
+        }
+        if ( lastTokenType == LdapFilterToken.SUBSTRING )
+        {
+            boolean forbiddenCharFound = false;
             StringBuffer sb = new StringBuffer();
             c = nextNonLinebreakChar();
-            while ( c != '(' && c != ')' && c != '\u0000' )
+            int count = 0;
+            while ( c != ')' && c != '\u0000' )
             {
+                if ( c == '(' )
+                {
+                    forbiddenCharFound = true;
+                    break;
+                }
+
                 sb.append( c );
                 c = nextNonLinebreakChar();
+                count++;
             }
             prevNonLinebreakChar();
 
-            if ( sb.length() > 0 )
+            if ( forbiddenCharFound )
+            {
+                while ( count > 0 )
+                {
+                    prevNonLinebreakChar();
+                    count--;
+                }
+            }
+            else if ( sb.length() > 0 )
             {
                 this.lastTokenType = LdapFilterToken.VALUE;
                 return new LdapFilterToken( this.lastTokenType, sb.toString(), pos - sb.length()
+ 1 );

Modified: directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/filter/parser/LdapFilterToken.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/filter/parser/LdapFilterToken.java?rev=602698&r1=602697&r2=602698&view=diff
==============================================================================
--- directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/filter/parser/LdapFilterToken.java
(original)
+++ directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/filter/parser/LdapFilterToken.java
Sun Dec  9 09:15:01 2007
@@ -77,6 +77,9 @@
 
     /** The token identifier for the present filter type =* */
     public static final int PRESENT = 45;
+    
+    /** The token identifier for the substring filter type =* */
+    public static final int SUBSTRING = 46;
 
     /** The token identifier for a value. */
     public static final int VALUE = 51;

Added: directory/studio/trunk/studio-ldapbrowser-core/src/test/java/org/apache/directory/studio/ldapbrowser/core/model/LdapFilterParserErrorTolerantTest.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-ldapbrowser-core/src/test/java/org/apache/directory/studio/ldapbrowser/core/model/LdapFilterParserErrorTolerantTest.java?rev=602698&view=auto
==============================================================================
--- directory/studio/trunk/studio-ldapbrowser-core/src/test/java/org/apache/directory/studio/ldapbrowser/core/model/LdapFilterParserErrorTolerantTest.java
(added)
+++ directory/studio/trunk/studio-ldapbrowser-core/src/test/java/org/apache/directory/studio/ldapbrowser/core/model/LdapFilterParserErrorTolerantTest.java
Sun Dec  9 09:15:01 2007
@@ -0,0 +1,169 @@
+/*
+ *   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.
+ *
+ */
+
+package org.apache.directory.studio.ldapbrowser.core.model;
+
+
+import junit.framework.TestCase;
+
+import org.apache.directory.studio.ldapbrowser.core.model.filter.LdapFilter;
+import org.apache.directory.studio.ldapbrowser.core.model.filter.LdapFilterComponent;
+import org.apache.directory.studio.ldapbrowser.core.model.filter.LdapFilterItemComponent;
+import org.apache.directory.studio.ldapbrowser.core.model.filter.parser.LdapFilterParser;
+import org.apache.directory.studio.ldapbrowser.core.model.filter.parser.LdapFilterToken;
+
+
+/**
+ * Tests the filter parser for error tolerance. 
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class LdapFilterParserErrorTolerantTest extends TestCase
+{
+    private LdapFilterParser parser = new LdapFilterParser();
+
+
+    public void testLpar()
+    {
+        parser.parse( "(" );
+
+        LdapFilter model = parser.getModel();
+
+        assertNotNull( model.getStartToken() );
+        assertEquals( 0, model.getStartToken().getOffset() );
+        assertEquals( 1, model.getStartToken().getLength() );
+        assertEquals( LdapFilterToken.LPAR, model.getStartToken().getType() );
+        assertEquals( "(", model.getStartToken().getValue() );
+
+        assertNull( model.getFilterComponent() );
+
+        assertNull( model.getStopToken() );
+
+        assertEquals( "(", model.toString() );
+        assertFalse( parser.getModel().isValid() );
+    }
+
+
+    public void testLparAttr()
+    {
+        parser.parse( "(objectClass" );
+
+        LdapFilter model = parser.getModel();
+
+        assertNotNull( model.getStartToken() );
+        assertEquals( 0, model.getStartToken().getOffset() );
+        assertEquals( 1, model.getStartToken().getLength() );
+        assertEquals( LdapFilterToken.LPAR, model.getStartToken().getType() );
+        assertEquals( "(", model.getStartToken().getValue() );
+
+        LdapFilterComponent filterComponent = model.getFilterComponent();
+        assertNotNull( filterComponent );
+        assertTrue( filterComponent instanceof LdapFilterItemComponent );
+        LdapFilterItemComponent filterItemComponent = ( LdapFilterItemComponent ) filterComponent;
+        assertNotNull( filterItemComponent.getAttributeToken() );
+        assertEquals( 1, filterItemComponent.getAttributeToken().getOffset() );
+        assertEquals( 11, filterItemComponent.getAttributeToken().getLength() );
+        assertEquals( LdapFilterToken.ATTRIBUTE, filterItemComponent.getAttributeToken().getType()
);
+        assertEquals( "objectClass", filterItemComponent.getAttributeToken().getValue() );
+        assertNull( filterItemComponent.getFilterToken() );
+        assertNull( filterItemComponent.getValueToken() );
+
+        assertNull( model.getStopToken() );
+
+        assertEquals( "(objectClass", model.toString() );
+        assertFalse( parser.getModel().isValid() );
+    }
+
+
+    public void testLparAttrEquals()
+    {
+        parser.parse( "(objectClass=" );
+
+        LdapFilter model = parser.getModel();
+
+        assertNotNull( model.getStartToken() );
+        assertEquals( 0, model.getStartToken().getOffset() );
+        assertEquals( 1, model.getStartToken().getLength() );
+        assertEquals( LdapFilterToken.LPAR, model.getStartToken().getType() );
+        assertEquals( "(", model.getStartToken().getValue() );
+
+        LdapFilterComponent filterComponent = model.getFilterComponent();
+        assertNotNull( filterComponent );
+        assertTrue( filterComponent instanceof LdapFilterItemComponent );
+        LdapFilterItemComponent filterItemComponent = ( LdapFilterItemComponent ) filterComponent;
+        assertNotNull( filterItemComponent.getAttributeToken() );
+        assertEquals( 1, filterItemComponent.getAttributeToken().getOffset() );
+        assertEquals( 11, filterItemComponent.getAttributeToken().getLength() );
+        assertEquals( LdapFilterToken.ATTRIBUTE, filterItemComponent.getAttributeToken().getType()
);
+        assertEquals( "objectClass", filterItemComponent.getAttributeToken().getValue() );
+
+        assertNotNull( filterItemComponent.getFilterToken() );
+        assertEquals( 12, filterItemComponent.getFilterToken().getOffset() );
+        assertEquals( 1, filterItemComponent.getFilterToken().getLength() );
+        assertEquals( LdapFilterToken.EQUAL, filterItemComponent.getFilterToken().getType()
);
+        assertEquals( "=", filterItemComponent.getFilterToken().getValue() );
+
+        assertNull( filterItemComponent.getValueToken() );
+
+        assertNull( model.getStopToken() );
+
+        assertEquals( "(objectClass=", model.toString() );
+        assertFalse( parser.getModel().isValid() );
+    }
+
+
+    public void testLparAttrEqualsRpar()
+    {
+        parser.parse( "(objectClass=)" );
+
+        LdapFilter model = parser.getModel();
+
+        assertNotNull( model.getStartToken() );
+        assertEquals( 0, model.getStartToken().getOffset() );
+        assertEquals( 1, model.getStartToken().getLength() );
+        assertEquals( LdapFilterToken.LPAR, model.getStartToken().getType() );
+        assertEquals( "(", model.getStartToken().getValue() );
+
+        LdapFilterComponent filterComponent = model.getFilterComponent();
+        assertNotNull( filterComponent );
+        assertTrue( filterComponent instanceof LdapFilterItemComponent );
+        LdapFilterItemComponent filterItemComponent = ( LdapFilterItemComponent ) filterComponent;
+        assertNotNull( filterItemComponent.getAttributeToken() );
+        assertEquals( 1, filterItemComponent.getAttributeToken().getOffset() );
+        assertEquals( 11, filterItemComponent.getAttributeToken().getLength() );
+        assertEquals( LdapFilterToken.ATTRIBUTE, filterItemComponent.getAttributeToken().getType()
);
+        assertEquals( "objectClass", filterItemComponent.getAttributeToken().getValue() );
+
+        assertNotNull( filterItemComponent.getFilterToken() );
+        assertEquals( 12, filterItemComponent.getFilterToken().getOffset() );
+        assertEquals( 1, filterItemComponent.getFilterToken().getLength() );
+        assertEquals( LdapFilterToken.EQUAL, filterItemComponent.getFilterToken().getType()
);
+        assertEquals( "=", filterItemComponent.getFilterToken().getValue() );
+
+        assertNotNull( filterItemComponent.getValueToken() );
+
+        assertNotNull( model.getStopToken() );
+
+        assertEquals( "(objectClass=)", model.toString() );
+        assertTrue( parser.getModel().isValid() );
+    }
+
+}

Propchange: directory/studio/trunk/studio-ldapbrowser-core/src/test/java/org/apache/directory/studio/ldapbrowser/core/model/LdapFilterParserErrorTolerantTest.java
------------------------------------------------------------------------------
    svn:executable = *

Modified: directory/studio/trunk/studio-ldapbrowser-core/src/test/java/org/apache/directory/studio/ldapbrowser/core/model/LdapFilterParserTest.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-ldapbrowser-core/src/test/java/org/apache/directory/studio/ldapbrowser/core/model/LdapFilterParserTest.java?rev=602698&r1=602697&r2=602698&view=diff
==============================================================================
--- directory/studio/trunk/studio-ldapbrowser-core/src/test/java/org/apache/directory/studio/ldapbrowser/core/model/LdapFilterParserTest.java
(original)
+++ directory/studio/trunk/studio-ldapbrowser-core/src/test/java/org/apache/directory/studio/ldapbrowser/core/model/LdapFilterParserTest.java
Sun Dec  9 09:15:01 2007
@@ -20,12 +20,14 @@
 
 package org.apache.directory.studio.ldapbrowser.core.model;
 
+
 import junit.framework.TestCase;
 
 import org.apache.directory.studio.ldapbrowser.core.model.filter.parser.LdapFilterParser;
 
+
 /**
- * Test the filter parser
+ * Tests the filter parser.
  *
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  * @version $Rev$, $Date$
@@ -33,29 +35,226 @@
 public class LdapFilterParserTest extends TestCase
 {
     private LdapFilterParser parser = new LdapFilterParser();
-    
+
+
     /**
      * Tests an equals filter
      */
     public void testEqualsFilter()
     {
         parser.parse( "(cn=test)" );
-        assertEquals( "(cn=test)", parser.getModel().toString());
+        assertEquals( "(cn=test)", parser.getModel().toString() );
+        assertTrue( parser.getModel().isValid() );
+    }
+
+
+    /**
+     * Tests an greater equals filter
+     */
+    public void testGreaterEqualsFilter()
+    {
+        parser.parse( "(cn>=test)" );
+        assertEquals( "(cn>=test)", parser.getModel().toString() );
+        assertTrue( parser.getModel().isValid() );
+    }
+
+
+    /**
+     * Tests an less equals filter
+     */
+    public void testLessEqualsFilter()
+    {
+        parser.parse( "(cn<=test)" );
+        assertEquals( "(cn<=test)", parser.getModel().toString() );
         assertTrue( parser.getModel().isValid() );
     }
+
+
+    /**
+     * Tests an aprox filter
+     */
+    public void testAproxFilter()
+    {
+        parser.parse( "(cn~=test)" );
+        assertEquals( "(cn~=test)", parser.getModel().toString() );
+        assertTrue( parser.getModel().isValid() );
+    }
+    
     
     /**
+     * Tests an substring filter
+     */
+    public void testSubstringFilter()
+    {
+        parser.parse( "(cn=te*st)" );
+        assertEquals( "(cn=te*st)", parser.getModel().toString() );
+        assertTrue( parser.getModel().isValid() );
+    }
+
+
+    /**
      * Tests an present filter
      */
     public void testPresentFilter()
     {
         parser.parse( "(cn=*)" );
-        assertEquals( "(cn=*)", parser.getModel().toString());
+        assertEquals( "(cn=*)", parser.getModel().toString() );
         assertTrue( parser.getModel().isValid() );
     }
-    
+
+
+    /**
+     * Tests an simple filter
+     */
+    public void testRFC4515_1()
+    {
+        parser.parse( "(cn=Babs Jensen)" );
+        assertEquals( "(cn=Babs Jensen)", parser.getModel().toString() );
+        assertTrue( parser.getModel().isValid() );
+    }
+
+
+    /**
+     * Tests an not filter
+     */
+    public void testRFC4515_2()
+    {
+        parser.parse( "(!(cn=Tim Howes))" );
+        assertEquals( "(!(cn=Tim Howes))", parser.getModel().toString() );
+        assertTrue( parser.getModel().isValid() );
+    }
+
+
+    /**
+     * Tests an and/or filter
+     */
+    public void testRFC4515_3()
+    {
+        parser.parse( "(&(objectClass=Person)(|(sn=Jensen)(cn=Babs J*)))" );
+        assertEquals( "(&(objectClass=Person)(|(sn=Jensen)(cn=Babs J*)))", parser.getModel().toString()
);
+        assertTrue( parser.getModel().isValid() );
+    }
+
+
+    /**
+     * Tests an substring filter
+     */
+    public void testRFC4515_4()
+    {
+        parser.parse( "(o=univ*of*mich*)" );
+        assertEquals( "(o=univ*of*mich*)", parser.getModel().toString() );
+        assertTrue( parser.getModel().isValid() );
+    }
+
+
+    /**
+     * Tests an empty assertion value
+     */
+    public void testRFC4515_5()
+    {
+        parser.parse( "(seeAlso=)" );
+        assertEquals( "(seeAlso=)", parser.getModel().toString() );
+        assertTrue( parser.getModel().isValid() );
+    }
+
+
+    /**
+     * Tests an filter with escaped assertion value.
+     * 
+     * From RFC4515:
+     * The first example shows the use of the escaping mechanism to
+     * represent parenthesis characters.  
+     */
+    public void testEscapeRFC4515_1()
+    {
+        parser.parse( "(o=Parens R Us \\28for all your parenthetical needs\\29)" );
+        assertEquals( "(o=Parens R Us \\28for all your parenthetical needs\\29)", parser.getModel().toString()
);
+        assertTrue( parser.getModel().isValid() );
+    }
+
+
+    /**
+     * Tests an filter with escaped assertion value.
+     * 
+     * From RFC4515:
+     * The second shows how to represent
+     * a "*" in an assertion value, preventing it from being interpreted as
+     * a substring indicator.
+     */
+    public void testEscapeRFC4515_2()
+    {
+        parser.parse( "(cn=*\\2A*)" );
+        assertEquals( "(cn=*\\2A*)", parser.getModel().toString() );
+        assertTrue( parser.getModel().isValid() );
+    }
+
+
+    /**
+     * Tests an filter with escaped assertion value.
+     * 
+     * From RFC4515:
+     * The third illustrates the escaping of the backslash character.
+     */
+    public void testEscapeRFC4515_3()
+    {
+        parser.parse( "(filename=C:\\5cMyFile)" );
+        assertEquals( "(filename=C:\\5cMyFile)", parser.getModel().toString() );
+        assertTrue( parser.getModel().isValid() );
+    }
+
+
     /**
-     * Tests an extensible filter
+     * Tests an filter with escaped assertion value.
+     * 
+     * From RFC4515:
+     * The fourth example shows a filter searching for the four-octet value
+     * 00 00 00 04 (hex), illustrating the use of the escaping mechanism to
+     * represent arbitrary data, including NUL characters.
+     */
+    public void testEscapeRFC4515_4()
+    {
+        parser.parse( "(bin=\\00\\00\\00\\04)" );
+        assertEquals( "(bin=\\00\\00\\00\\04)", parser.getModel().toString() );
+        assertTrue( parser.getModel().isValid() );
+    }
+
+
+    /**
+     * Tests an filter with escaped assertion value.
+     * 
+     * From RFC4515:
+     * The fifth example illustrates the use of the escaping mechanism to
+     * represent various non-ASCII UTF-8 characters.  Specifically, there
+     * are 5 characters in the <assertionvalue> portion of this example:
+     * LATIN CAPITAL LETTER L (U+004C), LATIN SMALL LETTER U (U+0075), LATIN
+     * SMALL LETTER C WITH CARON (U+010D), LATIN SMALL LETTER I (U+0069),
+     * and LATIN SMALL LETTER C WITH ACUTE (U+0107).
+     */
+    public void testEscapeRFC4515_5()
+    {
+        parser.parse( "(sn=Lu\\c4\\8di\\c4\\87)" );
+        assertEquals( "(sn=Lu\\c4\\8di\\c4\\87)", parser.getModel().toString() );
+        assertTrue( parser.getModel().isValid() );
+    }
+
+
+    /**
+     * Tests an filter with escaped assertion value.
+     * 
+     * From RFC4515:
+     * The sixth and final example demonstrates assertion of a BER-encoded´
+     * value.
+     */
+    public void testEscapeRFC4515_6()
+    {
+        parser.parse( "(1.3.6.1.4.1.1466.0=\\04\\02\\48\\69)" );
+        assertEquals( "(1.3.6.1.4.1.1466.0=\\04\\02\\48\\69)", parser.getModel().toString()
);
+        assertTrue( parser.getModel().isValid() );
+    }
+
+
+    /**
+     * Tests an extensible filter.
      * 
      * From RFC4515:
      * The first example shows use of the matching rule "caseExactMatch."
@@ -63,9 +262,11 @@
     public void testExtensibleFilterRFC4515_1()
     {
         parser.parse( "(cn:caseExactMatch:=Fred Flintstone)" );
-        assertEquals( "(cn:caseExactMatch:=Fred Flintstone)", parser.getModel().toString());
+        assertEquals( "(cn:caseExactMatch:=Fred Flintstone)", parser.getModel().toString()
);
         assertTrue( parser.getModel().isValid() );
     }
+
+
     /**
      * Tests an extensible filter.
      * 
@@ -76,9 +277,11 @@
     public void testExtensibleFilterRFC4515_2()
     {
         parser.parse( "(cn:=Betty Rubble)" );
-        assertEquals( "(cn:=Betty Rubble)", parser.getModel().toString());
+        assertEquals( "(cn:=Betty Rubble)", parser.getModel().toString() );
         assertTrue( parser.getModel().isValid() );
     }
+
+
     /**
      * Tests an extensible filter.
      * 
@@ -92,9 +295,11 @@
     public void testExtensibleFilterRFC4515_3()
     {
         parser.parse( "(sn:dn:2.4.6.8.10:=Barney Rubble)" );
-        assertEquals( "(sn:dn:2.4.6.8.10:=Barney Rubble)", parser.getModel().toString());
+        assertEquals( "(sn:dn:2.4.6.8.10:=Barney Rubble)", parser.getModel().toString() );
         assertTrue( parser.getModel().isValid() );
     }
+
+
     /**
      * Tests an extensible filter.
      * 
@@ -106,9 +311,11 @@
     public void testExtensibleFilterRFC4515_4()
     {
         parser.parse( "(o:dn:=Ace Industry)" );
-        assertEquals( "(o:dn:=Ace Industry)", parser.getModel().toString());
+        assertEquals( "(o:dn:=Ace Industry)", parser.getModel().toString() );
         assertTrue( parser.getModel().isValid() );
     }
+
+
     /**
      * Tests an extensible filter.
      * 
@@ -120,9 +327,11 @@
     public void testExtensibleFilterRFC4515_5()
     {
         parser.parse( "(:1.2.3:=Wilma Flintstone)" );
-        assertEquals( "(:1.2.3:=Wilma Flintstone)", parser.getModel().toString());
+        assertEquals( "(:1.2.3:=Wilma Flintstone)", parser.getModel().toString() );
         assertTrue( parser.getModel().isValid() );
     }
+
+
     /**
      * Tests an extensible filter.
      * 
@@ -135,8 +344,17 @@
     public void testExtensibleFilterRFC4515_6()
     {
         parser.parse( "(:DN:2.4.6.8.10:=Dino)" );
-        assertEquals( "(:DN:2.4.6.8.10:=Dino)", parser.getModel().toString());
+        assertEquals( "(:DN:2.4.6.8.10:=Dino)", parser.getModel().toString() );
         assertTrue( parser.getModel().isValid() );
     }
 
+
+    /**
+     * Test for DIRSTUIO-210.
+     */
+    public void testDIRSTUDIO210()
+    {
+        parser.parse( "(objectClass>=z*) " );
+        assertFalse( parser.getModel().isValid() );
+    }
 }



Mime
View raw message