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/06/11 09:17:43 UTC

svn commit: r1833313 - in /jackrabbit/branches/2.8: ./ jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/util/ChildrenCollectorFilter.java

Author: reschke
Date: Mon Jun 11 09:17:43 2018
New Revision: 1833313

URL: http://svn.apache.org/viewvc?rev=1833313&view=rev
Log:
JCR-4001: When using Node.getProperties(String namePattern) also child nodes are processed (ported to 2.8)

Modified:
    jackrabbit/branches/2.8/   (props changed)
    jackrabbit/branches/2.8/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/util/ChildrenCollectorFilter.java

Propchange: jackrabbit/branches/2.8/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Mon Jun 11 09:17:43 2018
@@ -1,3 +1,3 @@
 /jackrabbit/branches/JCR-2272:1173165-1176545
 /jackrabbit/sandbox/JCR-2415-lucene-3.0:1060860-1064038
-/jackrabbit/trunk:1592881,1597717,1597799,1597806,1598035,1598058,1603769,1603934,1609712,1615997,1625561,1627529,1634584,1653275,1667787,1674859,1680757,1709811,1717599,1729382,1730696,1732436,1740814-1740815,1751279,1752165,1758600,1759607,1759782,1759865,1761679,1761909,1762422,1763558,1766398,1771078,1771741,1771939,1771999,1772049,1772343,1772444,1772457,1772530,1772544,1773579,1773591,1773745,1774443,1775657,1779166,1779460,1780208,1786325,1787043,1787381,1792193,1793315,1793323,1793327,1793332,1796980,1797209,1797917,1798586,1799429,1802977,1807234,1807244,1810108,1811667,1814831,1817097,1822947,1822950,1826230,1826647,1826940,1826964
+/jackrabbit/trunk:1592881,1597717,1597799,1597806,1598035,1598058,1603769,1603934,1609712,1615997,1625561,1627529,1634584,1653275,1667787,1674859,1680757,1709811,1717599,1729382,1730696,1732436,1740814-1740815,1751279,1752165,1758600,1759607,1759782,1759865,1761679,1761909,1762422,1763558,1766398,1771078,1771741,1771939,1771999,1772049,1772343,1772444,1772457,1772530,1772544,1773579,1773591,1773745,1774443,1775657,1779166,1779460,1780208,1786325,1787043,1787381,1792193,1793315,1793323,1793327,1793332,1796980,1797209,1797917,1798586,1799429,1802977,1807234,1807244,1810108,1811667,1814831,1817097,1821597,1822947,1822950,1826230,1826647,1826940,1826964

Modified: jackrabbit/branches/2.8/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/util/ChildrenCollectorFilter.java
URL: http://svn.apache.org/viewvc/jackrabbit/branches/2.8/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/util/ChildrenCollectorFilter.java?rev=1833313&r1=1833312&r2=1833313&view=diff
==============================================================================
--- jackrabbit/branches/2.8/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/util/ChildrenCollectorFilter.java (original)
+++ jackrabbit/branches/2.8/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/util/ChildrenCollectorFilter.java Mon Jun 11 09:17:43 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;
+    }
 }