info.magnolia.cms.util
Class NodeDataUtil

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

public class NodeDataUtil
extends java.lang.Object

Util to work with NodeData.

Version:
$Revision: 48455 $ ($Author: dlipp $)
Author:
Sameer Charles

Constructor Summary
NodeDataUtil()
           
 
Method Summary
static javax.jcr.Value createValue(java.lang.Object obj, javax.jcr.ValueFactory valueFactory)
           
static javax.jcr.Value createValue(java.lang.String valueStr, int type)
          Uses the default value factory.
static javax.jcr.Value createValue(java.lang.String valueStr, int type, javax.jcr.ValueFactory valueFactory)
          Transforms a string to a jcr value object.
static boolean getBoolean(Content node, java.lang.String name, boolean defaultValue)
           
static java.util.Calendar getDate(Content node, java.lang.String name, java.util.Calendar defaultValue)
           
static java.lang.String getDateFormat()
           
static java.lang.String getI18NString(Content node, java.lang.String str)
          Uses the i18n mechanism to translate the message if the resulting string is a key.
static java.lang.String getI18NString(Content node, java.lang.String str, java.lang.String basename)
          Uses the i18n mechanism to translate the message if the resulting string is a key.
static int getJCRPropertyType(java.lang.Object obj)
           
static long getLong(Content node, java.lang.String name, long defaultValue)
           
static NodeData getOrCreate(Content node, java.lang.String name)
          If the NodeData does not exist yet, just create it.
static NodeData getOrCreate(Content node, java.lang.String name, int type)
          If the NodeData does not exist yet, just create it.
static NodeData getOrCreate(Content node, java.lang.String name, java.lang.Object obj)
           
static NodeData getOrCreateAndSet(Content node, java.lang.String name, boolean value)
           
static NodeData getOrCreateAndSet(Content node, java.lang.String name, int value)
           
static NodeData getOrCreateAndSet(Content node, java.lang.String name, long value)
           
static NodeData getOrCreateAndSet(Content node, java.lang.String name, java.lang.Object obj)
           
static NodeData getOrCreateAndSet(Content node, java.lang.String name, javax.jcr.Value[] value)
           
static java.lang.String getString(Content node, java.lang.String name)
          Get the string or the empty string if not existing.
static java.lang.String getString(Content node, java.lang.String name, java.lang.String defaultValue)
          You can define a default value if not found.
static java.lang.String getString(java.lang.String repository, java.lang.String path)
          Simple method to get strings like configuration informations.
static java.lang.String getString(java.lang.String repository, java.lang.String path, java.lang.String defaultValue)
          You can define a default value if not found.
static java.lang.String getTypeName(NodeData nd)
          String representation of the jcr property type.
static java.lang.Object getValueObject(NodeData nd)
          Returns the value as an Object.
static java.util.List<java.lang.String> getValuesStringList(javax.jcr.Value[] values)
           
static java.lang.String getValueString(NodeData nodeData)
          Same as getValueString(nd, dateFormat) but using the users short date format.
static java.lang.String getValueString(NodeData nodeData, java.lang.String dateFormat)
          Returns a String representation of the value.
static java.lang.String getValueString(javax.jcr.Value value, java.lang.String dateFormat)
          Same as value.getString(), but using custom date format.
static java.lang.Object inherit(Content node, java.lang.String name)
          Inherit a value.
static java.lang.Object inherit(Content node, java.lang.String name, java.lang.Object dflt)
          Inherit a value.
static java.lang.String inheritString(Content node, java.lang.String name)
          Inherit a value.
static java.lang.String inheritString(Content node, java.lang.String name, java.lang.String dflt)
          Inherit a value.
static NodeData setValue(NodeData nodeData, java.lang.Object valueObj)
          Calls the correct setValue method based on object type.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

NodeDataUtil

public NodeDataUtil()
Method Detail

getValueString

public static java.lang.String getValueString(NodeData nodeData)
Same as getValueString(nd, dateFormat) but using the users short date format.


getValueString

public static java.lang.String getValueString(NodeData nodeData,
                                              java.lang.String dateFormat)
Returns a String representation of the value. In case of a binary the path including filename and extension is returned

Parameters:
nodeData -
dateFormat - date format to use in the case it is a date
Returns:

getValueString

public static java.lang.String getValueString(javax.jcr.Value value,
                                              java.lang.String dateFormat)
Same as value.getString(), but using custom date format.


inheritString

public static java.lang.String inheritString(Content node,
                                             java.lang.String name)
                                      throws javax.jcr.RepositoryException
Inherit a value. Uses the string value. The "inherit" means that the method will look for the value in the content itself and if not found it will go up in the tree and try to locate value in one of the parents of the content until reaching the root. The first value found while traversing the tree way up is the one that will be returned.

Parameters:
node - Node expected to define or inherit the searched node value.
name - Name of the nodeData.
Throws:
javax.jcr.RepositoryException

inheritString

public static java.lang.String inheritString(Content node,
                                             java.lang.String name,
                                             java.lang.String dflt)
                                      throws javax.jcr.RepositoryException
Inherit a value. You can provide a default value if not found

Throws:
javax.jcr.RepositoryException

inherit

public static java.lang.Object inherit(Content node,
                                       java.lang.String name)
                                throws javax.jcr.RepositoryException
Inherit a value. Uses the string value

Throws:
javax.jcr.RepositoryException

inherit

