org.apache.jackrabbit.util
Class ChildrenCollectorFilter

java.lang.Object
  extended by javax.jcr.util.TraversingItemVisitor
      extended by javax.jcr.util.TraversingItemVisitor.Default
          extended by org.apache.jackrabbit.util.ChildrenCollectorFilter
All Implemented Interfaces:
ItemVisitor

public class ChildrenCollectorFilter
extends TraversingItemVisitor.Default

ChildrenCollectorFilter is a utility class which can be used to 'collect' child items of a node whose names match a certain pattern. It implements the ItemVisitor interface.


Nested Class Summary
 
Nested classes/interfaces inherited from class javax.jcr.util.TraversingItemVisitor
TraversingItemVisitor.Default
 
Field Summary
 
Fields inherited from class javax.jcr.util.TraversingItemVisitor
breadthFirst, maxLevel
 
Constructor Summary
ChildrenCollectorFilter(String[] nameGlobs, Collection<Item> children, boolean collectNodes, boolean collectProperties, int maxLevel)
          Constructs a ChildrenCollectorFilter
ChildrenCollectorFilter(String namePattern, Collection<Item> children, boolean collectNodes, boolean collectProperties, int maxLevel)
          Constructs a ChildrenCollectorFilter
 
Method Summary
static NodeIterator collectChildNodes(Node node, String namePattern)
           
static NodeIterator collectChildNodes(Node node, String[] nameGlobs)
           
static PropertyIterator collectProperties(Node node, String namePattern)
           
static PropertyIterator collectProperties(Node node, String[] nameGlobs)
           
protected  void entering(Node node, int level)
          
protected  void entering(Property property, int level)
          
static boolean matches(String name, String pattern)
          Matches the name pattern against the specified name.
static boolean matches(String name, String[] nameGlobs)
          Matches the nameGlob strings in the passed array against the specified name.
 
Methods inherited from class javax.jcr.util.TraversingItemVisitor.Default
leaving, leaving
 
Methods inherited from class javax.jcr.util.TraversingItemVisitor
visit, visit
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ChildrenCollectorFilter

public ChildrenCollectorFilter(String namePattern,
                               Collection<Item> children,
                               boolean collectNodes,
                               boolean collectProperties,
                               int maxLevel)
Constructs a ChildrenCollectorFilter

Parameters:
namePattern - the pattern which should be applied to the names of the children
children - where the matching children should be added
collectNodes - true, if child nodes should be collected; otherwise false
collectProperties - true, if child properties should be collected; otherwise false
maxLevel - number of hierarchy levels to traverse (e.g. 1 for direct children only, 2 for children and their children, and so on)

ChildrenCollectorFilter

public ChildrenCollectorFilter(String[] nameGlobs,
                               Collection<Item> children,
                               boolean collectNodes,
                               boolean collectProperties,
                               int maxLevel)
Constructs a ChildrenCollectorFilter

Parameters:
nameGlobs - an array of globbing strings which should be applied to the names of the children
children - where the matching children should be added
collectNodes - true, if child nodes should be collected; otherwise false
collectProperties - true, if child properties should be collected; otherwise false
maxLevel - number of hierarchy levels to traverse (e.g. 1 for direct children only, 2 for children and their children, and so on)
Method Detail

collectChildNodes

public static NodeIterator collectChildNodes(Node node,
                                             String namePattern)
                                      throws RepositoryException
Throws:
RepositoryException

collectChildNodes

public static NodeIterator collectChildNodes(Node node,
                                             String[] nameGlobs)
                                      throws RepositoryException
Throws:
RepositoryException

collectProperties

public static PropertyIterator collectProperties(Node node,
                                                 String namePattern)
                                          throws RepositoryException
Throws:
RepositoryException

collectProperties

public static PropertyIterator collectProperties(Node node,
                                                 String[] nameGlobs)
                                          throws RepositoryException
Throws:
RepositoryException

entering

protected void entering(Node node,
                        int level)
                 throws RepositoryException

Overrides:
entering in class TraversingItemVisitor.Default
Throws:
RepositoryException

entering

protected void entering(Property property,
                        int level)
                 throws RepositoryException

Overrides:
entering in class TraversingItemVisitor.Default
Throws:
RepositoryException

matches

public static boolean matches(String name,
                              String pattern)
Matches the name pattern against the specified name.

The pattern may be a full name or a partial name with one or more wildcard characters ("*"), or a disjunction (using the "|" character to represent logical OR) of these. For example,

"jcr:*|foo:bar"

would match

"foo:bar", but also "jcr:whatever".

 The EBNF for pattern is:

 namePattern ::= disjunct {'|' disjunct}
 disjunct ::= name [':' name]
 name ::= '*' |
          ['*'] fragment {'*' fragment}['*']
 fragment ::= char {char}
 char ::= nonspace | ' '
 nonspace ::= (* Any Unicode character except:
               '/', ':', '[', ']', '*',
               ''', '"', '|' or any whitespace
               character *)
 
Note that leading and trailing whitespace around a pattern is ignored.

Parameters:
name - the name to test the pattern with
pattern - the pattern to be matched against the name
Returns:
true if the specified name matches the pattern
See Also:
Node.getNodes(String)

matches

public static boolean matches(String name,
                              String[] nameGlobs)
Matches the nameGlob strings in the passed array against the specified name.

A glob may be a full name or a partial name with one or more wildcard characters ("*").

Note that unlike in the case of the matches(String, String) leading and trailing whitespace around a glob is not ignored.

Parameters:
name - the name to test the pattern with
nameGlobs - an array of globbing strings
Returns:
true if the specified name matches any of the globs
See Also:
Node.getNodes(String[])


Copyright © 2004-2010 The Apache Software Foundation. All Rights Reserved.