info.magnolia.cms.util
Class ContentUtil

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

public class ContentUtil
extends 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 List<Content> collectAllChildren(Content node)
          Get all children recursively (content and contentnode).
static List<Content> collectAllChildren(Content node, Content.ContentFilter filter)
          Get all children using a filter.
static List<Content> collectAllChildren(Content node, ItemType type)
          Get all children of a particular type.
static List<Content> collectAllChildren(Content node, ItemType[] types)
          Get all children of a particular type.
static void copyInSession(Content src, String dest)
          Session based copy operation.
static Content createPath(Content parent, String path, ItemType type)
           
static Content createPath(Content parent, String path, ItemType type, boolean save)
           
static Content createPath(HierarchyManager hm, String path)
           
static Content createPath(HierarchyManager hm, String path, boolean save)
           
static Content createPath(HierarchyManager hm, String path, ItemType type)
           
static Content createPath(HierarchyManager hm, String path, ItemType type, boolean save)
           
static void deleteAndRemoveEmptyParents(Content node)
           
static void deleteAndRemoveEmptyParents(Content node, int level)
           
static Collection<Content> getAllChildren(Content node)
          Returns all children (not recursively) independent of there type.
static Collection<Content> getAllChildren(Content node, Comparator<Content> comp)
          Returns all children (not recursively) independent of there type.
static Content getCaseInsensitive(Content node, String name)
          Get a subnode case insensitive.
static Content getContent(Content node, String name)
          Get the node or null if not exists.
static Content getContent(String repository, String path)
          Returns a Content object of the named repository or null if not existing.
static Content getContentByUUID(String repository, String uuid)
           
static Content getOrCreateContent(Content node, String name, ItemType contentType)
          If the node doesn't exist just create it.
static Content getOrCreateContent(Content node, String name, ItemType contentType, boolean save)
          If the node doesn't exist just create it.
static void moveInSession(Content src, String dest)
          Magnolia uses by default workspace move operation to move nodes.
static void orderAfter(Content nodeToMove, String targetNodeName)
          Convenient method for ordering a node after a specific target node.
static void orderBefore(Content nodeToMove, String targetNodeName)
          Convenient method to order a node before a target node.
static void orderNodes(Content node, Comparator<Content> comparator)
          Uses the passed comparator to create the jcr ordering of the children.
static void orderNodes(Content node, String[] nodes)
           
static String path2uuid(String repository, String path)
           
static void rename(Content node, String newName)
           
static String uuid2path(String repository, 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(String repository,
                                 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(String repository,
                                       String uuid)
Returns:
null if not found

getContent

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

Parameters:
node -
name -
Returns:
the sub node

getOrCreateContent

public static Content getOrCreateContent(Content node,
                                         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,
                                         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,
                                         String name)
Get a subnode case insensitive.

Parameters:
node -
name -
Returns:

collectAllChildren

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


collectAllChildren

public static 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 List<Content> collectAllChildren(Content node,
                                               ItemType type)
Get all children of a particular type.


getAllChildren

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


getAllChildren

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


collectAllChildren

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


orderBefore

public static void orderBefore(Content nodeToMove,
                               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,
                              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,
                              String[] nodes)
                       throws javax.jcr.RepositoryException
Throws:
javax.jcr.RepositoryException

orderNodes

public static void orderNodes(Content node,
                              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 Exception
Throws:
Exception

visit

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

createPath

public static Content createPath(HierarchyManager hm,
                                 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,
                                 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,
                                 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,
                                 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,
                                 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,
                                 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 String uuid2path(String repository,
                               String uuid)

path2uuid

public static String path2uuid(String repository,
                               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,
                                 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,
                                 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,
                          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.