directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From seelm...@apache.org
Subject svn commit: r545640 [2/2] - in /directory/studio/trunk: ldapstudio-aciitemeditor/src/main/java/org/apache/directory/ldapstudio/aciitemeditor/valueeditors/ ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/dialogs/ l...
Date Fri, 08 Jun 2007 21:42:20 GMT
Modified: directory/studio/trunk/ldapstudio-browser-core/src/main/java/org/apache/directory/ldapstudio/browser/core/model/filter/parser/LdapFilterParser.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/ldapstudio-browser-core/src/main/java/org/apache/directory/ldapstudio/browser/core/model/filter/parser/LdapFilterParser.java?view=diff&rev=545640&r1=545639&r2=545640
==============================================================================
--- directory/studio/trunk/ldapstudio-browser-core/src/main/java/org/apache/directory/ldapstudio/browser/core/model/filter/parser/LdapFilterParser.java
(original)
+++ directory/studio/trunk/ldapstudio-browser-core/src/main/java/org/apache/directory/ldapstudio/browser/core/model/filter/parser/LdapFilterParser.java
Fri Jun  8 14:42:18 2007
@@ -26,21 +26,34 @@
 import org.apache.directory.ldapstudio.browser.core.model.filter.LdapAndFilterComponent;
 import org.apache.directory.ldapstudio.browser.core.model.filter.LdapFilter;
 import org.apache.directory.ldapstudio.browser.core.model.filter.LdapFilterComponent;
+import org.apache.directory.ldapstudio.browser.core.model.filter.LdapFilterExtensibleComponent;
 import org.apache.directory.ldapstudio.browser.core.model.filter.LdapFilterItemComponent;
 import org.apache.directory.ldapstudio.browser.core.model.filter.LdapNotFilterComponent;
 import org.apache.directory.ldapstudio.browser.core.model.filter.LdapOrFilterComponent;
 
 
+/**
+ * The LdapFilterParser implements a parser for LDAP filters.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
 public class LdapFilterParser
 {
 
+    /** The scanner. */
     private LdapFilterScanner scanner;
 
-    private Stack filterStack;
+    /** The filter stack. */
+    private Stack<LdapFilter> filterStack;
 
+    /** The parsed LDAP filter model. */
     private LdapFilter model;
 
 
+    /**
+     * Creates a new instance of LdapFilterParser.
+     */
     public LdapFilterParser()
     {
         this.scanner = new LdapFilterScanner();
@@ -48,42 +61,49 @@
     }
 
 
+    /**
+     * Gets the parsed LDAP filter model.
+     * 
+     * @return the parsed model
+     */
     public LdapFilter getModel()
     {
-        return this.model;
+        return model;
     }
 
 
