info.magnolia.jcr.util
Class NodeUtil

java.lang.Object
  extended by info.magnolia.jcr.util.NodeUtil

public class NodeUtil
extends Object

Various utility methods to collect data from JCR repository.

Version:
$Id$

Field Summary
static org.apache.jackrabbit.commons.predicate.Predicate ALL_NODES_EXCEPT_JCR_FILTER
          Node filter accepting everything except nodes with namespace jcr (version and system store).
static AbstractPredicate<javax.jcr.Node> EXCLUDE_META_DATA_FILTER
          Node filter accepting everything except meta data and jcr types.
static AbstractPredicate<javax.jcr.Node> MAGNOLIA_FILTER
          Node filter accepting all nodes of a type with namespace mgnl.
 
Constructor Summary
NodeUtil()
           
 
Method Summary
static Iterable<javax.jcr.Node> asIterable(javax.jcr.NodeIterator iterator)
           
static List<javax.jcr.Node> asList(Iterable<javax.jcr.Node> nodes)
           
static Iterable<javax.jcr.Node> collectAllChildren(List<javax.jcr.Node> nodes, javax.jcr.Node parent, org.apache.jackrabbit.commons.predicate.Predicate predicate)
          Get all children (by recursion) using a Predicate.
static Iterable<javax.jcr.Node> collectAllChildren(javax.jcr.Node node)
          Get all children (by recursion) using MAGNOLIA_FILTER (filter accepting all nodes of a type with namespace mgnl).
static Iterable<javax.jcr.Node> collectAllChildren(javax.jcr.Node node, org.apache.jackrabbit.commons.predicate.Predicate predicate)
          Get all children (by recursion) using a Predicate.
static String combinePathAndName(String path, String name)
           
static javax.jcr.Node createPath(javax.jcr.Node parent, String relPath, String primaryNodeTypeName)
          Creates a node under the specified parent and relative path, then returns it.
static javax.jcr.Node createPath(javax.jcr.Node parent, String relPath, String primaryNodeTypeName, boolean save)
          Creates a node under the specified parent and relative path, then returns it.
static javax.jcr.Node deepUnwrap(javax.jcr.Node node, Class<? extends DelegateNodeWrapper> wrapper)
          Removes a wrapper by type.
static javax.jcr.Node deepUnwrapAll(javax.jcr.Node node, Class<? extends DelegateNodeWrapper> wrapperClass)
          Removes all wrappers of a given type.
static javax.jcr.NodeIterator filterDuplicates(javax.jcr.NodeIterator iterator)
           
static javax.jcr.NodeIterator filterNodeType(javax.jcr.NodeIterator iterator, String nodeType)
           
static javax.jcr.NodeIterator filterParentNodeType(javax.jcr.NodeIterator iterator, String nodeType)
           
static Collection<javax.jcr.Node> getAncestors(javax.jcr.Node node)
          Get all Ancestors until level 1.
static Collection<javax.jcr.Node> getCollectionFromNodeIterator(javax.jcr.NodeIterator iterator)
           
static String getName(javax.jcr.Node content)
          This method return the node's name on success, otherwise it handles the RepositoryException by throwing a RuntimeRepositoryException.
static javax.jcr.Node getNodeByIdentifier(String workspace, String identifier)
          Get a Node by identifier.
static String getNodeIdentifierIfPossible(javax.jcr.Node content)
          Used for building exception messages where we want to avoid handling another exception inside a throws clause.
static String getNodePathIfPossible(javax.jcr.Node node)
           
static Iterable<javax.jcr.Node> getNodes(javax.jcr.Node parent)
           
static Iterable<javax.jcr.Node> getNodes(javax.jcr.Node parent, org.apache.jackrabbit.commons.predicate.Predicate predicate)
           
static Iterable<javax.jcr.Node> getNodes(javax.jcr.Node parent, String nodeTypeName)
           
static String getPathIfPossible(javax.jcr.Node node)
          Return the Path of the node.
static javax.jcr.Node getSiblingAfter(javax.jcr.Node node)
           
static javax.jcr.Node getSiblingBefore(javax.jcr.Node node)
           
static Iterable<javax.jcr.Node> getSiblings(javax.jcr.Node node)
          Gets the siblings of this node.
static Iterable<javax.jcr.Node> getSiblings(javax.jcr.Node node, org.apache.jackrabbit.commons.predicate.Predicate predicate)
          Gets the siblings of this node according to predicate.
