info.magnolia.cms.util
Class ContentUtil

java.lang.Object
  extended by info.magnolia.cms.util.ContentUtil

public class ContentUtil
extends java.lang.Object

Some easy to use methods to handle with Content objects.


Nested Class Summary
static interface ContentUtil.PostVisitor
          Used in ContentUtil.Visitor.visit(Content) if the visitor wants to use post order.
static interface ContentUtil.Visitor
          Used in ContentUtil.Visitor.visit(Content) to visit the hierarchy.
 
Field Summary
static Content.ContentFilter ALL_NODES_CONTENT_FILTER
          Content filter accepting everything.
static Content.ContentFilter ALL_NODES_EXCEPT_JCR_CONTENT_FILTER
          Content filter accepting everything exept nodes with namespace jcr (version and system store).
static Content.ContentFilter EXCLUDE_META_DATA_CONTENT_FILTER
          Content filter accepting everything except meta data and jcr types.
static Content.ContentFilter MAGNOLIA_FILTER
          Content filter accepting all nodes with a nodetype of namespace mgnl.
 
Constructor Summary
ContentUtil()
           
 
Method Summary
static void changeNodeType(Content node, ItemType newType, boolean replaceAll)
          Utility method to change the jcr:primaryType value of a node.
static java.util.List<Content> collectAllChildren(Content node)
          Get all children recursively (content and contentnode).
static java.util.List<Content> collectAllChildren(Content node, Content.ContentFilter filter)
          Get all children using a filter.
static java.util.List<Content> collectAllChildren(Content node, ItemType type)
          Get all children of a particular type.
static java.util.List<Content> collectAllChildren(Content node, ItemType[] types)
          Get all children of a particular type.
static void copyInSession(Content src, java.lang.String dest)
          Session based copy operation.
static Content createPath(Content parent, java.lang.String path, ItemType type)
           
static Content createPath(Content parent, java.lang.String path, ItemType type, boolean save)
           
static Content createPath(HierarchyManager hm, java.lang.String path)
           
static Content createPath(HierarchyManager hm, java.lang.String path, boolean save)
           
static Content createPath(HierarchyManager hm, java.lang.String path, ItemType type)
           
static Content createPath(HierarchyManager hm, java.lang.String path, ItemType type, boolean save)
           
static void deleteAndRemoveEmptyParents(Content node)
           
static void deleteAndRemoveEmptyParents(Content node, int level)
           
static java.util.Collection<Content> getAllChildren(Content node)
          Returns all children (not recursively) independent of there type.
static java.util.Collection<Content> getAllChildren(Content node, java.util.Comparator<Content> comp)
          Returns all children (not recursively) independent of there type.
static Content getAncestorOfType(Content firstNode, java.lang.String nodeType)
          Returns the first found ancestor of the given node which is of the given type, or the given node itself, it is of the given type.
static Content getCaseInsensitive(Content node, java.lang.String name)
          Get a subnode case insensitive.
static Content getContent(Content node, java.lang.String name)
          Get the node or null if not exists.
static Content getContent(java.lang.String repository, java.lang.String path)
          Returns a Content object of the named repository or null if not existing.
static Content getContentByUUID(java.lang.String repository, java.lang.String uuid)
           
static Content getOrCreateContent(Content node, java.lang.String name, ItemType contentType)
          If the node doesn't exist just create it.
static Content getOrCreateContent(Content node, java.lang.String name, ItemType contentType, boolean save)
          If the node doesn't exist just create it.
static void moveInSession(Content src, java.lang.String dest)
          Magnolia uses by default workspace move operation to move nodes.
static void orderAfter(Content nodeToMove, java.lang.String targetNodeName)
          Convenient method for ordering a node after a specific target node.
static void orderBefore(Content nodeToMove, java.lang.String targetNodeName)
          Convenient method to order a node before a target node.
static void orderNodes(Content node, java.util.Comparator<Content> comparator)
          Uses the passed comparator to create the jcr ordering of the children.
static void orderNodes(Content node, java.lang.String[] nodes)
           
static java.lang.String path2uuid(java.lang.String repository, java.lang.String path)
           
static void rename(Content node, java.lang.String newName)
           
static java.lang.String uuid2path(java.lang.String repository, java.lang.String uuid)
           
static void visit(Content node, ContentUtil.Visitor visitor)
           
static void visit(Content node, ContentUtil.Visitor visitor, Content.ContentFilter filter)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ALL_NODES_CONTENT_FILTER