+    /**
+     * Parses the given LDAP filter.
+     * 
+     * @param ldapFilter the LDAP filter
+     */
     public void parse( String ldapFilter )
     {
-
         // reset state
-        this.filterStack = new Stack();
-        this.scanner.reset( ldapFilter );
-        this.model = new LdapFilter();
+        filterStack = new Stack<LdapFilter>();
+        scanner.reset( ldapFilter );
+        model = new LdapFilter();
 
         // handle error tokens before filter
-        LdapFilterToken token = this.scanner.nextToken();
+        LdapFilterToken token = scanner.nextToken();
         while ( token.getType() != LdapFilterToken.LPAR && token.getType() != LdapFilterToken.EOF
)
         {
-            this.handleError( false, token, this.model );
+            handleError( false, token, model );
             token = scanner.nextToken();
         }
 
         // check filter start
         if ( token.getType() == LdapFilterToken.LPAR )
         {
-
             // start top level filter
-            this.model.setStartToken( token );
-            filterStack.push( this.model );
+            model.setStartToken( token );
+            filterStack.push( model );
 
             // loop till filter end or EOF
             do
             {
-
                 // next token
-                token = this.scanner.nextToken();
+                token = scanner.nextToken();
 
                 switch ( token.getType() )
                 {
@@ -92,7 +112,7 @@
                         LdapFilter newFilter = new LdapFilter();
                         newFilter.setStartToken( token );
 
-                        LdapFilter currentFilter = ( LdapFilter ) filterStack.peek();
+                        LdapFilter currentFilter = filterStack.peek();
                         LdapFilterComponent filterComponent = currentFilter.getFilterComponent();
                         if ( filterComponent != null && filterComponent.addFilter(
newFilter ) )
                         {
@@ -107,8 +127,8 @@
                     }
                     case LdapFilterToken.RPAR:
                     {
-                        LdapFilter currentFilter = ( LdapFilter ) filterStack.pop();
-                        this.handleError( currentFilter.setStopToken( token ), token, currentFilter
);
+                        LdapFilter currentFilter = filterStack.pop();
+                        handleError( currentFilter.setStopToken( token ), token, currentFilter
);
                         /*
                          * if(!filterStack.isEmpty()) { LdapFilter parentFilter =
                          * (LdapFilter) filterStack.peek(); LdapFilterComponent
@@ -119,43 +139,55 @@
                     }
                     case LdapFilterToken.AND:
                     {
-                        LdapFilter currentFilter = ( LdapFilter ) filterStack.peek();
+                        LdapFilter currentFilter = filterStack.peek();
                         LdapAndFilterComponent filterComponent = new LdapAndFilterComponent(
currentFilter );
                         filterComponent.setStartToken( token );
-                        this.handleError( currentFilter.setFilterComponent( filterComponent
), token, currentFilter );
+                        handleError( currentFilter.setFilterComponent( filterComponent ),
token, currentFilter );
                         break;
                     }
                     case LdapFilterToken.OR:
                     {
-                        LdapFilter currentFilter = ( LdapFilter ) filterStack.peek();
+                        LdapFilter currentFilter = filterStack.peek();
                         LdapOrFilterComponent filterComponent = new LdapOrFilterComponent(
currentFilter );
                         filterComponent.setStartToken( token );
-                        this.handleError( currentFilter.setFilterComponent( filterComponent
), token, currentFilter );
+                        handleError( currentFilter.setFilterComponent( filterComponent ),
token, currentFilter );
                         break;
                     }
                     case LdapFilterToken.NOT:
                     {
-                        LdapFilter currentFilter = ( LdapFilter ) filterStack.peek();
+                        LdapFilter currentFilter = filterStack.peek();
                         LdapNotFilterComponent filterComponent = new LdapNotFilterComponent(
currentFilter );
                         filterComponent.setStartToken( token );
-                        this.handleError( currentFilter.setFilterComponent( filterComponent
), token, currentFilter );
+                        handleError( currentFilter.setFilterComponent( filterComponent ),
token, currentFilter );
                         break;
                     }
                     case LdapFilterToken.ATTRIBUTE:
                     {
-                        LdapFilter currentFilter = ( LdapFilter ) filterStack.peek();
+                        LdapFilter currentFilter = filterStack.peek();
                         LdapFilterItemComponent filterComponent = new LdapFilterItemComponent(
currentFilter );
                         filterComponent.setAttributeToken( token );
-                        this.handleError( currentFilter.setFilterComponent( filterComponent
), token, currentFilter );
+                        handleError( currentFilter.setFilterComponent( filterComponent ),
token, currentFilter );
                         break;
                     }
                     case LdapFilterToken.VALUE:
                     {
-                        LdapFilter currentFilter = ( LdapFilter ) filterStack.peek();
+                        LdapFilter currentFilter = filterStack.peek();
                         LdapFilterComponent filterComponent = currentFilter.getFilterComponent();
-                        this.handleError( ( filterComponent instanceof LdapFilterItemComponent
)
-                            && ( ( LdapFilterItemComponent ) filterComponent ).setValueToken(
token ), token,
-                            currentFilter );
+                        if( filterComponent instanceof LdapFilterItemComponent )
+                        {
+                            handleError( ( filterComponent instanceof LdapFilterItemComponent
)
+                                && ( ( LdapFilterItemComponent ) filterComponent
).setValueToken( token ), token,
+                                currentFilter );
+                        }
+                        else if( filterComponent instanceof LdapFilterExtensibleComponent
)
+                        {
+                            handleError( ( filterComponent instanceof LdapFilterExtensibleComponent
)
+                                && ( ( LdapFilterExtensibleComponent ) filterComponent
).setValueToken( token ), token,
+                                currentFilter );
+                        }
+                        else {
+                            handleError( false, token, currentFilter );
+                        }
                         break;
                     }
                     case LdapFilterToken.EQUAL:
@@ -164,46 +196,135 @@
                     case LdapFilterToken.APROX:
                     case LdapFilterToken.PRESENT:
                     {
+                        LdapFilter currentFilter = filterStack.peek();
+                        LdapFilterComponent filterComponent = currentFilter.getFilterComponent();
+                        if( filterComponent instanceof LdapFilterItemComponent )
+                        {
+                            handleError( ( filterComponent instanceof LdapFilterItemComponent
)
+                                && ( ( LdapFilterItemComponent ) filterComponent
).setFiltertypeToken( token ), token,
+                                currentFilter );
+                        }
+                        else if( filterComponent instanceof LdapFilterExtensibleComponent
)
+                        {
+                            handleError( ( filterComponent instanceof LdapFilterExtensibleComponent
)
+                                && ( ( LdapFilterExtensibleComponent ) filterComponent
).setEqualsToken( token ), token,
+                                currentFilter );
+                        }
+                        else {
+                            handleError( false, token, currentFilter );
+                        }
+                        break;
+                    }
+                    case LdapFilterToken.WHITESPACE:
+                    {
+                        LdapFilter currentFilter = filterStack.peek();
+                        currentFilter.addOtherToken( token );
+                        break;
+                    }
+                    case LdapFilterToken.EXTENSIBLE_ATTRIBUTE:
+                    {
+                        LdapFilter currentFilter = ( LdapFilter ) filterStack.peek();
+                        LdapFilterExtensibleComponent filterComponent = new LdapFilterExtensibleComponent(
currentFilter );
+                        filterComponent.setAttributeToken( token );
+                        handleError( currentFilter.setFilterComponent( filterComponent ),
token, currentFilter );
+                        break;
+                    }
+                    case LdapFilterToken.EXTENSIBLE_DNATTR_COLON:
+                    {
+                        LdapFilter currentFilter = ( LdapFilter ) filterStack.peek();
+                        LdapFilterComponent filterComponent = currentFilter.getFilterComponent();
+                        if( filterComponent == null )
+                        {
+                            filterComponent = new LdapFilterExtensibleComponent( currentFilter
);
+                            (( LdapFilterExtensibleComponent ) filterComponent ).setDnAttrColonToken(
token );
+                            handleError( currentFilter.setFilterComponent( filterComponent
), token, currentFilter );
+                        }
+                        else
+                        {
+                            handleError( ( filterComponent instanceof LdapFilterExtensibleComponent
)
+                                && ( ( LdapFilterExtensibleComponent ) filterComponent
).setDnAttrColonToken( token ), token,
+                                currentFilter );
+                        }
+                        break;
+                    }
+                    case LdapFilterToken.EXTENSIBLE_DNATTR:
+                    {
                         LdapFilter currentFilter = ( LdapFilter ) filterStack.peek();
                         LdapFilterComponent filterComponent = currentFilter.getFilterComponent();
-                        this.handleError( ( filterComponent instanceof LdapFilterItemComponent
)
-                            && ( ( LdapFilterItemComponent ) filterComponent ).setFiltertypeToken(
token ), token,
+                        handleError( ( filterComponent instanceof LdapFilterExtensibleComponent
)
+                            && ( ( LdapFilterExtensibleComponent ) filterComponent
).setDnAttrToken( token ), token,
                             currentFilter );
                         break;
                     }
-                    case LdapFilterToken.WHITESPACE:
+                    case LdapFilterToken.EXTENSIBLE_MATCHINGRULEOID_COLON:
                     {
                         LdapFilter currentFilter = ( LdapFilter ) filterStack.peek();
-                        currentFilter.addOtherToken( token );
+                        LdapFilterComponent filterComponent = currentFilter.getFilterComponent();
+                        if( filterComponent == null )
+                        {
+                            filterComponent = new LdapFilterExtensibleComponent( currentFilter
);
+                            (( LdapFilterExtensibleComponent ) filterComponent ).setMatchingRuleColonToken(
token );
+                            handleError( currentFilter.setFilterComponent( filterComponent
), token, currentFilter );
+                        }
+                        else
+                        {
+                            handleError( ( filterComponent instanceof LdapFilterExtensibleComponent
)
+                                && ( ( LdapFilterExtensibleComponent ) filterComponent
).setMatchingRuleColonToken( token ), token,
+                                currentFilter );
+                        }
+                        break;
+                    }
+                    case LdapFilterToken.EXTENSIBLE_MATCHINGRULEOID:
+                    {
+                        LdapFilter currentFilter = ( LdapFilter ) filterStack.peek();
+                        LdapFilterComponent filterComponent = currentFilter.getFilterComponent();
+                        handleError( ( filterComponent instanceof LdapFilterExtensibleComponent
)
+                            && ( ( LdapFilterExtensibleComponent ) filterComponent
).setMatchingRuleToken( token ), token,
+                            currentFilter );
                         break;
                     }
+                    case LdapFilterToken.EXTENSIBLE_EQUALS_COLON:
+                        {
+                            LdapFilter currentFilter = ( LdapFilter ) filterStack.peek();
+                            LdapFilterComponent filterComponent = currentFilter.getFilterComponent();
+                            handleError( ( filterComponent instanceof LdapFilterExtensibleComponent
)
+                                && ( ( LdapFilterExtensibleComponent ) filterComponent
).setEqualsColonToken( token ), token,
+                                currentFilter );
+                            break;
+                        }
+                    
                     case LdapFilterToken.EOF:
                     {
-                        this.model.addOtherToken( token );
+                        model.addOtherToken( token );
                         break;
                     }
                     default:
                     {
-                        LdapFilter currentFilter = ( LdapFilter ) filterStack.peek();
-                        this.handleError( false, token, currentFilter );
+                        LdapFilter currentFilter = filterStack.peek();
+                        handleError( false, token, currentFilter );
                     }
                 }
             }
             while ( !filterStack.isEmpty() && token.getType() != LdapFilterToken.EOF
);
-
         }
 
         // handle error token after filter
         token = scanner.nextToken();
         while ( token.getType() != LdapFilterToken.EOF )
         {
-            this.handleError( false, token, this.model );
+            handleError( false, token, model );
             token = scanner.nextToken();
         }
-
     }
 
 
+    /**
+     * Helper method to handle parse errors.
+     * 
+     * @param success the success flag
+     * @param filter the filter
+     * @param token the token
+     */
     private void handleError( boolean success, LdapFilterToken token, LdapFilter filter )
     {
         if ( !success )

Modified: directory/studio/trunk/ldapstudio-browser-core/src/main/java/org/apache/directory/ldapstudio/browser/core/model/filter/parser/LdapFilterScanner.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/ldapstudio-browser-core/src/main/java/org/apache/directory/ldapstudio/browser/core/model/filter/parser/LdapFilterScanner.java?view=diff&rev=545640&r1=545639&r2=545640
==============================================================================
--- directory/studio/trunk/ldapstudio-browser-core/src/main/java/org/apache/directory/ldapstudio/browser/core/model/filter/parser/LdapFilterScanner.java
(original)
+++ directory/studio/trunk/ldapstudio-browser-core/src/main/java/org/apache/directory/ldapstudio/browser/core/model/filter/parser/LdapFilterScanner.java
Fri Jun  8 14:42:18 2007
@@ -22,8 +22,7 @@
 
 
 /**
- * 
- * TODO LdapFilterScanner.
+ * The LdapFilterScanner is a scanner for LDAP filters. 
  *
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  * @version $Rev$, $Date$
@@ -151,6 +150,12 @@
     }
 
 
+    /**
+     * Increments the position counter as long as there are
+     * line breaks and gets the character at that positon.
+     * 
+     * @return the character at the next position
+     */
     private char nextNonLinebreakChar()
     {
         while ( nextChar() == '\n' );
@@ -158,6 +163,12 @@
     }
 
 
+    /**
+     * Decrements the position counter as long as there are
+     * line breaks and gets the character at that positon.
+     * 
+     * @return the character at the previous position
+     */
     private char prevNonLinebreakChar()
     {
         while ( prevChar() == '\n' );
@@ -165,15 +176,11 @@
     }
 
 
-    // private char nextNonWhitespaceChar() {
-    // while(Character.isWhitespace(nextChar()));
-    // return currentChar();
-    // }
-    // private char prevNonWhitespaceChar() {
-    // while(Character.isWhitespace(prevChar()));
-    // return currentChar();
-    // }
-
+    /**
+     * Gets the next token.
+     * 
+     * @return the next token
+     */
     public LdapFilterToken nextToken()
     {
         char c;
@@ -285,6 +292,11 @@
                         return new LdapFilterToken( this.lastTokenType, "=", pos );
                     }
                 }
+                else if ( lastTokenType == LdapFilterToken.EXTENSIBLE_EQUALS_COLON )
+                {
+                    this.lastTokenType = LdapFilterToken.EQUAL;
+                    return new LdapFilterToken( this.lastTokenType, "=", pos );
+                }
                 break;
             case '>':
                 if ( lastTokenType == LdapFilterToken.ATTRIBUTE )
@@ -328,17 +340,57 @@
                     }
                 }
                 break;
+            case ':':
+                char t1 = nextChar();
+                char t2 = nextChar();
+                char t3 = nextChar();
+                prevChar();
+                prevChar();
+                prevChar();
+                if ( ( lastTokenType == LdapFilterToken.LPAR || lastTokenType == LdapFilterToken.EXTENSIBLE_ATTRIBUTE
)
+                    &&
+                    ( 
+//                        ( t1 == ':' && t2 != '=' )
+//                        ||
+//                        ( ( t1 == 'd' || t1 == 'D' ) && t2 == ':' && t3
== ':' )
+//                        ||
+                        ( ( t1 == 'd' || t1 == 'D' )  && ( t2 == 'n' || t2 == 'N'
) && ( t3 == ':' ) )
+                    )
+                    )
+                {
+                    this.lastTokenType = LdapFilterToken.EXTENSIBLE_DNATTR_COLON;
+                    return new LdapFilterToken( this.lastTokenType, ":", pos );
+                }
+                else if ( ( lastTokenType == LdapFilterToken.EXTENSIBLE_ATTRIBUTE
+                    || lastTokenType == LdapFilterToken.EXTENSIBLE_DNATTR
+                    || lastTokenType == LdapFilterToken.EXTENSIBLE_MATCHINGRULEOID 
+                    || lastTokenType == LdapFilterToken.EXTENSIBLE_MATCHINGRULEOID_COLON
)
+                    && t1 == '=' )
+                {
+                    this.lastTokenType = LdapFilterToken.EXTENSIBLE_EQUALS_COLON;
+                    return new LdapFilterToken( this.lastTokenType, ":", pos );
+                }
+                else if ( ( lastTokenType == LdapFilterToken.LPAR
+                    || lastTokenType == LdapFilterToken.EXTENSIBLE_ATTRIBUTE 
+                    || lastTokenType == LdapFilterToken.EXTENSIBLE_DNATTR 
+                    || lastTokenType == LdapFilterToken.EXTENSIBLE_DNATTR_COLON ) )
+                {
+                    this.lastTokenType = LdapFilterToken.EXTENSIBLE_MATCHINGRULEOID_COLON;
+                    return new LdapFilterToken( this.lastTokenType, ":", pos );
+                }
+                break;
+                
         } // switch
         prevChar();
 
-        // check attribute
+        // check attribute or extensible attribute
         if ( this.lastTokenType == LdapFilterToken.LPAR )
         {
             StringBuffer sb = new StringBuffer();
 
             // first char must be non-whitespace
             c = nextChar();
-            while ( c != '=' && c != '<' && c != '>' && c !=
'~' && c != '(' && c != ')' && c != '\u0000'
+            while ( c != ':' && c != '=' && c != '<' && c != '>'
&& c != '~' && c != '(' && c != ')' && c != '\u0000'
                 && !Character.isWhitespace( c ) )
             {
                 sb.append( c );
@@ -348,8 +400,17 @@
 
             if ( sb.length() > 0 )
             {
-                this.lastTokenType = LdapFilterToken.ATTRIBUTE;
-                return new LdapFilterToken( this.lastTokenType, sb.toString(), pos - sb.length()
+ 1 );
+                boolean isExtensible = ( c == ':' );
+                if(isExtensible)
+                {
+                    this.lastTokenType = LdapFilterToken.EXTENSIBLE_ATTRIBUTE;
+                    return new LdapFilterToken( this.lastTokenType, sb.toString(), pos -
sb.length() + 1 );
+                }
+                else
+                {
+                    this.lastTokenType = LdapFilterToken.ATTRIBUTE;
+                    return new LdapFilterToken( this.lastTokenType, sb.toString(), pos -
sb.length() + 1 );
+                }
             }
         }
 
@@ -374,6 +435,46 @@
             }
         }
 
+        // check extensible dn
+        if ( lastTokenType == LdapFilterToken.EXTENSIBLE_DNATTR_COLON )
+        {
+            char t1 = nextChar();
+            char t2 = nextChar();
+            char t3 = nextChar();
+            prevChar();
+            if ( ( t1 == 'd' || t1 == 'D' )
+                && ( t2 == 'n' || t2 == 'N' )
+                && ( t3 == ':' || t3 == '\u0000' ) )
+            {
+                this.lastTokenType = LdapFilterToken.EXTENSIBLE_DNATTR;
+                return new LdapFilterToken( this.lastTokenType, ""+t1+t2, pos - 1 );
+            }
+            prevChar();
+            prevChar();
+        }
+        
+        // check extensible matchingrule
+        if ( lastTokenType == LdapFilterToken.EXTENSIBLE_MATCHINGRULEOID_COLON )
+        {
+            StringBuffer sb = new StringBuffer();
+
+            // first char must be non-whitespace
+            c = nextChar();
+            while ( c != ':' && c != '=' && c != '<' && c != '>'
&& c != '~' && c != '(' && c != ')' && c != '\u0000'
+                && !Character.isWhitespace( c ) )
+            {
+                sb.append( c );
+                c = nextChar();
+            }
+            prevChar();
+
+            if ( sb.length() > 0 )
+            {
+                this.lastTokenType = LdapFilterToken.EXTENSIBLE_MATCHINGRULEOID;
+                return new LdapFilterToken( this.lastTokenType, sb.toString(), pos - sb.length()
+ 1 );
+            }
+        }
+        
         // no match
         StringBuffer sb = new StringBuffer();
         c = nextChar();

Modified: directory/studio/trunk/ldapstudio-browser-core/src/main/java/org/apache/directory/ldapstudio/browser/core/model/filter/parser/LdapFilterToken.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/ldapstudio-browser-core/src/main/java/org/apache/directory/ldapstudio/browser/core/model/filter/parser/LdapFilterToken.java?view=diff&rev=545640&r1=545639&r2=545640
==============================================================================
--- directory/studio/trunk/ldapstudio-browser-core/src/main/java/org/apache/directory/ldapstudio/browser/core/model/filter/parser/LdapFilterToken.java
(original)
+++ directory/studio/trunk/ldapstudio-browser-core/src/main/java/org/apache/directory/ldapstudio/browser/core/model/filter/parser/LdapFilterToken.java
Fri Jun  8 14:42:18 2007
@@ -21,52 +21,104 @@
 package org.apache.directory.ldapstudio.browser.core.model.filter.parser;
 
 
+/**
+ * The LdapFilterToken is used to exchange tokens from the scanner to the parser.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
 public class LdapFilterToken implements Comparable
 {
 
+    /** The token identifier for a new filter */
     public static final int NEW = Integer.MIN_VALUE;
 
+    /** The token identifier for an error token */
     public static final int ERROR = -2;
 
+    /** The token identifier for end of file */
     public static final int EOF = -1;
 
+    /** The token identifier for an unknown token */
     public static final int UNKNOWN = 0;
 
+    /** The token identifier for a whitespace */
     public static final int WHITESPACE = 1;
 
+    /** The token identifier for the left parenthesis ( */
     public static final int LPAR = 11;
 
+    /** The token identifier for the right parenthesis ) */
     public static final int RPAR = 12;
 
+    /** The token identifier for the and operator & */
     public static final int AND = 21;
 
+    /** The token identifier for the or operator | */
     public static final int OR = 22;
 
+    /** The token identifier for the not operator ! */
     public static final int NOT = 23;
 
+    /** The token identifier for the attribute = */
     public static final int ATTRIBUTE = 31;
 
+    /** The token identifier for the equal filter type = */
     public static final int EQUAL = 41;
 
+    /** The token identifier for the approx filter type ~= */
     public static final int APROX = 42;
 
+    /** The token identifier for the greater or equal filter type >= */
     public static final int GREATER = 43;
 
+    /** The token identifier for the less or equal filter type <= */
     public static final int LESS = 44;
 
+    /** The token identifier for the present filter type =* */
     public static final int PRESENT = 45;
 
+    /** The token identifier for a value. */
     public static final int VALUE = 51;
 
+    /** The token identifier for the asterisk. */
     public static final int ASTERISK = 52;
 
+    /** The token identifier for the attribute type in extensible filters. */
+    public static final int EXTENSIBLE_ATTRIBUTE = 61;
+
+    /** The token identifier for the colon before the DN flag in extensible filters. */
+    public static final int EXTENSIBLE_DNATTR_COLON = 62;
+
+    /** The token identifier for the DN flag in extensible filters. */
+    public static final int EXTENSIBLE_DNATTR = 63;
+
+    /** The token identifier for the colon before the matching rule OID in extensible filters.
*/
+    public static final int EXTENSIBLE_MATCHINGRULEOID_COLON = 64;
+
+    /** The token identifier for the matching rule OID in extensible filters. */
+    public static final int EXTENSIBLE_MATCHINGRULEOID = 65;
+
+    /** The token identifier for the colon before the equals in extensible filters. */
+    public static final int EXTENSIBLE_EQUALS_COLON = 66;
+
+    /** The offset. */
     private int offset;
 
+    /** The type. */
     private int type;
 
+    /** The value. */
     private String value;
 
 
+    /**
+     * Creates a new instance of LdapFilterToken.
+     * 
+     * @param type the type
+     * @param value the value
+     * @param offset the offset
+     */
     public LdapFilterToken( int type, String value, int offset )
     {
         this.type = type;
@@ -82,7 +134,7 @@
      */
     public int getOffset()
     {
-        return this.offset;
+        return offset;
     }
 
 
@@ -93,28 +145,44 @@
      */
     public int getLength()
     {
-        return this.value.length();
+        return value.length();
     }
 
 
+    /**
+     * Gets the token type.
+     * 
+     * @return the token type
+     */
     public int getType()
     {
-        return this.type;
+        return type;
     }
 
 
+    /**
+     * Gets the value of the token in the original filter.
+     * 
+     * @return the value of the token
+     */
     public String getValue()
     {
-        return this.value;
+        return value;
     }
 
 
+    /**
+     * @see java.lang.Object#toString()
+     */
     public String toString()
     {
-        return "(" + this.offset + ") " + "(" + this.type + ") " + this.value;
+        return "(" + offset + ") " + "(" + type + ") " + value;
     }
 
 
+    /**
+     * @see java.lang.Comparable#compareTo(java.lang.Object)
+     */
     public int compareTo( Object o )
     {
         if ( o instanceof LdapFilterToken )

Added: directory/studio/trunk/ldapstudio-browser-core/src/test/java/org/apache/directory/ldastudio/browser/core/model/LdapFilterParserTest.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/ldapstudio-browser-core/src/test/java/org/apache/directory/ldastudio/browser/core/model/LdapFilterParserTest.java?view=auto&rev=545640
==============================================================================
--- directory/studio/trunk/ldapstudio-browser-core/src/test/java/org/apache/directory/ldastudio/browser/core/model/LdapFilterParserTest.java
(added)
+++ directory/studio/trunk/ldapstudio-browser-core/src/test/java/org/apache/directory/ldastudio/browser/core/model/LdapFilterParserTest.java
Fri Jun  8 14:42:18 2007
@@ -0,0 +1,142 @@
+/*
+ *   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.ldastudio.browser.core.model;
+
+import junit.framework.TestCase;
+
+import org.apache.directory.ldapstudio.browser.core.model.filter.parser.LdapFilterParser;
+
+/**
+ * Test the filter parser
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+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());
+        assertTrue( parser.getModel().isValid() );
+    }
+    
+    /**
+     * Tests an present filter
+     */
+    public void testPresentFilter()
+    {
+        parser.parse( "(cn=*)" );
+        assertEquals( "(cn=*)", parser.getModel().toString());
+        assertTrue( parser.getModel().isValid() );
+    }
+    
+    /**
+     * Tests an extensible filter
+     * 
+     * From RFC4515:
+     * The first example shows use of the matching rule "caseExactMatch."
+     */
+    public void testExtensibleFilterRFC4515_1()
+    {
+        parser.parse( "(cn:caseExactMatch:=Fred Flintstone)" );
+        assertEquals( "(cn:caseExactMatch:=Fred Flintstone)", parser.getModel().toString());
+        assertTrue( parser.getModel().isValid() );
+    }
+    /**
+     * Tests an extensible filter.
+     * 
+     * From RFC4515:
+     * The second example demonstrates use of a MatchingRuleAssertion form
+     * without a matchingRule.
+     */
+    public void testExtensibleFilterRFC4515_2()
+    {
+        parser.parse( "(cn:=Betty Rubble)" );
+        assertEquals( "(cn:=Betty Rubble)", parser.getModel().toString());
+        assertTrue( parser.getModel().isValid() );
+    }
+    /**
+     * Tests an extensible filter.
+     * 
+     * From RFC4515:
+     * The third example illustrates the use of the ":oid" notation to
+     * indicate that the matching rule identified by the OID "2.4.6.8.10"
+     * should be used when making comparisons, and that the attributes of an
+     * entry's distinguished name should be considered part of the entry
+     * when evaluating the match (indicated by the use of ":dn").
+     */
+    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());
+        assertTrue( parser.getModel().isValid() );
+    }
+    /**
+     * Tests an extensible filter.
+     * 
+     * From RFC4515:
+     * The fourth example denotes an equality match, except that DN
+     * components should be considered part of the entry when doing the
+     * match.
+     */
+    public void testExtensibleFilterRFC4515_4()
+    {
+        parser.parse( "(o:dn:=Ace Industry)" );
+        assertEquals( "(o:dn:=Ace Industry)", parser.getModel().toString());
+        assertTrue( parser.getModel().isValid() );
+    }
+    /**
+     * Tests an extensible filter.
+     * 
+     * From RFC4515:
+     * The fifth example is a filter that should be applied to any attribute
+     * supporting the matching rule given (since the <attr> has been
+     * omitted).
+     */
+    public void testExtensibleFilterRFC4515_5()
+    {
+        parser.parse( "(:1.2.3:=Wilma Flintstone)" );
+        assertEquals( "(:1.2.3:=Wilma Flintstone)", parser.getModel().toString());
+        assertTrue( parser.getModel().isValid() );
+    }
+    /**
+     * Tests an extensible filter.
+     * 
+     * From RFC4515:
+     * The sixth and final example is also a filter that should be applied
+     * to any attribute supporting the matching rule given.  Attributes
+     * supporting the matching rule contained in the DN should also be
+     * considered.
+     */
+    public void testExtensibleFilterRFC4515_6()
+    {
+        parser.parse( "(:DN:2.4.6.8.10:=Dino)" );
+        assertEquals( "(:DN:2.4.6.8.10:=Dino)", parser.getModel().toString());
+        assertTrue( parser.getModel().isValid() );
+    }
+
+}

