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.


Field Summary
static org.apache.jackrabbit.commons.predicate.Predicate ALL_NODES_EXCEPT_JCR_FILTER
          Deprecated. since 5.0 - obsolete as there's no nodetypes with namespace jcr
static AbstractPredicate<javax.jcr.Property> ALL_PROPERTIES_EXCEPT_JCR_AND_MGNL_FILTER
          Deprecated. since 5.0 - obsolete as there's no nodetypes with namespace jcr. In addition you could use JCRMgnlPropertyHidingPredicate
static AbstractPredicate<javax.jcr.Node> EXCLUDE_META_DATA_FILTER
          Deprecated. since 5.0 - obsolete as there's no nodetypes with namespace jcr and because of MAGNOLIA-4640
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 getNearestAncestorOfType(javax.jcr.Node node, String nodeTypeName)
          Returns the nearest ancestor of a certain node type or null if none of the ancestors have the node type.
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 Collection<javax.jcr.Node> getSortedCollectionFromNodeIterator(javax.jcr.NodeIterator iterator)
           
static boolean hasMixin(javax.jcr.Node node, String mixinName)
          Checks if the node has a mixin assigned.
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 nodeTypeName)
          Checks if the node is of the supplied node type or if the node type is a mixin checks if the node has the mixin.
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 void traceNodeChildren(javax.jcr.Node nodeOp)
          Write the children of the node to the log.
static void traceNodeProperties(javax.jcr.Node nodeOp)
          Write the properties of the node to the log.
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_PROPERTIES_EXCEPT_JCR_AND_MGNL_FILTER

public static AbstractPredicate<javax.jcr.Property> ALL_PROPERTIES_EXCEPT_JCR_AND_MGNL_FILTER
Deprecated. since 5.0 - obsolete as there's no nodetypes with namespace jcr. In addition you could use JCRMgnlPropertyHidingPredicate
Predicate hiding properties prefixed with jcr or mgnl.


ALL_NODES_EXCEPT_JCR_FILTER

public static org.apache.jackrabbit.commons.predicate.Predicate ALL_NODES_EXCEPT_JCR_FILTER
Deprecated. since 5.0 - obsolete as there's no nodetypes with namespace jcr
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
Deprecated. since 5.0 - obsolete as there's no nodetypes with namespace jcr and because of MAGNOLIA-4640
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
Checks if the node has a mixin assigned. This includes only those mixin types explicitly assigned to this node.

Throws:
javax.jcr.RepositoryException
See Also:
Node.getMixinNodeTypes()

isNodeType

public static boolean isNodeType(javax.jcr.Node node,
                                 String nodeTypeName)
                          throws javax.jcr.RepositoryException
Checks if the node is of the supplied node type or if the node type is a mixin checks if the node has the mixin. Also, if the node is frozen checks the node's type prior to being frozen.

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
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:
RuntimeRepositoryException - 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)
Returns:
a valid jcr path combined from the provided path and 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

getNearestAncestorOfType

public static javax.jcr.Node getNearestAncestorOfType(javax.jcr.Node node,
                                                      String nodeTypeName)
                                               throws javax.jcr.RepositoryException
Returns the nearest ancestor of a certain node type or null if none of the ancestors have the node type. The nearest node is the first parent walking from the node and upwards. Works also for mixins and subtypes.

Parameters:
node - the node whose ancestors to consider
nodeTypeName - the node type to query for
Returns:
the nearest ancestor having the node type or null if none exists
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)

getSortedCollectionFromNodeIterator

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

traceNodeProperties

public static void traceNodeProperties(javax.jcr.Node nodeOp)
                                throws javax.jcr.RepositoryException
Write the properties of the node to the log.

Throws:
javax.jcr.RepositoryException

traceNodeChildren

public static void traceNodeChildren(javax.jcr.Node nodeOp)
                              throws javax.jcr.RepositoryException
Write the children of the node to the log.

Throws:
javax.jcr.RepositoryException


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