static Iterable<javax.jcr.Node> getSiblings(javax.jcr.Node node, String nodeTypeName)
          Gets the siblings of this node with certain type.
static Iterable<javax.jcr.Node> getSiblingsAfter(javax.jcr.Node node)
          Gets the siblings after this node.
static Iterable<javax.jcr.Node> getSiblingsAfter(javax.jcr.Node node, String nodeTypeName)
          Gets the siblings after this node with certain type.
static Iterable<javax.jcr.Node> getSiblingsBefore(javax.jcr.Node node)
          Gets the siblings before this node.
static Iterable<javax.jcr.Node> getSiblingsBefore(javax.jcr.Node node, String nodeTypeName)
          Gets the siblings before this node with certain type.
static boolean hasMixin(javax.jcr.Node node, String mixinName)
          from default content.
static boolean isFirstSibling(javax.jcr.Node node)
           
static boolean isGranted(javax.jcr.Node node, long permissions)
           
static boolean isLastSibling(javax.jcr.Node node)
           
static boolean isNodeType(javax.jcr.Node node, String type)
          TODO dlipp: better name? Clear javadoc! Move to MetaDataUtil, do not assign method-param! TODO cringele : shouldn't @param nodeType be aligned to JCR API? There it is nodeTypeName, nodeType is used for NodeType object
static boolean isSame(javax.jcr.Node lhs, javax.jcr.Node rhs)
          Returns true if both arguments represents the same node.
static boolean isSameNameSiblings(javax.jcr.Node node1, javax.jcr.Node node2)
          Check if node1 and node2 are siblings.
static boolean isWrappedWith(javax.jcr.Node node, Class<? extends DelegateNodeWrapper> wrapper)
           
static void moveNode(javax.jcr.Node nodeToMove, javax.jcr.Node newParent)
           
static void moveNodeAfter(javax.jcr.Node nodeToMove, javax.jcr.Node target)
           
static void moveNodeBefore(javax.jcr.Node nodeToMove, javax.jcr.Node target)
           
static void orderAfter(javax.jcr.Node node, String siblingName)
          Orders the node directly after a given sibling.
static void orderBefore(javax.jcr.Node node, String siblingName)
          Convenience - delegate to Node.orderBefore(String, String).
static void orderFirst(javax.jcr.Node node)
          Orders the node first among its siblings.
static void orderLast(javax.jcr.Node node)
          Orders the node last among its siblings.
static void orderNodeDown(javax.jcr.Node node)
          Orders the node down one step among its siblings.
static void orderNodeUp(javax.jcr.Node node)
          Orders the node up one step among its siblings.
static void renameNode(javax.jcr.Node node, String newName)
           
static javax.jcr.Node unwrap(javax.jcr.Node node)
           
static void visit(javax.jcr.Node node, NodeVisitor visitor)
          Visits the given node and then all of nodes beneath it except for metadata nodes and nodes of jcr type.
static void visit(javax.jcr.Node node, NodeVisitor visitor, org.apache.jackrabbit.commons.predicate.Predicate predicate)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ALL_NODES_EXCEPT_JCR_FILTER

public static org.apache.jackrabbit.commons.predicate.Predicate ALL_NODES_EXCEPT_JCR_FILTER
Node filter accepting everything except nodes with namespace jcr (version and system store).


EXCLUDE_META_DATA_FILTER

public static AbstractPredicate<javax.jcr.Node> EXCLUDE_META_DATA_FILTER
Node filter accepting everything except meta data and jcr types.


MAGNOLIA_FILTER

public static AbstractPredicate<javax.jcr.Node> MAGNOLIA_FILTER
Node filter accepting all nodes of a type with namespace mgnl.

Constructor Detail

NodeUtil

public NodeUtil()
Method Detail

getNodeByIdentifier

public static javax.jcr.Node getNodeByIdentifier(String workspace,
                                                 String identifier)
                                          throws javax.jcr.RepositoryException
Get a Node by identifier.

Throws:
javax.jcr.RepositoryException

hasMixin

public static boolean hasMixin(javax.jcr.Node node,
                               String mixinName)
                        throws javax.jcr.RepositoryException
from default content.

Throws:
javax.jcr.RepositoryException

isNodeType

public static boolean isNodeType(javax.jcr.Node node,
                                 String type)
                          throws javax.jcr.RepositoryException
