You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jackrabbit.apache.org by re...@apache.org on 2018/02/09 14:38:05 UTC
svn commit: r1823660 - in /jackrabbit/branches/2.14: ./
jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/util/ChildrenCollectorFilter.java
Author: reschke
Date: Fri Feb 9 14:38:05 2018
New Revision: 1823660
URL: http://svn.apache.org/viewvc?rev=1823660&view=rev
Log:
JCR-4001: When using Node.getProperties(String namePattern) also child nodes are processed (ported to 2.14)
Modified:
jackrabbit/branches/2.14/ (props changed)
jackrabbit/branches/2.14/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/util/ChildrenCollectorFilter.java
Propchange: jackrabbit/branches/2.14/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Fri Feb 9 14:38:05 2018
@@ -1,3 +1,3 @@
/jackrabbit/branches/JCR-2272:1173165-1176545
/jackrabbit/sandbox/JCR-2415-lucene-3.0:1060860-1064038
-/jackrabbit/trunk:1776907,1776911-1776912,1776914,1776918,1779166,1779460,1779614,1779632,1780208,1780220,1780406,1785225,1786325,1786330,1787043,1787381,1792100,1792105,1792113,1792193,1793315,1793323,1793327,1793332,1793339,1796980,1797209,1797917,1798586,1799429,1799538,1799549,1799575,1800359,1800378,1800752,1802925,1802977,1807234,1807244,1808752,1808754,1809149,1809329,1809624,1810108,1811667,1812543,1812634,1814831,1817097,1820119
+/jackrabbit/trunk:1776907,1776911-1776912,1776914,1776918,1779166,1779460,1779614,1779632,1780208,1780220,1780406,1785225,1786325,1786330,1787043,1787381,1792100,1792105,1792113,1792193,1793315,1793323,1793327,1793332,1793339,1796980,1797209,1797917,1798586,1799429,1799538,1799549,1799575,1800359,1800378,1800752,1802925,1802977,1807234,1807244,1808752,1808754,1809149,1809329,1809624,1810108,1811667,1812543,1812634,1814831,1817097,1820119,1821597
Modified: jackrabbit/branches/2.14/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/util/ChildrenCollectorFilter.java
URL: http://svn.apache.org/viewvc/jackrabbit/branches/2.14/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/util/ChildrenCollectorFilter.java?rev=1823660&r1=1823659&r2=1823660&view=diff
==============================================================================
--- jackrabbit/branches/2.14/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/util/ChildrenCollectorFilter.java (original)
+++ jackrabbit/branches/2.14/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/util/ChildrenCollectorFilter.java Fri Feb 9 14:38:05 2018
@@ -30,6 +30,7 @@ import org.apache.jackrabbit.commons.ite
import java.util.ArrayList;
import java.util.Collection;
+import java.util.Collections;
/**
* <code>ChildrenCollectorFilter</code> is a utility class
@@ -64,7 +65,7 @@ public class ChildrenCollectorFilter ext
boolean collectNodes, boolean collectProperties, int maxLevel) {
super(false, maxLevel);
this.namePattern = namePattern;
- nameGlobs = null;
+ this.nameGlobs = null;
this.children = children;
this.collectNodes = collectNodes;
this.collectProperties = collectProperties;
@@ -86,7 +87,7 @@ public class ChildrenCollectorFilter ext
boolean collectNodes, boolean collectProperties, int maxLevel) {
super(false, maxLevel);
this.nameGlobs = nameGlobs;
- namePattern = null;
+ this.namePattern = null;
this.children = children;
this.collectNodes = collectNodes;
this.collectProperties = collectProperties;
@@ -110,17 +111,26 @@ public class ChildrenCollectorFilter ext
public static PropertyIterator collectProperties(
Node node, String namePattern) throws RepositoryException {
- Collection<Item> properties = new ArrayList<Item>();
- node.accept(new ChildrenCollectorFilter(
- namePattern, properties, false, true, 1));
+ Collection<Item> properties = Collections.emptySet();
+ PropertyIterator pit = node.getProperties();
+ while (pit.hasNext()) {
+ Property p = pit.nextProperty();
+ if (matches(p.getName(), namePattern)) {
+ properties = addToCollection(properties, p);
+ }
+ }
return new PropertyIteratorAdapter(properties);
}
- public static PropertyIterator collectProperties(
- Node node, String[] nameGlobs) throws RepositoryException {
- Collection<Item> properties = new ArrayList<Item>();
- node.accept(new ChildrenCollectorFilter(
- nameGlobs, properties, false, true, 1));
+ public static PropertyIterator collectProperties(Node node, String[] nameGlobs) throws RepositoryException {
+ Collection<Item> properties = Collections.emptySet();
+ PropertyIterator pit = node.getProperties();
+ while (pit.hasNext()) {
+ Property p = pit.nextProperty();
+ if (matches(p.getName(), nameGlobs)) {
+ properties = addToCollection(properties, p);
+ }
+ }
return new PropertyIteratorAdapter(properties);
}
@@ -179,4 +189,18 @@ public class ChildrenCollectorFilter ext
public static boolean matches(String name, String[] nameGlobs) {
return ItemNameMatcher.matches(name, nameGlobs);
}
+
+ private static Collection<Item> addToCollection(Collection<Item> c, Item p) {
+ Collection<Item> nc = c;
+ if (c.isEmpty()) {
+ nc = Collections.singleton(p);
+ } else if (c.size() == 1) {
+ nc = new ArrayList<Item>(c);
+ nc.add(p);
+ } else {
+ nc.add(p);
+ }
+
+ return nc;
+ }
}