Modified: directory/studio/trunk/ldapstudio-browser-ui/src/main/java/org/apache/directory/ldapstudio/browser/ui/dialogs/properties/SearchPropertyPage.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/ldapstudio-browser-ui/src/main/java/org/apache/directory/ldapstudio/browser/ui/dialogs/properties/SearchPropertyPage.java?view=diff&rev=545640&r1=545639&r2=545640
==============================================================================
--- directory/studio/trunk/ldapstudio-browser-ui/src/main/java/org/apache/directory/ldapstudio/browser/ui/dialogs/properties/SearchPropertyPage.java
(original)
+++ directory/studio/trunk/ldapstudio-browser-ui/src/main/java/org/apache/directory/ldapstudio/browser/ui/dialogs/properties/SearchPropertyPage.java
Fri Jun  8 14:42:18 2007
@@ -30,21 +30,31 @@
 import org.apache.directory.ldapstudio.browser.core.internal.model.Search;
 import org.apache.directory.ldapstudio.browser.core.model.ISearch;
 import org.apache.directory.ldapstudio.browser.core.utils.Utils;
-
 import org.eclipse.swt.widgets.Composite;
 import org.eclipse.swt.widgets.Control;
 import org.eclipse.ui.IWorkbenchPropertyPage;
 import org.eclipse.ui.dialogs.PropertyPage;
 
 