TODO dlipp: better name? Clear javadoc! Move to MetaDataUtil, do not assign method-param! TODO cringele : shouldn't @param nodeType be aligned to JCR API? There it is nodeTypeName, nodeType is used for NodeType object

Throws:
javax.jcr.RepositoryException

unwrap

public static javax.jcr.Node unwrap(javax.jcr.Node node)
                             throws javax.jcr.RepositoryException
Throws:
javax.jcr.RepositoryException

deepUnwrap

public static javax.jcr.Node deepUnwrap(javax.jcr.Node node,
                                        Class<? extends DelegateNodeWrapper> wrapper)
Removes a wrapper by type. The wrapper can be deep in a chain of wrappers in which case wrappers before it will be cloned creating a new chain that leads to the same real node.


deepUnwrapAll

public static javax.jcr.Node deepUnwrapAll(javax.jcr.Node node,
                                           Class<? extends DelegateNodeWrapper> wrapperClass)
Removes all wrappers of a given type. Other wrappers are cloned creating a new chain that leads to the same real node.


isWrappedWith

public static boolean isWrappedWith(javax.jcr.Node node,
                                    Class<? extends DelegateNodeWrapper> wrapper)

orderBefore

public static void orderBefore(javax.jcr.Node node,
                               String siblingName)
                        throws javax.jcr.RepositoryException
Convenience - delegate to Node.orderBefore(String, String).

Throws:
javax.jcr.RepositoryException

orderAfter

public static void orderAfter(javax.jcr.Node node,
                              String siblingName)
                       throws javax.jcr.RepositoryException
Orders the node directly after a given sibling. If no sibling is specified the node is placed first.

Throws:
javax.jcr.RepositoryException

orderFirst

public static void orderFirst(javax.jcr.Node node)
                       throws javax.jcr.RepositoryException
Orders the node first among its siblings.

Throws:
javax.jcr.RepositoryException

orderLast

public static void orderLast(javax.jcr.Node node)
                      throws javax.jcr.RepositoryException
Orders the node last among its siblings.

Throws:
javax.jcr.RepositoryException

orderNodeUp

public static void orderNodeUp(javax.jcr.Node node)
                        throws javax.jcr.RepositoryException
Orders the node up one step among its siblings. If the node is the only sibling or the first sibling this method has no effect.

Throws:
javax.jcr.RepositoryException

orderNodeDown

public static void orderNodeDown(javax.jcr.Node node)
                          throws javax.jcr.RepositoryException
Orders the node down one step among its siblings. If the node is the only sibling or the last sibling this method has no effect.

Throws:
javax.jcr.RepositoryException

getSiblingBefore

public static javax.jcr.Node getSiblingBefore(javax.jcr.Node node)
                                       throws javax.jcr.RepositoryException
Throws:
javax.jcr.RepositoryException

getSiblingAfter

public static javax.jcr.Node getSiblingAfter(javax.jcr.Node node)
                                      throws javax.jcr.RepositoryException
Throws:
javax.jcr.RepositoryException

getSiblings

public static Iterable<javax.jcr.Node> getSiblings(javax.jcr.Node node)
                                            throws javax.jcr.RepositoryException
Gets the siblings of this node.

Parameters:
node - node from which will be siblings retrieved
nodeTypeName - requested type of siblings nodes
Returns:
list of siblings of the given Node (only the given node is excluded)
Throws:
javax.jcr.RepositoryException

getSiblings

public static Iterable<javax.jcr.Node> getSiblings(javax.jcr.Node node,
                                                   String nodeTypeName)
                                            throws javax.jcr.RepositoryException
Gets the siblings of this node with certain type.

Parameters:
node - node from which will be siblings retrieved
nodeTypeName - requested type of siblings nodes
Returns:
list of siblings of the given Node (the given node is excluded)
Throws:
javax.jcr.RepositoryException

getSiblings

public static Iterable<javax.jcr.Node> getSiblings(javax.jcr.Node node,
                                                   org.apache.jackrabbit.commons.predicate.Predicate predicate)
                                            throws javax.jcr.RepositoryException
Gets the siblings of this node according to predicate.

Parameters:
node - node from which will be siblings retrieved
predicate - predicate
Returns:
list of siblings of the given Node (the given node is excluded)
Throws:
javax.jcr.RepositoryException

getSiblingsBefore