public static Content.ContentFilter ALL_NODES_CONTENT_FILTER
Content filter accepting everything.


ALL_NODES_EXCEPT_JCR_CONTENT_FILTER

public static Content.ContentFilter ALL_NODES_EXCEPT_JCR_CONTENT_FILTER
Content filter accepting everything exept nodes with namespace jcr (version and system store).


EXCLUDE_META_DATA_CONTENT_FILTER

public static Content.ContentFilter EXCLUDE_META_DATA_CONTENT_FILTER
Content filter accepting everything except meta data and jcr types.


MAGNOLIA_FILTER

public static Content.ContentFilter MAGNOLIA_FILTER
Content filter accepting all nodes with a nodetype of namespace mgnl.

Constructor Detail

ContentUtil

public ContentUtil()
Method Detail

getContent

public static Content getContent(java.lang.String repository,
                                 java.lang.String path)
Returns a Content object of the named repository or null if not existing.

Returns:
null if not found

getContentByUUID

public static Content getContentByUUID(java.lang.String repository,
                                       java.lang.String uuid)
Returns:
null if not found

getContent

public static Content getContent(Content node,
                                 java.lang.String name)
Get the node or null if not exists.

Parameters:
node -
name -
Returns:
the sub node

getOrCreateContent

public static Content getOrCreateContent(Content node,
                                         java.lang.String name,
                                         ItemType contentType)
                                  throws AccessDeniedException,
                                         javax.jcr.RepositoryException
If the node doesn't exist just create it. Attention the method does not save the newly created node.

Throws:
AccessDeniedException
javax.jcr.RepositoryException

getOrCreateContent

public static Content getOrCreateContent(Content node,
                                         java.lang.String name,
                                         ItemType contentType,
                                         boolean save)
                                  throws AccessDeniedException,
                                         javax.jcr.RepositoryException
If the node doesn't exist just create it. If the parameter save is true the parent node is saved.

Throws:
AccessDeniedException
javax.jcr.RepositoryException

getCaseInsensitive

public static Content getCaseInsensitive(Content node,
                                         java.lang.String name)
Get a subnode case insensitive.

Parameters:
node -
name -
Returns:

collectAllChildren

public static java.util.List<Content> collectAllChildren(Content node)
Get all children recursively (content and contentnode).


collectAllChildren

public static java.util.List<Content> collectAllChildren(Content node,
                                                         Content.ContentFilter filter)
Get all children using a filter.

Parameters:
node -
filter -
Returns:
list of all found nodes

collectAllChildren

public static java.util.List<Content> collectAllChildren(Content node,
                                                         ItemType type)
Get all children of a particular type.


getAllChildren

public static java.util.Collection<Content> getAllChildren(Content node)
Returns all children (not recursively) independent of there type.


getAllChildren

public static java.util.Collection<Content> getAllChildren(Content node,
                                                           java.util.Comparator<Content> comp)
Returns all children (not recursively) independent of there type.


collectAllChildren

public static java.util.List<Content> collectAllChildren(Content node,
                                                         ItemType[] types)
Get all children of a particular type.


getAncestorOfType

public static Content getAncestorOfType(Content firstNode,
                                        java.lang.String nodeType)
                                 throws javax.jcr.RepositoryException
Returns the first found ancestor of the given node which is of the given type, or the given node itself, it is of the given type.

Throws:
javax.jcr.RepositoryException

orderBefore

public static void orderBefore(Content nodeToMove,
                               java.lang.String targetNodeName)
                        throws javax.jcr.RepositoryException
Convenient method to order a node before a target node.

Throws:
javax.jcr.RepositoryException

orderAfter

public static void orderAfter(Content nodeToMove,
                              java.lang.String targetNodeName)
                       throws javax.jcr.RepositoryException
Convenient method for ordering a node after a specific target node. This is not that simple as jcr only supports ordering before a node.

Throws:
javax.jcr.RepositoryException

orderNodes

public static void orderNodes(Content node,
                              java.lang.String[] nodes)
                       throws javax.jcr.RepositoryException
Throws:
javax.jcr.RepositoryException

orderNodes

public static void orderNodes(Content node,
                              java.util.Comparator<Content> comparator)
                       throws javax.jcr.RepositoryException
Uses the passed comparator to create the jcr ordering of the children.

Throws:
javax.jcr.RepositoryException

visit

public static void visit(Content node,
                         ContentUtil.Visitor visitor)
                  throws java.lang.Exception
