Package nl.gx.webmanager.foundation
Class JcrUtil
- java.lang.Object
-
- nl.gx.webmanager.foundation.JcrUtil
-
public final class JcrUtil extends Object
This class provides a number of utility methods for JCR node operations. These can be especially useful for implementors of CMS item classes (such as PanelBase, MediaItemBase and ElementBase), and for implementors of domain classes for WCB's.- Author:
- martijnh
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static javax.jcr.Node
create(javax.jcr.Node parent, String childName, String childType)
Creates a child node with the specified name and type.static Boolean
getBoolean(javax.jcr.Node node, String property)
Returns the string representation of a property of a node.static boolean[]
getBooleans(javax.jcr.Node node, String property)
static javax.jcr.Node
getByUUID(String uuid)
Finds a node by the given UUID.static Calendar
getCalendar(javax.jcr.Node node, String property)
Returns the calendar representation of a property of a node.static Calendar[]
getCalendars(javax.jcr.Node node, String property)
Returns the calendar representation of a property of a node.static Double
getDouble(javax.jcr.Node node, String property)
Returns the string representation of a property of a node.static double[]
getDoubles(javax.jcr.Node node, String property)
static Long
getLong(javax.jcr.Node node, String property)
Returns the string representation of a property of a node.static long[]
getLongs(javax.jcr.Node node, String property)
static javax.jcr.Node
getNode(javax.jcr.Node parent, String childName)
Gets a child node with the specified name of the given parent node.static javax.jcr.Node
getOrCreate(javax.jcr.Node parent, String childName, String childType)
Gets a childnode with the specified name or creates a child node with the specified name and type in case the parent node doesn't have a child with the given name yet.static javax.jcr.Node
getReferencedNode(javax.jcr.Node parent, String referencePropName)
Gets a referenced node.static javax.jcr.Node[]
getReferencedNodes(javax.jcr.Node parent, String referencePropName)
Gets referenced nodes.static InputStream
getStream(javax.jcr.Node node, String property)
Returns the string representation of a property of a node.static InputStream[]
getStreams(javax.jcr.Node node, String property)
Returns the inputstream representation of a property of a node.static String
getString(javax.jcr.Node node, String property)
Returns the string representation of a property of a node.static String[]
getStrings(javax.jcr.Node node, String property)
Returns the string representation of a property of a node.static String
getUUID(javax.jcr.Node node)
Gets the UUID of a Node.static boolean
hasNode(javax.jcr.Node parent, String childName)
Checks whether a given node has a childnode with the specified name.static void
makeExportable(javax.jcr.Node node, String exportName)
Makes the specified node exportable, i.e., it adds the mixin types wm:exportable and mix:referenceable.static void
makeReferenceable(javax.jcr.Node node)
Makes the specified node referenceable.static void
removeProperty(javax.jcr.Node node, String propName)
Removes a property.static void
setBoolean(javax.jcr.Node node, String property, boolean value)
Sets a string value for a node.static void
setBooleans(javax.jcr.Node node, String property, boolean[] values)
static void
setCalendar(javax.jcr.Node node, String property, Calendar value)
Sets a string value for a node.static void
setCalendars(javax.jcr.Node node, String property, Calendar[] values)
static void
setDouble(javax.jcr.Node node, String property, double value)
Sets a string value for a node.static void
setDoubles(javax.jcr.Node node, String property, double[] values)
static void
setFile(javax.jcr.Node node, org.springframework.web.multipart.MultipartFile multiPartFile, boolean isPublic, String serverName)
Sets a file property for a nodestatic void
setLong(javax.jcr.Node node, String property, long value)
Sets a string value for a node.static void
setLongs(javax.jcr.Node node, String property, long[] values)
static void
setReferencedNode(javax.jcr.Node parent, String referencePropName, String targetUUID)
Creates a reference to a node.static void
setReferencedNode(javax.jcr.Node parent, String referencePropName, javax.jcr.Node targetNode)
Creates a reference to a node.static void
setReferencedNodes(javax.jcr.Node parent, String referencePropName, String[] targetUUIDs)
Creates references to nodes.static void
setReferencedNodes(javax.jcr.Node parent, String referencePropName, javax.jcr.Node[] targetNodes)
Creates references to nodes.static void
setStream(javax.jcr.Node node, String property, InputStream value)
Sets a string value for a node.static void
setStreams(javax.jcr.Node node, String property, InputStream[] values)
static void
setString(javax.jcr.Node node, String property, String value)
Sets a string value for a node.static void
setStrings(javax.jcr.Node node, String property, String[] values)
Sets the value of a property.
-
-
-
Method Detail
-
hasNode
public static boolean hasNode(javax.jcr.Node parent, String childName)
Checks whether a given node has a childnode with the specified name.- Parameters:
parent
- the parent nodechildName
- the name of the child node- Returns:
- true iff node parent has a child node with the given name
-
getNode
public static javax.jcr.Node getNode(javax.jcr.Node parent, String childName)
Gets a child node with the specified name of the given parent node.- Parameters:
parent
- the parent nodechildName
- the name of the childnode- Returns:
- a child node with the specified name, or null if such a node doesn't exist
-
create
public static javax.jcr.Node create(javax.jcr.Node parent, String childName, String childType)
Creates a child node with the specified name and type.- Parameters:
parent
- the parent nodechildName
- the name of the child nodechildType
- the type of the child node (null gives nt:unstructured node)- Returns:
- the created child node
-
getOrCreate
public static javax.jcr.Node getOrCreate(javax.jcr.Node parent, String childName, String childType)
Gets a childnode with the specified name or creates a child node with the specified name and type in case the parent node doesn't have a child with the given name yet.- Parameters:
parent
- the parent nodechildName
- the name of the child nodechildType
- the type of the child node (if it is created; null gives nt:unstructured node)- Returns:
- the child node
-
makeExportable
public static void makeExportable(javax.jcr.Node node, String exportName)
Makes the specified node exportable, i.e., it adds the mixin types wm:exportable and mix:referenceable.- Parameters:
node
- the node that should be exportableexportName
- the exportname of the node
-
makeReferenceable
public static void makeReferenceable(javax.jcr.Node node)
Makes the specified node referenceable. I.e., it gets a UUID.- Parameters:
node
- the node that should be referenceable
-
getUUID
public static String getUUID(javax.jcr.Node node)
Gets the UUID of a Node.- Parameters:
node
- the Node of which to get the UUID- Returns:
- the UUID string, or null if the node is not referenceable
-
getByUUID
public static javax.jcr.Node getByUUID(String uuid)
Finds a node by the given UUID.- Parameters:
uuid
- the UUID of the Node to find- Returns:
- a Node with the given UUID, or null if it does not exist
-
removeProperty
public static void removeProperty(javax.jcr.Node node, String propName)
Removes a property.- Parameters:
node
- the Node for which to remove a propertypropName
- the name of the property to remove
-
getStrings
public static String[] getStrings(javax.jcr.Node node, String property)
Returns the string representation of a property of a node.- Parameters:
node
- The node for which the value should be returned.property
- The name of the property for which the value should be returned.- Returns:
- The string representation of the property, or
null
if the value is not available.
-
getString
public static String getString(javax.jcr.Node node, String property)
Returns the string representation of a property of a node.- Parameters:
node
- The node for which the string value should be returned.property
- The name of the property for which the string value should be returned.- Returns:
- The string representation of the property, or
null
if the value is not available.
-
setStrings
public static void setStrings(javax.jcr.Node node, String property, String[] values)
Sets the value of a property.- Parameters:
node
- The node for which the given property should be set.property
- The name of the property to set.values
- The new values for the property.
-
setString
public static void setString(javax.jcr.Node node, String property, String value)
Sets a string value for a node.- Parameters:
node
- The node that should be updated.property
- The name of the property that should be setvalue
- The new value for the property. If the value argument isnull
, an existing property will be removed.
-
getCalendars
public static Calendar[] getCalendars(javax.jcr.Node node, String property)
Returns the calendar representation of a property of a node.- Parameters:
node
- The node for which the value should be returned.property
- The name of the property for which the value should be returned.- Returns:
- The calendar representation of the property, or
null
if the value is not available.
-
getCalendar
public static Calendar getCalendar(javax.jcr.Node node, String property)
Returns the calendar representation of a property of a node.- Parameters:
node
- The node for which the value should be returned.property
- The name of the property for which the value should be returned.- Returns:
- The calendar representation of the property, or
null
if the value is not available.
-
setCalendars
public static void setCalendars(javax.jcr.Node node, String property, Calendar[] values)
-
setCalendar
public static void setCalendar(javax.jcr.Node node, String property, Calendar value)
Sets a string value for a node.- Parameters:
node
- The node that should be updated.property
- The name of the property that should be setvalue
- The new value for the property. If the value argument isnull
, an existing property will be removed.
-
getStreams
public static InputStream[] getStreams(javax.jcr.Node node, String property)
Returns the inputstream representation of a property of a node.- Parameters:
node
- The node for which the value should be returned.property
- The name of the property for which the value should be returned.- Returns:
- The inputstream representation of the property, or
null
if the value is not available.
-
getStream
public static InputStream getStream(javax.jcr.Node node, String property)
Returns the string representation of a property of a node.- Parameters:
node
- The node for which the string value should be returned.property
- The name of the property for which the string value should be returned.- Returns:
- The string representation of the property, or
null
if the value is available.
-
setStreams
public static void setStreams(javax.jcr.Node node, String property, InputStream[] values)
-
setStream
public static void setStream(javax.jcr.Node node, String property, InputStream value)
Sets a string value for a node.- Parameters:
node
- The node that should be updated.property
- The name of the property that should be setvalue
- The new value for the property. If the value argument isnull
, an existing property will be removed.
-
getLongs
public static long[] getLongs(javax.jcr.Node node, String property)
-
getLong
public static Long getLong(javax.jcr.Node node, String property)
Returns the string representation of a property of a node.- Parameters:
node
- The node for which the string value should be returned.property
- The name of the property for which the string value should be returned.- Returns:
- The Long representation of the property, or
null
if the value is available.
-
setLongs
public static void setLongs(javax.jcr.Node node, String property, long[] values)
-
setLong
public static void setLong(javax.jcr.Node node, String property, long value)
Sets a string value for a node.- Parameters:
node
- The node that should be updated.property
- The name of the property that should be setvalue
- The new value for the property. If the value argument isnull
, an existing property will be removed.
-
getDoubles
public static double[] getDoubles(javax.jcr.Node node, String property)
-
getDouble
public static Double getDouble(javax.jcr.Node node, String property)
Returns the string representation of a property of a node.- Parameters:
node
- The node for which the string value should be returned.property
- The name of the property for which the string value should be returned.- Returns:
- The Double representation of the property, or
null
if the value is available.
-
setDoubles
public static void setDoubles(javax.jcr.Node node, String property, double[] values)
-
setDouble
public static void setDouble(javax.jcr.Node node, String property, double value)
Sets a string value for a node.- Parameters:
node
- The node that should be updated.property
- The name of the property that should be setvalue
- The new value for the property. If the value argument isnull
, an existing property will be removed.
-
getBooleans
public static boolean[] getBooleans(javax.jcr.Node node, String property)
-
getBoolean
public static Boolean getBoolean(javax.jcr.Node node, String property)
Returns the string representation of a property of a node.- Parameters:
node
- The node for which the string value should be returned.property
- The name of the property for which the string value should be returned.- Returns:
- The Boolean representation of the property, or
null
if the value is not available.
-
setBooleans
public static void setBooleans(javax.jcr.Node node, String property, boolean[] values)
-
setBoolean
public static void setBoolean(javax.jcr.Node node, String property, boolean value)
Sets a string value for a node.- Parameters:
node
- The node that should be updated.property
- The name of the property that should be setvalue
- The new value for the property. If the value argument isnull
, an existing property will be removed.
-
setFile
public static void setFile(javax.jcr.Node node, org.springframework.web.multipart.MultipartFile multiPartFile, boolean isPublic, String serverName)
Sets a file property for a node- Parameters:
node
- The node to which the file content should be writtenmultiPartFile
- The multipartfile from which the file content should be writtenisPublic
- Indicates if the file must be public or not. Public files will be copied to the webserver automatically and can thus be served by a webserver and are accessible by all users. Non-public files are accessible only from the application server by an editor that is logged in into WebManager.serverName
- The servername to which the file was uploaded. The servername determines the URL with which the file can be retrieved and the directory to which the file is copied.
-
getReferencedNode
public static javax.jcr.Node getReferencedNode(javax.jcr.Node parent, String referencePropName)
Gets a referenced node.- Parameters:
parent
- the node with the reference propertyreferencePropName
- the name of the reference property- Returns:
- the referenced node, or null if the reference property does not exist
-
setReferencedNode
public static void setReferencedNode(javax.jcr.Node parent, String referencePropName, javax.jcr.Node targetNode)
Creates a reference to a node.- Parameters:
parent
- the node with the reference propertyreferencePropName
- the name of the reference propertytargetNode
- the node that must be referenced, or null to delete the reference
-
setReferencedNode
public static void setReferencedNode(javax.jcr.Node parent, String referencePropName, String targetUUID)
Creates a reference to a node.- Parameters:
parent
- the node with the reference propertyreferencePropName
- the name of the reference propertytargetUUID
- the UUID of the node that must be referenced, or null to delete the reference
-
getReferencedNodes
public static javax.jcr.Node[] getReferencedNodes(javax.jcr.Node parent, String referencePropName)
Gets referenced nodes.- Parameters:
parent
- the node with the references propertyreferencePropName
- the name of the references property- Returns:
- the referenced nodes, or null if the references property does not exist
-
setReferencedNodes
public static void setReferencedNodes(javax.jcr.Node parent, String referencePropName, javax.jcr.Node[] targetNodes)
Creates references to nodes.- Parameters:
parent
- the node with the references propertyreferencePropName
- the name of the references propertytargetNodes
- the nodes that must be referenced, or null to delete the references
-
setReferencedNodes
public static void setReferencedNodes(javax.jcr.Node parent, String referencePropName, String[] targetUUIDs)
Creates references to nodes.- Parameters:
parent
- the node with the references propertyreferencePropName
- the name of the references propertytargetUUIDs
- the UUIDs of nodes that must be referenced, or null to delete the references
-
-