public static Iterable<javax.jcr.Node> getSiblingsBefore(javax.jcr.Node node)
                                                  throws javax.jcr.RepositoryException
Gets the siblings before this node.

Parameters:
node - node from which will be siblings retrieved
Returns:
list of siblings before the given Node (the given node is excluded)
Throws:
javax.jcr.RepositoryException

getSiblingsAfter

public static Iterable<javax.jcr.Node> getSiblingsAfter(javax.jcr.Node node)
                                                 throws javax.jcr.RepositoryException
Gets the siblings after this node.

Parameters:
node - node from which will be siblings retrieved
Returns:
list of siblings after the given Node (the given node is excluded)
Throws:
javax.jcr.RepositoryException

getSiblingsBefore

public static Iterable<javax.jcr.Node> getSiblingsBefore(javax.jcr.Node node,
                                                         String nodeTypeName)
                                                  throws javax.jcr.RepositoryException
Gets the siblings before this node with certain type.

Parameters:
node - node from which will be siblings retrieved
nodeTypeName - requested type of siblings nodes
Returns:
list of siblings before the given Node (the given node is excluded)
Throws:
javax.jcr.RepositoryException

getSiblingsAfter

public static Iterable<javax.jcr.Node> getSiblingsAfter(javax.jcr.Node node,
                                                        String nodeTypeName)
                                                 throws javax.jcr.RepositoryException
Gets the siblings after this node with certain type.

Parameters:
node - node from which will be siblings retrieved
nodeTypeName - requested type of siblings nodes
Returns:
list of siblings after the given Node (the given node is excluded)
Throws:
javax.jcr.RepositoryException

moveNode

public static void moveNode(javax.jcr.Node nodeToMove,
                            javax.jcr.Node newParent)
                     throws javax.jcr.RepositoryException
Throws:
javax.jcr.RepositoryException

moveNodeBefore

public static void moveNodeBefore(javax.jcr.Node nodeToMove,
                                  javax.jcr.Node target)
                           throws javax.jcr.RepositoryException
Throws:
javax.jcr.RepositoryException

moveNodeAfter

public static void moveNodeAfter(javax.jcr.Node nodeToMove,
                                 javax.jcr.Node target)
                          throws javax.jcr.RepositoryException
Throws:
javax.jcr.RepositoryException

isFirstSibling

public static boolean isFirstSibling(javax.jcr.Node node)
                              throws javax.jcr.RepositoryException
Throws:
javax.jcr.RepositoryException

isSameNameSiblings

public static boolean isSameNameSiblings(javax.jcr.Node node1,
                                         javax.jcr.Node node2)
                                  throws javax.jcr.RepositoryException
Check if node1 and node2 are siblings.

Throws:
javax.jcr.RepositoryException

isLastSibling

public static boolean isLastSibling(javax.jcr.Node node)
                             throws javax.jcr.RepositoryException
Throws:
javax.jcr.RepositoryException

renameNode

public static void renameNode(javax.jcr.Node node,
                              String newName)
                       throws javax.jcr.RepositoryException
Throws:
javax.jcr.RepositoryException

isGranted

public static boolean isGranted(javax.jcr.Node node,
                                long permissions)
Returns:
Whether the provided node as the provided permission or not.
Throws:
RuntimeException - in case of RepositoryException.

isSame

public static boolean isSame(javax.jcr.Node lhs,
                             javax.jcr.Node rhs)
                      throws javax.jcr.RepositoryException
Returns true if both arguments represents the same node. In case the nodes are wrapped the comparison is done one the actual nodes behind the wrappers.

Throws:
javax.jcr.RepositoryException

combinePathAndName

public static String combinePathAndName(String path,
                                        String name)

createPath

public static javax.jcr.Node createPath(javax.jcr.Node parent,
                                        String relPath,
                                        String primaryNodeTypeName)
                                 throws javax.jcr.RepositoryException,
                                        javax.jcr.PathNotFoundException,
                                        AccessDeniedException
Creates a node under the specified parent and relative path, then returns it. Should the node already exist, the method will simply return it.

Throws:
javax.jcr.RepositoryException
javax.jcr.PathNotFoundException
AccessDeniedException

createPath

public static javax.jcr.Node createPath(javax.jcr.Node parent,
                                        String relPath,
                                        String primaryNodeTypeName,
                                        boolean save)
                                 throws javax.jcr.RepositoryException,
                                        javax.jcr.PathNotFoundException,
                                        AccessDeniedException