+/**
+ * The SearchPropertyPage implements the property page for an {@link ISearch}.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
 public class SearchPropertyPage extends PropertyPage implements IWorkbenchPropertyPage, WidgetModifyListener
 {
 
+    /** The search. */
     private ISearch search;
 
+    /** The search page wrapper. */
     private SearchPageWrapper spw;
 
 
+    /**
+     * Creates a new instance of SearchPropertyPage.
+     */
     public SearchPropertyPage()
     {
         super();
@@ -52,13 +62,19 @@
     }
 
 
+    /**
+     * @see org.eclipse.jface.dialogs.DialogPage#dispose()
+     */
     public void dispose()
     {
-        this.spw.removeWidgetModifyListener( this );
+        spw.removeWidgetModifyListener( this );
         super.dispose();
     }
 
 
+    /**
+     * @see org.eclipse.jface.preference.PreferencePage#createContents(org.eclipse.swt.widgets.Composite)
+     */
     protected Control createContents( Composite parent )
     {
 
@@ -77,34 +93,43 @@
 
         Composite composite = BaseWidgetUtils.createColumnContainer( parent, 3, 1 );
 
-        this.spw = new SearchPageWrapper( SearchPageWrapper.CONNECTION_READONLY );
-        this.spw.createContents( composite );
-        this.spw.loadFromSearch( this.search );
-        this.spw.addWidgetModifyListener( this );
+        spw = new SearchPageWrapper( SearchPageWrapper.CONNECTION_READONLY );
+        spw.createContents( composite );
+        spw.loadFromSearch( search );
+        spw.addWidgetModifyListener( this );
+
+        widgetModified( new WidgetModifyEvent( this ) );
 
         return composite;
     }
 
 