public static java.lang.Object inherit(Content node,
                                       java.lang.String name,
                                       java.lang.Object dflt)
                                throws javax.jcr.RepositoryException
Inherit a value. You can provide a default value if not found

Throws:
javax.jcr.RepositoryException

getValueObject

public static java.lang.Object getValueObject(NodeData nd)
Returns the value as an Object.

Returns:
Object

setValue

public static NodeData setValue(NodeData nodeData,
                                java.lang.Object valueObj)
                         throws AccessDeniedException,
                                javax.jcr.RepositoryException
Calls the correct setValue method based on object type. If the value is null an empty string is set.

Throws:
AccessDeniedException
javax.jcr.RepositoryException

getTypeName

public static java.lang.String getTypeName(NodeData nd)
String representation of the jcr property type.


getString

public static java.lang.String getString(java.lang.String repository,
                                         java.lang.String path)
Simple method to get strings like configuration informations.


getString

public static java.lang.String getString(Content node,
                                         java.lang.String name)
Get the string or the empty string if not existing.


getString

public static java.lang.String getString(java.lang.String repository,
                                         java.lang.String path,
                                         java.lang.String defaultValue)
You can define a default value if not found.


getString

public static java.lang.String getString(Content node,
                                         java.lang.String name,
                                         java.lang.String defaultValue)
You can define a default value if not found.


getLong

public static long getLong(Content node,
                           java.lang.String name,
                           long defaultValue)

getDate

public static java.util.Calendar getDate(Content node,
                                         java.lang.String name,
                                         java.util.Calendar defaultValue)

getBoolean

public static boolean getBoolean(Content node,
                                 java.lang.String name,
                                 boolean defaultValue)

getOrCreate

public static NodeData getOrCreate(Content node,
                                   java.lang.String name)
                            throws AccessDeniedException,
                                   javax.jcr.RepositoryException
If the NodeData does not exist yet, just create it.

Parameters:
node -
name -
Returns:
the found or created NodeData
Throws:
AccessDeniedException
PathNotFoundException
javax.jcr.RepositoryException

getOrCreate

public static NodeData getOrCreate(Content node,
                                   java.lang.String name,
                                   int type)
                            throws AccessDeniedException,
                                   javax.jcr.RepositoryException
If the NodeData does not exist yet, just create it.

Parameters:
node -
name -
Returns:
the found or created NodeData
Throws:
AccessDeniedException
PathNotFoundException
javax.jcr.RepositoryException

getOrCreate

public static NodeData getOrCreate(Content node,
                                   java.lang.String name,
                                   java.lang.Object obj)
                            throws AccessDeniedException,
                                   javax.jcr.RepositoryException
Throws:
AccessDeniedException
javax.jcr.RepositoryException

getOrCreateAndSet

public static NodeData getOrCreateAndSet(Content node,
                                         java.lang.String name,
                                         java.lang.Object obj)
                                  throws AccessDeniedException,
                                         javax.jcr.RepositoryException
Throws:
AccessDeniedException
javax.jcr.RepositoryException

getOrCreateAndSet

public static NodeData getOrCreateAndSet(Content node,
                                         java.lang.String name,
                                         long value)
                                  throws AccessDeniedException,
                                         javax.jcr.RepositoryException
Throws:
AccessDeniedException
javax.jcr.RepositoryException

getOrCreateAndSet

public static NodeData getOrCreateAndSet(Content node,
                                         java.lang.String name,
                                         javax.jcr.Value[] value)
                                  throws AccessDeniedException,
                                         javax.jcr.RepositoryException
Throws:
AccessDeniedException
javax.jcr.RepositoryException

getOrCreateAndSet

public static NodeData getOrCreateAndSet(Content node,
                                         java.lang.String name,
                                         int value)
                                  throws AccessDeniedException,
                                         javax.jcr.RepositoryException
Throws:
AccessDeniedException
javax.jcr.RepositoryException

getOrCreateAndSet

public static NodeData getOrCreateAndSet(Content node,
                                         java.lang.String name,
                                         boolean value)
                                  throws AccessDeniedException,
                                         javax.jcr.RepositoryException
Throws:
AccessDeniedException
javax.jcr.RepositoryException

getI18NString

public static java.lang.String getI18NString(Content node,
                                             java.lang.String str)
Uses the i18n mechanism to translate the message if the resulting string is a key.


getI18NString

public static java.lang.String getI18NString(Content node,
                                             java.lang.String str,
                                             java.lang.String basename)
Uses the i18n mechanism to translate the message if the resulting string is a key.


createValue

public static javax.jcr.Value createValue(java.lang.String valueStr,
                                          int type)
                                   throws javax.jcr.RepositoryException
Uses the default value factory.

Throws:
javax.jcr.RepositoryException

createValue

public static javax.jcr.Value createValue(java.lang.Object obj,
                                          javax.jcr.ValueFactory valueFactory)
                                   throws javax.jcr.RepositoryException
Throws:
javax.jcr.RepositoryException

createValue

public static javax.jcr.Value createValue(java.lang.String valueStr,
                                          int type,
                                          javax.jcr.ValueFactory valueFactory)
Transforms a string to a jcr value object.


getJCRPropertyType

public static int getJCRPropertyType(java.lang.Object obj)

getValuesStringList

public static java.util.List<java.lang.String> getValuesStringList(javax.jcr.Value[] values)

getDateFormat

public static java.lang.String getDateFormat()


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