Creates a node under the specified parent and relative path, then returns it. Should the node already exist, the method will simply return it.

Throws:
javax.jcr.RepositoryException
javax.jcr.PathNotFoundException
AccessDeniedException

visit

public static void visit(javax.jcr.Node node,
                         NodeVisitor visitor)
                  throws javax.jcr.RepositoryException
Visits the given node and then all of nodes beneath it except for metadata nodes and nodes of jcr type.

Throws:
javax.jcr.RepositoryException

visit

public static void visit(javax.jcr.Node node,
                         NodeVisitor visitor,
                         org.apache.jackrabbit.commons.predicate.Predicate predicate)
                  throws javax.jcr.RepositoryException
Throws:
javax.jcr.RepositoryException

getNodes

public static Iterable<javax.jcr.Node> getNodes(javax.jcr.Node parent,
                                                org.apache.jackrabbit.commons.predicate.Predicate predicate)
                                         throws javax.jcr.RepositoryException
Throws:
javax.jcr.RepositoryException

getNodes

public static Iterable<javax.jcr.Node> getNodes(javax.jcr.Node parent)
                                         throws javax.jcr.RepositoryException
Throws:
javax.jcr.RepositoryException

getNodes

public static Iterable<javax.jcr.Node> getNodes(javax.jcr.Node parent,
                                                String nodeTypeName)
                                         throws javax.jcr.RepositoryException
Throws:
javax.jcr.RepositoryException

asIterable

public static Iterable<javax.jcr.Node> asIterable(javax.jcr.NodeIterator iterator)

asList

public static List<javax.jcr.Node> asList(Iterable<javax.jcr.Node> nodes)

getName

public static String getName(javax.jcr.Node content)
This method return the node's name on success, otherwise it handles the RepositoryException by throwing a RuntimeRepositoryException.


collectAllChildren

public static Iterable<javax.jcr.Node> collectAllChildren(javax.jcr.Node node)
                                                   throws javax.jcr.RepositoryException
Get all children (by recursion) using MAGNOLIA_FILTER (filter accepting all nodes of a type with namespace mgnl).

Throws:
javax.jcr.RepositoryException

collectAllChildren

public static Iterable<javax.jcr.Node> collectAllChildren(javax.jcr.Node node,
                                                          org.apache.jackrabbit.commons.predicate.Predicate predicate)
                                                   throws javax.jcr.RepositoryException
Get all children (by recursion) using a Predicate.

Throws:
javax.jcr.RepositoryException

collectAllChildren

public static Iterable<javax.jcr.Node> collectAllChildren(List<javax.jcr.Node> nodes,
                                                          javax.jcr.Node parent,
                                                          org.apache.jackrabbit.commons.predicate.Predicate predicate)
                                                   throws javax.jcr.RepositoryException
Get all children (by recursion) using a Predicate. // TODO this method should really be private or renamed

Throws:
javax.jcr.RepositoryException

getAncestors

public static Collection<javax.jcr.Node> getAncestors(javax.jcr.Node node)
                                               throws javax.jcr.RepositoryException
Get all Ancestors until level 1.

Throws:
javax.jcr.RepositoryException

getNodeIdentifierIfPossible

public static String getNodeIdentifierIfPossible(javax.jcr.Node content)
Used for building exception messages where we want to avoid handling another exception inside a throws clause.


getNodePathIfPossible

public static String getNodePathIfPossible(javax.jcr.Node node)

getPathIfPossible

public static String getPathIfPossible(javax.jcr.Node node)
Return the Path of the node.

Returns:
the path for the node or an empty String in case of exception

filterNodeType

public static javax.jcr.NodeIterator filterNodeType(javax.jcr.NodeIterator iterator,
                                                    String nodeType)

filterDuplicates

public static javax.jcr.NodeIterator filterDuplicates(javax.jcr.NodeIterator iterator)

filterParentNodeType

public static javax.jcr.NodeIterator filterParentNodeType(javax.jcr.NodeIterator iterator,
                                                          String nodeType)
                                                   throws javax.jcr.RepositoryException
Throws:
javax.jcr.RepositoryException

getCollectionFromNodeIterator

public static Collection<javax.jcr.Node> getCollectionFromNodeIterator(javax.jcr.NodeIterator iterator)


Copyright © 2003-2013 Magnolia International Ltd.. All Rights Reserved.