jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ste...@apache.org
Subject svn commit: r1341565 - in /jackrabbit/oak/trunk: oak-it/mk/src/main/java/org/apache/jackrabbit/mk/test/ oak-mk/src/main/java/org/apache/jackrabbit/mk/util/ oak-mk/src/test/java/org/apache/jackrabbit/mk/util/
Date Tue, 22 May 2012 17:21:03 GMT
Author: stefan
Date: Tue May 22 17:21:02 2012
New Revision: 1341565

URL: http://svn.apache.org/viewvc?rev=1341565&view=rev
Log:
OAK-75: specify format and semantics of 'filter' parameter in MicroKernel API (WIP)

Modified:
    jackrabbit/oak/trunk/oak-it/mk/src/main/java/org/apache/jackrabbit/mk/test/MicroKernelIT.java
    jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/util/NameFilter.java
    jackrabbit/oak/trunk/oak-mk/src/test/java/org/apache/jackrabbit/mk/util/NameFilterTest.java

Modified: jackrabbit/oak/trunk/oak-it/mk/src/main/java/org/apache/jackrabbit/mk/test/MicroKernelIT.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-it/mk/src/main/java/org/apache/jackrabbit/mk/test/MicroKernelIT.java?rev=1341565&r1=1341564&r2=1341565&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-it/mk/src/main/java/org/apache/jackrabbit/mk/test/MicroKernelIT.java
(original)
+++ jackrabbit/oak/trunk/oak-it/mk/src/main/java/org/apache/jackrabbit/mk/test/MicroKernelIT.java
Tue May 22 17:21:02 2012
@@ -414,7 +414,7 @@ public class MicroKernelIT extends Abstr
         String head = mk.getHeadRevision();
 
         // verify initial content using filter
-        String filter = "{ properties : [ \"\\\\*ntProp\", \"\\\\-mult\\\\*\" ] } ";
+        String filter = "{ properties : [ \"*ntProp\", \"-mult*\" ] } ";
         JSONObject obj = parseJSONObject(mk.getNodes("/", head, 1, 0, -1, filter));
         assertPropertyExists(obj, "test/intProp");
         assertPropertyNotExists(obj, "test/multiIntProp");

Modified: jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/util/NameFilter.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/util/NameFilter.java?rev=1341565&r1=1341564&r2=1341565&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/util/NameFilter.java
(original)
+++ jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/util/NameFilter.java
Tue May 22 17:21:02 2012
@@ -22,22 +22,23 @@ import java.util.List;
 /**
  * Simple name filter utility class.
  * <ul>
- *     <li>a filter consists of one or more <i>globs</i></li>
- *     <li>a <i>glob</i> prefixed by {@code "\-"} is treated as an exclusion
pattern;
- *     all others are considered inclusion patterns</li>
- *     <li>{@code "\*"} serves as a <i>wild card</i>, i.e. it matches any
substring in the target name</li>
- *     <li>a filter matches a target name if any of the inclusion patterns match but
- *     none of the exclusion patterns</li>
+ * <li>a filter consists of one or more <i>globs</i></li>
+ * <li>a <i>glob</i> prefixed by {@code -} (dash) is treated as an exclusion
pattern;
+ * all others are considered inclusion patterns</li>
+ * <li>{@code *} (asterisk) serves as a <i>wildcard</i>, i.e. it matches
any substring in the target name</li>
+ * <li>a filter matches a target name if any of the inclusion patterns match but
+ * none of the exclusion patterns</li>
  * </ul>
  * Example:
  * <p/>
- * {@code ["foo\*", "\-foo99"]} matches {@code "foo"} and {@code "foo bar"}
+ * {@code ["foo*", "-foo99"]} matches {@code "foo"} and {@code "foo bar"}
  * but not {@code "foo99"}.
  */
 public class NameFilter {
 
-    public static String WILDCARD = "\\*";
-    public static String EXCLUDE_PREFIX = "\\-";
+    public static final char WILDCARD = '*';
+    public static final char EXCLUDE_PREFIX = '-';
+    public static final char ESCAPE = '\\';
 
     // list of ORed inclusion patterns
     private final List<String> inclPatterns = new ArrayList<String>();
@@ -46,8 +47,10 @@ public class NameFilter {
 
     public NameFilter(String[] patterns) {
         for (String pattern : patterns) {
-            if (pattern.startsWith(EXCLUDE_PREFIX)) {
-                exclPatterns.add(pattern.substring(EXCLUDE_PREFIX.length()));
+            if (pattern.isEmpty()) {
+                continue;
+            } else if (pattern.charAt(0) == EXCLUDE_PREFIX) {
+                exclPatterns.add(pattern.substring(1));
             } else {
                 inclPatterns.add(pattern);
             }
@@ -93,15 +96,15 @@ public class NameFilter {
             if (pOff >= pLen) {
                 return sOff >= sLen ? true : false;
             }
-            if (sOff >= sLen && pattern.indexOf(WILDCARD, pOff) != pOff) {
+            if (sOff >= sLen && pattern.charAt(pOff) != WILDCARD) {
                 return false;
             }
 
-            // check for a wildcard '\*' as the next pattern;
+            // check for a WILDCARD as the next pattern;
             // this is handled by a recursive call for
             // each postfix of the name.
-            if (pattern.indexOf(WILDCARD, pOff) == pOff) {
-                pOff += WILDCARD.length();
+            if (pattern.charAt(pOff) == WILDCARD) {
+                ++pOff;
                 if (pOff >= pLen) {
                     return true;
                 }
@@ -118,6 +121,14 @@ public class NameFilter {
             }
 
             if (pOff < pLen && sOff < sLen) {
+                // check for ESCAPE character
+                if (pattern.charAt(pOff) == ESCAPE) {
+                    if (pOff < pLen - 1
+                            && (pattern.charAt(pOff + 1) == WILDCARD
+                                || pattern.charAt(pOff + 1) == EXCLUDE_PREFIX)) {
+                        ++pOff;
+                    }
+                }
                 if (pattern.charAt(pOff) != s.charAt(sOff)) {
                     return false;
                 }

Modified: jackrabbit/oak/trunk/oak-mk/src/test/java/org/apache/jackrabbit/mk/util/NameFilterTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-mk/src/test/java/org/apache/jackrabbit/mk/util/NameFilterTest.java?rev=1341565&r1=1341564&r2=1341565&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-mk/src/test/java/org/apache/jackrabbit/mk/util/NameFilterTest.java
(original)
+++ jackrabbit/oak/trunk/oak-mk/src/test/java/org/apache/jackrabbit/mk/util/NameFilterTest.java
Tue May 22 17:21:02 2012
@@ -28,12 +28,20 @@ public class NameFilterTest {
 
     @Test
     public void test() {
-        NameFilter filter = new NameFilter(new String[]{"foo\\*", "\\-foo99"});
+        NameFilter filter = new NameFilter(new String[]{"foo*", "-foo99"});
         assertTrue(filter.matches("foo1"));
         assertTrue(filter.matches("foo*"));
         assertTrue(filter.matches("foo bar"));
         assertTrue(filter.matches("foo 99"));
         assertFalse(filter.matches("foo99"));
+
+        filter = new NameFilter(new String[]{"*foo"});
+        assertTrue(filter.matches("foo"));
+        assertFalse(filter.matches("bar"));
+
+        filter = new NameFilter(new String[]{"foo\\*bar"});
+        assertFalse(filter.matches("foo bar"));
+        assertTrue(filter.matches("foo*bar"));
     }
 
 }



Mime
View raw message