info.magnolia.module.data.util
Class DataUtil

java.lang.Object
  extended by info.magnolia.module.data.util.DataUtil

public class DataUtil
extends Object

Data related utilities.

Version:
$Revision: $ ($Author: $)
Author:
had

Field Summary
static info.magnolia.cms.core.ItemType MULTI_VALUE_ITEM_TYPE
          Multi value node item type.
 
Constructor Summary
DataUtil()
           
 
Method Summary
static info.magnolia.cms.core.Content addMultiValue(info.magnolia.cms.core.Content node, String name, String value)
          Adds multi value type.
static info.magnolia.cms.core.Content addMultiValue(info.magnolia.cms.core.Content node, String name, String valueStr, info.magnolia.cms.core.ItemType itemType)
          Adds multi value type.
static info.magnolia.cms.core.Content addMultiValue(info.magnolia.cms.core.Content node, String name, javax.jcr.Value value, info.magnolia.cms.core.ItemType itemType)
          Adds multi value type.
static info.magnolia.cms.core.Content addMultiValueOnce(info.magnolia.cms.core.Content node, String name, String value)
          Adds multi value type if such doesn't exist yet.
static info.magnolia.cms.core.Content addMultiValueOnce(info.magnolia.cms.core.Content node, String name, String value, info.magnolia.cms.core.ItemType itemType)
          Adds multi value type if such doesn't exist yet.
static String configureDialog(info.magnolia.cms.core.Content type)
          Creating or updating the dialog for editing instances of the type.
static TypeDefinition createTypeDefinition(info.magnolia.cms.core.Content content)
          Create a TypeDefinition object from a content node.
static List<info.magnolia.cms.core.Content> getMultiValueNodes(info.magnolia.cms.core.Content node, String name)
          Gets list of child nodes with given content node name.
static List<Object> getMultiValues(info.magnolia.cms.core.Content node, String name)
          Gets list of values extracted from content nodes with given name for provided parent node.
static boolean hasMultiValue(info.magnolia.cms.core.Content node, String name, Object value)
          Validates whether node with given value already exists.
static void registerNodeType(TypeDefinition type)
          Registers a new node type for the given repository and type.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MULTI_VALUE_ITEM_TYPE

public static final info.magnolia.cms.core.ItemType MULTI_VALUE_ITEM_TYPE
Multi value node item type.

Constructor Detail

DataUtil

public DataUtil()
Method Detail

addMultiValue

public static info.magnolia.cms.core.Content addMultiValue(info.magnolia.cms.core.Content node,
                                                           String name,
                                                           String value)
                                                    throws javax.jcr.RepositoryException
Adds multi value type.

Parameters:
node - Parent node.
name - Name of the value node.
value - Value.
Returns:
Newly created multi value node.
Throws:
javax.jcr.RepositoryException - When node can't be created or saved.

addMultiValue

public static info.magnolia.cms.core.Content addMultiValue(info.magnolia.cms.core.Content node,
                                                           String name,
                                                           String valueStr,
                                                           info.magnolia.cms.core.ItemType itemType)
                                                    throws javax.jcr.RepositoryException
Adds multi value type.

Parameters:
node - Parent node.
name - Name of the value node.
valueStr - Node value formatted as a String.
itemType - Item type of newly created node.
Returns:
Newly created multi value node.
Throws:
javax.jcr.RepositoryException - When node can't be created or saved.
See Also:
MULTI_VALUE_ITEM_TYPE

addMultiValue

public static info.magnolia.cms.core.Content addMultiValue(info.magnolia.cms.core.Content node,
                                                           String name,
                                                           javax.jcr.Value value,
                                                           info.magnolia.cms.core.ItemType itemType)
                                                    throws javax.jcr.RepositoryException
Adds multi value type.

Parameters:
node - Parent node.
name - Name of the value node.
value - Value.
itemType - Item type of newly created node.
Returns:
Newly created multi value node.
Throws:
javax.jcr.RepositoryException - When node can't be created or saved.
See Also:
MULTI_VALUE_ITEM_TYPE

addMultiValueOnce

public static info.magnolia.cms.core.Content addMultiValueOnce(info.magnolia.cms.core.Content node,
                                                               String name,
                                                               String value)
                                                        throws javax.jcr.RepositoryException
Adds multi value type if such doesn't exist yet. If already exists, existing node is returned. IF node exists but with different value, no new node is created and null is returned instead.

Parameters:
node - Parent node.
name - Name of the value node.
value - Value.
Returns:
Existing or newly created multi value node or null when existing node has different value.
Throws:
javax.jcr.RepositoryException - When node can't be created or saved.

addMultiValueOnce

public static info.magnolia.cms.core.Content addMultiValueOnce(info.magnolia.cms.core.Content node,
                                                               String name,
                                                               String value,
                                                               info.magnolia.cms.core.ItemType itemType)
                                                        throws javax.jcr.RepositoryException
Adds multi value type if such doesn't exist yet. If already exists, existing node is returned. IF node exists but with different value, no new node is created and null is returned instead.

Parameters:
node - Parent node.
name - Name of the value node.
value - Value.
itemType - Item type of newly created node.
Returns:
Existing or newly created multi value node or null when existing node has different value.
Throws:
javax.jcr.RepositoryException - When node can't be created or saved.
See Also:
MULTI_VALUE_ITEM_TYPE

hasMultiValue

public static boolean hasMultiValue(info.magnolia.cms.core.Content node,
                                    String name,
                                    Object value)
                             throws javax.jcr.RepositoryException
Validates whether node with given value already exists.

Parameters:
node - Checked node.
name - Child content node name.
value - Expected value.
Returns:
True if provided node has content node with expected value, false otherwise.
Throws:
javax.jcr.RepositoryException - When repository can't be accessed.

getMultiValues

public static List<Object> getMultiValues(info.magnolia.cms.core.Content node,
                                          String name)
                                   throws javax.jcr.RepositoryException
Gets list of values extracted from content nodes with given name for provided parent node.

Parameters:
node - Parent node.
name - Child content node name.
Returns:
List of values under given parent with given content node name.
Throws:
javax.jcr.RepositoryException - When access to repository fails.

getMultiValueNodes

public static List<info.magnolia.cms.core.Content> getMultiValueNodes(info.magnolia.cms.core.Content node,
                                                                      String name)
                                                               throws javax.jcr.RepositoryException
Gets list of child nodes with given content node name.

Parameters:
node - Parent node.
name - Child content node name.
Returns:
List of value nodes under given parent with given content node name.
Throws:
javax.jcr.RepositoryException - When access to repository fails.

configureDialog

public static String configureDialog(info.magnolia.cms.core.Content type)
                              throws javax.jcr.RepositoryException
Creating or updating the dialog for editing instances of the type.

Throws:
javax.jcr.RepositoryException

registerNodeType

public static void registerNodeType(TypeDefinition type)
                             throws javax.jcr.RepositoryException
Registers a new node type for the given repository and type.

Throws:
javax.jcr.RepositoryException - when node type can't be registered. Most often this happens when the node type of given name already exists or when the definition is invalid

createTypeDefinition

public static TypeDefinition createTypeDefinition(info.magnolia.cms.core.Content content)
Create a TypeDefinition object from a content node.

Parameters:
content - the node
Returns:
the definition


Copyright © 2012 Magnolia International Ltd.. All Rights Reserved.