GitLab Mirror pushed to branch trunk at cms-community / hippo-jackrabbit

Commits:
b1220146 by Julian Reschke at 2018-01-19T08:32:27+00:00
JCR-4001: When using Node.getProperties(String namePattern) also child nodes 
are processed

git-svn-id: https://svn.apache.org/repos/asf/jackrabbit/trunk@1821597 
13f79535-47bb-0310-9956-ffa450edef68

- - - - -


1 changed file:

- 
jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/util/ChildrenCollectorFilter.java


Changes:

=====================================
jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/util/ChildrenCollectorFilter.java
=====================================
--- 
a/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/util/ChildrenCollectorFilter.java
+++ 
b/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/util/ChildrenCollectorFilter.java
@@ -30,6 +30,7 @@ import 
org.apache.jackrabbit.commons.iterator.PropertyIteratorAdapter;
 
 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 extends 
TraversingItemVisitor.Default {
             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 extends 
TraversingItemVisitor.Default {
             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 extends 
TraversingItemVisitor.Default {
 
     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 extends 
TraversingItemVisitor.Default {
     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;
+    }
 }



View it on GitLab: 
https://code.onehippo.org/cms-community/hippo-jackrabbit/commit/b1220146fa5887911540053f39043ff517c2829f

---
View it on GitLab: 
https://code.onehippo.org/cms-community/hippo-jackrabbit/commit/b1220146fa5887911540053f39043ff517c2829f
You're receiving this email because of your account on code.onehippo.org.
_______________________________________________
Hippocms-svn mailing list
Hippocms-svn@lists.onehippo.org
https://lists.onehippo.org/mailman/listinfo/hippocms-svn

Reply via email to