info.magnolia.jcr.util
Class PropertyUtil

java.lang.Object
  extended by info.magnolia.jcr.util.PropertyUtil

public class PropertyUtil
extends Object

Property-related utility methods.


Constructor Summary
PropertyUtil()
           
 
Method Summary
static javax.jcr.Value createValue(Object obj, javax.jcr.ValueFactory valueFactory)
           
static javax.jcr.Value createValue(String valueStr, int type, javax.jcr.ValueFactory valueFactory)
          Transforms a string to a jcr value object.
static boolean getBoolean(javax.jcr.Node node, String name, boolean defaultValue)
          Return the boolean representing the node property value.
static Calendar getDate(javax.jcr.Node node, String name)
          Return the Calendar representing the node property value.
static Calendar getDate(javax.jcr.Node node, String name, Calendar defaultValue)
          Return the Calendar representing the node property value.
static String getDateFormat()
           
static int getJCRPropertyType(Object obj)
           
static Long getLong(javax.jcr.Node node, String name)
           
static Long getLong(javax.jcr.Node node, String name, Long defaultValue)
           
static javax.jcr.Property getProperty(javax.jcr.Node node, String relativePath)
          Deprecated. since 4.5 - use getPropertyOrNull instead
static javax.jcr.Property getPropertyOrNull(javax.jcr.Node node, String relativePath)
          Return the Property relative to the Node or null if it's not existing or in case of any RepositoryException.
static Object getPropertyValueObject(javax.jcr.Node node, String relativePath)
          Return the Value Object from a property.
static String getString(javax.jcr.Node node, String name)
          Return the String representing the node property value.
static String getString(javax.jcr.Node node, String name, String defaultValue)
          Return the String representing the node property value.
static Object getValueObject(javax.jcr.Value value)
          Return the Value Object from a Value.
static List<String> getValuesStringList(javax.jcr.Value[] values)
           
static String getValueString(javax.jcr.Property property)
          Returns value of the property converted to string no matter what it's type actually is.
static String getValueString(javax.jcr.Value value)
          Returns value converted to string no matter what it's type actually is.
static javax.jcr.Property renameProperty(javax.jcr.Property property, String newName)
           
static void setProperty(javax.jcr.Node node, String propertyName, Object propertyValue)
          Allows setting a Node's property from an object.
static void updateOrCreate(javax.jcr.Node node, String string, GregorianCalendar gregorianCalendar)
          Updates existing property or creates a new one if it doesn't exist already.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PropertyUtil

public PropertyUtil()
Method Detail

renameProperty

public static javax.jcr.Property renameProperty(javax.jcr.Property property,
                                                String newName)
                                         throws javax.jcr.RepositoryException
Throws:
javax.jcr.RepositoryException

setProperty

public static void setProperty(javax.jcr.Node node,
                               String propertyName,
                               Object propertyValue)
                        throws javax.jcr.RepositoryException
Allows setting a Node's property from an object.

Throws:
javax.jcr.RepositoryException

createValue

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


getJCRPropertyType

public static int getJCRPropertyType(Object obj)
Returns:
JCR-PropertyType corresponding to provided Object.

updateOrCreate

public static void updateOrCreate(javax.jcr.Node node,
                                  String string,
                                  GregorianCalendar gregorianCalendar)
                           throws javax.jcr.RepositoryException
Updates existing property or creates a new one if it doesn't exist already.

Throws:
javax.jcr.RepositoryException

getDateFormat

public static String getDateFormat()

getValuesStringList

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

getValueString

public static String getValueString(javax.jcr.Property property)
Returns value of the property converted to string no matter what it's type actually is. In case of dates, value if formatted according to format returned by getDateFormat(). Binary and reference values are converted to empty string. In case of error during conversion, null will be returned instead. Works only for single value properties.


getValueString

public static String getValueString(javax.jcr.Value value)
Returns value converted to string no matter what it's type actually is. In case of dates, value if formatted according to format returned by getDateFormat(). Binary and reference values are converted to empty string. In case of error during conversion, null will be returned instead.


createValue

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

getDate

public static Calendar getDate(javax.jcr.Node node,
                               String name)
Return the Calendar representing the node property value. If the Node did not contain such a Property, then return null.


getDate

public static Calendar getDate(javax.jcr.Node node,
                               String name,
                               Calendar defaultValue)
Return the Calendar representing the node property value. If the Node did not contain such a Property, then return the default value.


getString

public static String getString(javax.jcr.Node node,
                               String name)
Return the String representing the node property value. If the Node did not contain such a Property or if the Node is null, then return null.


getString

public static String getString(javax.jcr.Node node,
                               String name,
                               String defaultValue)
Return the String representing the node property value. If the Node did not contain such a Property or if the Node is null, then return the default value.


getLong

public static Long getLong(javax.jcr.Node node,
                           String name)

getLong

public static Long getLong(javax.jcr.Node node,
                           String name,
                           Long defaultValue)

getBoolean

public static boolean getBoolean(javax.jcr.Node node,
                                 String name,
                                 boolean defaultValue)
Return the boolean representing the node property value. If the Node did not contain such a Property, then return the default value.


getPropertyOrNull

public static javax.jcr.Property getPropertyOrNull(javax.jcr.Node node,
                                                   String relativePath)
Return the Property relative to the Node or null if it's not existing or in case of any RepositoryException.


getProperty

public static javax.jcr.Property getProperty(javax.jcr.Node node,
                                             String relativePath)
Deprecated. since 4.5 - use getPropertyOrNull instead


getPropertyValueObject

public static Object getPropertyValueObject(javax.jcr.Node node,
                                            String relativePath)
Return the Value Object from a property. Return null in case of exception. The returned Object could be a basic PropertyType type or in case of multivalue, a LinkedList of PropertyType type objects.


getValueObject

public static Object getValueObject(javax.jcr.Value value)
Return the Value Object from a Value. Return null in case of exception.



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