GitLab Mirror pushed to branch 2.14 at cms-community / hippo-jackrabbit
Commits: bf372ca3 by Julian Reschke at 2018-02-09T14:38:05+00:00 JCR-4001: When using Node.getProperties(String namePattern) also child nodes are processed (ported to 2.14) git-svn-id: https://svn.apache.org/repos/asf/jackrabbit/branches/2.14@1823660 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/bf372ca317cdcaba7e6bf4d515b2153f61e92e12 --- View it on GitLab: https://code.onehippo.org/cms-community/hippo-jackrabbit/commit/bf372ca317cdcaba7e6bf4d515b2153f61e92e12 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