Throws:
java.lang.Exception

visit

public static void visit(Content node,
                         ContentUtil.Visitor visitor,
                         Content.ContentFilter filter)
                  throws java.lang.Exception
Throws:
java.lang.Exception

createPath

public static Content createPath(HierarchyManager hm,
                                 java.lang.String path)
                          throws AccessDeniedException,
                                 javax.jcr.PathNotFoundException,
                                 javax.jcr.RepositoryException
Throws:
AccessDeniedException
javax.jcr.PathNotFoundException
javax.jcr.RepositoryException

createPath

public static Content createPath(HierarchyManager hm,
                                 java.lang.String path,
                                 boolean save)
                          throws AccessDeniedException,
                                 javax.jcr.PathNotFoundException,
                                 javax.jcr.RepositoryException
Throws:
AccessDeniedException
javax.jcr.PathNotFoundException
javax.jcr.RepositoryException

createPath

public static Content createPath(HierarchyManager hm,
                                 java.lang.String path,
                                 ItemType type)
                          throws AccessDeniedException,
                                 javax.jcr.PathNotFoundException,
                                 javax.jcr.RepositoryException
Throws:
AccessDeniedException
javax.jcr.PathNotFoundException
javax.jcr.RepositoryException

createPath

public static Content createPath(HierarchyManager hm,
                                 java.lang.String path,
                                 ItemType type,
                                 boolean save)
                          throws AccessDeniedException,
                                 javax.jcr.PathNotFoundException,
                                 javax.jcr.RepositoryException
Throws:
AccessDeniedException
javax.jcr.PathNotFoundException
javax.jcr.RepositoryException

createPath

public static Content createPath(Content parent,
                                 java.lang.String path,
                                 ItemType type)
                          throws javax.jcr.RepositoryException,
                                 javax.jcr.PathNotFoundException,
                                 AccessDeniedException
Throws:
javax.jcr.RepositoryException
javax.jcr.PathNotFoundException
AccessDeniedException

createPath

public static Content createPath(Content parent,
                                 java.lang.String path,
                                 ItemType type,
                                 boolean save)
                          throws javax.jcr.RepositoryException,
                                 javax.jcr.PathNotFoundException,
                                 AccessDeniedException
Throws:
javax.jcr.RepositoryException
javax.jcr.PathNotFoundException
AccessDeniedException

uuid2path

public static java.lang.String uuid2path(java.lang.String repository,
                                         java.lang.String uuid)

path2uuid

public static java.lang.String path2uuid(java.lang.String repository,
                                         java.lang.String path)

deleteAndRemoveEmptyParents

public static void deleteAndRemoveEmptyParents(Content node)
                                        throws javax.jcr.PathNotFoundException,
                                               javax.jcr.RepositoryException,
                                               AccessDeniedException
Throws:
javax.jcr.PathNotFoundException
javax.jcr.RepositoryException
AccessDeniedException

deleteAndRemoveEmptyParents

public static void deleteAndRemoveEmptyParents(Content node,
                                               int level)
                                        throws javax.jcr.PathNotFoundException,
                                               javax.jcr.RepositoryException,
                                               AccessDeniedException
Throws:
javax.jcr.PathNotFoundException
javax.jcr.RepositoryException
AccessDeniedException

copyInSession

public static void copyInSession(Content src,
                                 java.lang.String dest)
                          throws javax.jcr.RepositoryException
Session based copy operation. As JCR only supports workspace based copies this operation is performed by using export import operations.

Throws:
javax.jcr.RepositoryException

moveInSession

public static void moveInSession(Content src,
                                 java.lang.String dest)
                          throws javax.jcr.RepositoryException
Magnolia uses by default workspace move operation to move nodes. This is a util method to move a node inside a session.

Throws:
javax.jcr.RepositoryException

rename

public static void rename(Content node,
                          java.lang.String newName)
                   throws javax.jcr.RepositoryException
Throws:
javax.jcr.RepositoryException

changeNodeType

public static void changeNodeType(Content node,
                                  ItemType newType,
                                  boolean replaceAll)
                           throws javax.jcr.RepositoryException
Utility method to change the jcr:primaryType value of a node.

Parameters:
node - - Content the node whose type has to be changed
newType - - ItemType the new node type to be assigned
replaceAll - - boolean when true replaces all occurrences of the old node type. When false replaces only the first occurrence.
Throws:
javax.jcr.RepositoryException


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