Author: chetanm
Date: Wed Oct 19 15:07:42 2016
New Revision: 1765624
URL: http://svn.apache.org/viewvc?rev=1765624&view=rev
Log:
OAK-1312 - [bundling] Bundle nodes into a document
Support glob pattern of '**' to indicate including all children
Modified:
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/bundlor/Include.java
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/bundlor/IncludeMatcherTest.java
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/bundlor/IncludeTest.java
Modified:
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/bundlor/Include.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/bundlor/Include.java?rev=1765624&r1=1765623&r2=1765624&view=diff
==============================================================================
---
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/bundlor/Include.java
(original)
+++
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/bundlor/Include.java
Wed Oct 19 15:07:42 2016
@@ -26,7 +26,6 @@ import com.google.common.collect.Lists;
import org.apache.jackrabbit.oak.commons.PathUtils;
import static com.google.common.base.Preconditions.checkElementIndex;
-import static org.apache.jackrabbit.oak.commons.PathUtils.concat;
/**
* Include represents a single path pattern which captures the path which
@@ -35,7 +34,7 @@ import static org.apache.jackrabbit.oak.
* <li>* - Match any immediate child</li>
* <li>*\/* - Match child with any name upto 2 levels of depth</li>
* <li>jcr:content - Match immediate child with name jcr:content</li>
- * <li>jcr:content\/*;all - Match jcr:content and all its child</li>
+ * <li>jcr:content\/** - Match jcr:content and all its child</li>
* </ul>
*
* The last path element can specify a directive. Supported directive
@@ -44,6 +43,9 @@ import static org.apache.jackrabbit.oak.
* </ul>
*/
public class Include {
+ private static final String STAR = "*";
+ private static final String STAR_STAR = "**";
+
enum Directive {ALL, NONE}
private final String[] elements;
private final Directive directive;
@@ -60,6 +62,12 @@ public class Include {
directive = Directive.valueOf(e.substring(indexOfColon +
1).toUpperCase());
e = e.substring(0, indexOfColon);
}
+
+ if (STAR_STAR.equals(e)){
+ e = STAR;
+ directive = Directive.ALL;
+ }
+
elementList.add(e);
if (directive != Directive.NONE && i < pathElements.size() - 1){
@@ -100,7 +108,7 @@ public class Include {
public boolean match(String nodeName, int depth) {
checkElementIndex(depth, elements.length);
String e = elements[depth];
- return "*".equals(e) || nodeName.equals(e);
+ return STAR.equals(e) || nodeName.equals(e);
}
public int size() {
Modified:
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/bundlor/IncludeMatcherTest.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/bundlor/IncludeMatcherTest.java?rev=1765624&r1=1765623&r2=1765624&view=diff
==============================================================================
---
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/bundlor/IncludeMatcherTest.java
(original)
+++
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/bundlor/IncludeMatcherTest.java
Wed Oct 19 15:07:42 2016
@@ -41,7 +41,7 @@ public class IncludeMatcherTest {
@Test
public void includeAll() throws Exception{
- Matcher m = new Include("x/*;all").createMatcher();
+ Matcher m = new Include("x/**").createMatcher();
assertTrue(m.isMatch());
assertTrue(m.next("x").isMatch());
Modified:
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/bundlor/IncludeTest.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/bundlor/IncludeTest.java?rev=1765624&r1=1765623&r2=1765624&view=diff
==============================================================================
---
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/bundlor/IncludeTest.java
(original)
+++
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/bundlor/IncludeTest.java
Wed Oct 19 15:07:42 2016
@@ -50,7 +50,7 @@ public class IncludeTest {
Include i0 = new Include("x/*");
assertEquals(Include.Directive.NONE, i0.getDirective());
- Include i = new Include("x/*;all");
+ Include i = new Include("x/**");
assertEquals(Include.Directive.ALL, i.getDirective());
}
@@ -61,12 +61,12 @@ public class IncludeTest {
@Test
public void directiveAll() throws Exception{
- Include i = new Include("x/*;all");
+ Include i = new Include("x/**");
assertTrue(i.match("x/y"));
assertTrue(i.match("x/y/z"));
assertTrue(i.match("x/y/z/x"));
- Include i2 = new Include("x/y;all");
+ Include i2 = new Include("x/y/**");
assertTrue(i2.match("x/y"));
assertTrue(i2.match("x/y/z"));
assertTrue(i2.match("x/y/z/x"));
@@ -82,7 +82,7 @@ public class IncludeTest {
// x/y/z would not match so depth should be 0
assertEquals(0,
i0.createMatcher().next("x").next("y").next("z").depth());
- Include i2 = new Include("x/y;all");
+ Include i2 = new Include("x/y/**");
assertEquals(0, i2.createMatcher().depth());
assertEquals(1, i2.createMatcher().next("x").depth());
assertEquals(2, i2.createMatcher().next("x").next("y").depth());