+    /**
+     * @see org.eclipse.jface.preference.PreferencePage#performOk()
+     */
     public boolean performOk()
     {
-        boolean modified = this.spw.saveToSearch( this.search );
-        if ( modified && this.search.getConnection() != null && this.search.getConnection().isOpened()
)
+        boolean modified = spw.saveToSearch( search );
+        if ( modified && search.getConnection() != null && search.getConnection().isOpened()
)
         {
             // send update event to force saving of new search parameters.
-            EventRegistry.fireSearchUpdated( new SearchUpdateEvent( this.search,
+            EventRegistry.fireSearchUpdated( new SearchUpdateEvent( search,
                 SearchUpdateEvent.EventDetail.SEARCH_PARAMETER_UPDATED ), this );
 
-            return this.spw.performSearch( this.search );
+            return spw.performSearch( search );
         }
 
         return true;
     }
 
 
+    /**
+     * @see org.apache.directory.ldapstudio.browser.common.widgets.WidgetModifyListener#widgetModified(org.apache.directory.ldapstudio.browser.common.widgets.WidgetModifyEvent)
+     */
     public void widgetModified( WidgetModifyEvent event )
     {
-        setValid( this.spw.isValid() );
+        setValid( spw.isValid() );
+        setErrorMessage( spw.getErrorMessage() );
     }
 
 }

Modified: directory/studio/trunk/ldapstudio-browser-ui/src/main/java/org/apache/directory/ldapstudio/browser/ui/search/SearchPage.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/ldapstudio-browser-ui/src/main/java/org/apache/directory/ldapstudio/browser/ui/search/SearchPage.java?view=diff&rev=545640&r1=545639&r2=545640
==============================================================================
--- directory/studio/trunk/ldapstudio-browser-ui/src/main/java/org/apache/directory/ldapstudio/browser/ui/search/SearchPage.java
(original)
+++ directory/studio/trunk/ldapstudio-browser-ui/src/main/java/org/apache/directory/ldapstudio/browser/ui/search/SearchPage.java
Fri Jun  8 14:42:18 2007
@@ -36,6 +36,7 @@
 import org.eclipse.swt.layout.GridData;
 import org.eclipse.swt.layout.GridLayout;
 import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Label;
 import org.eclipse.ui.PlatformUI;
 
 
@@ -58,6 +59,9 @@
     /** The search page wrapper. */
     private SearchPageWrapper spw;
 
+    /** The error message label. */
+    private Label errorMessageLabel;
+
 
     /**
      * Gets the ID of the LDAP search page.
@@ -159,6 +163,8 @@
         spw.loadFromSearch( search );
         spw.addWidgetModifyListener( this );
 
+        errorMessageLabel = BaseWidgetUtils.createLabel( parent, "", 3 );
+
         PlatformUI.getWorkbench().getHelpSystem().setHelp( composite,
             BrowserUIPlugin.PLUGIN_ID + "." + "tools_search_dialog" );
         PlatformUI.getWorkbench().getHelpSystem().setHelp( parent,
@@ -184,6 +190,9 @@
     public void widgetModified( WidgetModifyEvent event )
     {
         container.setPerformActionEnabled( spw.isValid() );
+
+        setErrorMessage( spw.getErrorMessage() );
+        errorMessageLabel.setText( getErrorMessage() != null ? getErrorMessage() : "" );
     }
 
 }

Modified: directory/studio/trunk/ldapstudio-browser-ui/src/main/java/org/apache/directory/ldapstudio/browser/ui/wizards/BatchOperationApplyOnWizardPage.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/ldapstudio-browser-ui/src/main/java/org/apache/directory/ldapstudio/browser/ui/wizards/BatchOperationApplyOnWizardPage.java?view=diff&rev=545640&r1=545639&r2=545640
==============================================================================
--- directory/studio/trunk/ldapstudio-browser-ui/src/main/java/org/apache/directory/ldapstudio/browser/ui/wizards/BatchOperationApplyOnWizardPage.java
(original)
+++ directory/studio/trunk/ldapstudio-browser-ui/src/main/java/org/apache/directory/ldapstudio/browser/ui/wizards/BatchOperationApplyOnWizardPage.java
Fri Jun  8 14:42:18 2007
@@ -88,7 +88,8 @@
 
     private void validate()
     {
-        setPageComplete( getApplyOnDns() != null || this.spw.isValid() );
+        setPageComplete( getApplyOnDns() != null || spw.isValid() );
+        setErrorMessage( searchButton.getSelection() ? spw.getErrorMessage() : null );
     }
 
 

Modified: directory/studio/trunk/ldapstudio-browser-ui/src/main/java/org/apache/directory/ldapstudio/browser/ui/wizards/ExportBaseFromWizardPage.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/ldapstudio-browser-ui/src/main/java/org/apache/directory/ldapstudio/browser/ui/wizards/ExportBaseFromWizardPage.java?view=diff&rev=545640&r1=545639&r2=545640
==============================================================================
--- directory/studio/trunk/ldapstudio-browser-ui/src/main/java/org/apache/directory/ldapstudio/browser/ui/wizards/ExportBaseFromWizardPage.java
(original)
+++ directory/studio/trunk/ldapstudio-browser-ui/src/main/java/org/apache/directory/ldapstudio/browser/ui/wizards/ExportBaseFromWizardPage.java
Fri Jun  8 14:42:18 2007
@@ -80,11 +80,13 @@
 
 
     /**
-     * Validates this page
+     * Validates this page and sets the error message
+     * if this page is not valid.
      */
     protected void validate()
     {
         setPageComplete( spw.isValid() );
+        setErrorMessage( spw.getErrorMessage() );
     }
 
 



Mime
View raw message