public class JcrUtils extends Object
Modifier and Type | Field and Description |
---|---|
static int |
ALL_EVENTS |
Constructor and Description |
---|
JcrUtils() |
Modifier and Type | Method and Description |
---|---|
static javax.jcr.Node |
copy(javax.jcr.Node srcNode,
String destNodeName,
javax.jcr.Node destParentNode)
Copies
Node srcNode to destParentNode with name destNodeName . |
static javax.jcr.Node |
copy(javax.jcr.Session session,
String srcAbsPath,
String destAbsPath)
Copies node at
srcAbsPath to destAbsPath as session operation. |
static javax.jcr.Node |
copyTo(javax.jcr.Node srcNode,
CopyHandler chain)
Copies
Node srcNode to destNode with a handler to rewrite content if necessary. |
static void |
copyTo(javax.jcr.Node srcNode,
javax.jcr.Node destNode)
Copies
Node srcNode to destNode . |
static void |
copyToChain(javax.jcr.Node srcNode,
CopyHandler chain) |
static javax.jcr.Value |
createBinaryValueFromObject(javax.jcr.Session session,
Object object)
Serialize the given
object into a binary JCR value. |
static NodeIterable |
emptyNodeIterable() |
static void |
ensureIsCheckedOut(javax.jcr.Node node)
Make sure the node is in checked out state.
|
static javax.jcr.Binary |
getBinaryProperty(javax.jcr.Node baseNode,
String relPath,
javax.jcr.Binary defaultValue)
Returns the binary property value at
relPath from baseNode or defaultValue
if no such property exists. |
static javax.jcr.Binary |
getBinaryProperty(javax.jcr.Session session,
String absPath,
javax.jcr.Binary defaultValue)
Returns the binary property value at
absPath or defaultValue if no such property
exists. |
static Boolean |
getBooleanProperty(javax.jcr.Node baseNode,
String relPath,
Boolean defaultValue)
Returns the boolean property value at
relPath from baseNode or
defaultValue if no such property exists. |
static Boolean |
getBooleanProperty(javax.jcr.Session session,
String absPath,
Boolean defaultValue)
Returns the boolean property value at
absPath or defaultValue if no such property
exists. |
static Calendar |
getDateProperty(javax.jcr.Node baseNode,
String relPath,
Calendar defaultValue)
Returns the date property value at
relPath from baseNode or defaultValue
if no such property exists. |
static Calendar |
getDateProperty(javax.jcr.Session session,
String absPath,
Calendar defaultValue)
Returns the date property value at
absPath or defaultValue if no such property exists. |
static BigDecimal |
getDecimalProperty(javax.jcr.Node baseNode,
String relPath,
BigDecimal defaultValue)
Returns the decimal property value at
relPath from baseNode or
defaultValue if no such property exists. |
static BigDecimal |
getDecimalProperty(javax.jcr.Session session,
String absPath,
BigDecimal defaultValue)
Returns the decimal property value at
absPath or defaultValue if no such property
exists. |
static Double |
getDoubleProperty(javax.jcr.Node baseNode,
String relPath,
Double defaultValue)
Returns the double property value at
relPath from baseNode or defaultValue
if no such property exists. |
static Double |
getDoubleProperty(javax.jcr.Session session,
String absPath,
Double defaultValue)
Returns the double property value at
absPath or defaultValue if no such property
exists. |
static javax.jcr.Node |
getLastNodeIfExists(String absPath,
javax.jcr.Session session)
Gets the node at
absPath or null if no such node exists. |
static Long |
getLongProperty(javax.jcr.Node baseNode,
String relPath,
Long defaultValue)
Returns the long property value at
relPath from baseNode or defaultValue
if no such property exists. |
static Long |
getLongProperty(javax.jcr.Session session,
String absPath,
Long defaultValue)
Returns the long property value at
absPath or defaultValue if no such property exists. |
static javax.jcr.nodetype.NodeType[] |
getMixinNodeTypes(javax.jcr.Node node)
Retrieve the mixin node types present on a node.
|
static String[] |
getMultipleStringProperty(javax.jcr.Node baseNode,
String relPath,
String[] defaultValue)
Returns the multiple string property value at
relPath from baseNode or defaultValue
if no such property exists. |
static javax.jcr.Node |
getNextSiblingIfExists(javax.jcr.Node current)
Returns the next sibling
Node of current . |
static javax.jcr.Node |
getNodeIfExists(javax.jcr.Node baseNode,
String relPath)
Get the node at
relPath from baseNode or null if no such node exists. |
static javax.jcr.Node |
getNodeIfExists(String absPath,
javax.jcr.Session session)
Gets the node at
absPath or null if no such node exists. |
static String |
getNodeNameQuietly(javax.jcr.Node node)
Get the name of a
Node , or null if the node cannot be retrieved. |
static String |
getNodePathQuietly(javax.jcr.Node node)
Get the path of a
Node , or null if the path cannot be retrieved. |
static javax.jcr.Node |
getNodeProperty(javax.jcr.Node baseNode,
String relPath,
javax.jcr.Node defaultValue)
Returns the node property value at
relPath from baseNode or defaultValue
if no such property exists. |
static javax.jcr.Node |
getNodeProperty(javax.jcr.Session session,
String absPath,
javax.jcr.Node defaultValue)
Returns the node property value at
absPath or defaultValue if no such property exists. |
static javax.jcr.nodetype.NodeType |
getPrimaryNodeType(javax.jcr.Node node)
Retrieve the primary node type.
|
static Iterable<javax.jcr.Property> |
getProperties(javax.jcr.Node node)
Calls
Node.getProperties() on the given node and returns
the it as an Iterable instance for use in a Java 5 for-each loop. |
static javax.jcr.Property |
getPropertyIfExists(javax.jcr.Node baseNode,
String relPath)
Get the property at
relPath from baseNode or null if no such property
exists. |
static javax.jcr.Property |
getPropertyIfExists(String absPath,
javax.jcr.Session session)
Gets the property at
absPath or null if no such property exists. |
static String |
getStringProperty(javax.jcr.Node baseNode,
String relPath,
String defaultValue)
Returns the string property value at
relPath from baseNode or defaultValue
if no such property exists. |
static String |
getStringProperty(javax.jcr.Session session,
String absPath,
String defaultValue)
Returns the string property value at
absPath or defaultValue if no such property
exists. |
static boolean |
isPropertyEvent(javax.jcr.observation.Event event) |
static boolean |
isVirtual(javax.jcr.Node node) |
public static final int ALL_EVENTS
public static javax.jcr.Node getNodeIfExists(javax.jcr.Node baseNode, String relPath) throws javax.jcr.RepositoryException
relPath
from baseNode
or null
if no such node exists.baseNode
- existing node that should be the base for the relative pathrelPath
- relative path to the node to getrelPath
from baseNode
or null
if no such node exists.javax.jcr.RepositoryException
- in case of exception accessing the Repositorypublic static javax.jcr.Node getNodeIfExists(String absPath, javax.jcr.Session session) throws javax.jcr.RepositoryException
absPath
or null
if no such node exists.absPath
- the absolute path to the node to returnsession
- to useabsPath
or null
if no such node exists.javax.jcr.RepositoryException
- in case of exception accessing the Repositorypublic static javax.jcr.Node getLastNodeIfExists(String absPath, javax.jcr.Session session) throws javax.jcr.RepositoryException
absPath
or null
if no such node exists. In case there are more nodes
at absPath
, the last node is returned.absPath
- the absolute path to the node to returnsession
- to useabsPath
or null
if no such node exists.javax.jcr.RepositoryException
public static String getStringProperty(javax.jcr.Node baseNode, String relPath, String defaultValue) throws javax.jcr.RepositoryException
relPath
from baseNode
or defaultValue
if no such property exists.baseNode
- existing node that should be the base for the relative pathrelPath
- relative path to the property to getdefaultValue
- default value to return when the property does not existrelPath
from baseNode
or defaultValue
if no such property existsjavax.jcr.RepositoryException
- in case of exception accessing the Repositorypublic static String[] getMultipleStringProperty(javax.jcr.Node baseNode, String relPath, String[] defaultValue) throws javax.jcr.RepositoryException
relPath
from baseNode
or defaultValue
if no such property exists.baseNode
- existing node that should be the base for the relative pathrelPath
- relative path to the property to getdefaultValue
- default value to return when the property does not existrelPath
from baseNode
or defaultValue
if no such property existsjavax.jcr.RepositoryException
- in case of exception accessing the Repositorypublic static Long getLongProperty(javax.jcr.Node baseNode, String relPath, Long defaultValue) throws javax.jcr.RepositoryException
relPath
from baseNode
or defaultValue
if no such property exists.baseNode
- existing node that should be the base for the relative pathrelPath
- relative path to the property to getdefaultValue
- default value to return when the property does not existrelPath
from baseNode
or defaultValue
if no such property existsjavax.jcr.RepositoryException
- in case of exception accessing the Repositorypublic static Double getDoubleProperty(javax.jcr.Node baseNode, String relPath, Double defaultValue) throws javax.jcr.RepositoryException
relPath
from baseNode
or defaultValue
if no such property exists.baseNode
- existing node that should be the base for the relative pathrelPath
- relative path to the property to getdefaultValue
- default value to return when the property does not existrelPath
from baseNode
or defaultValue
if no such property existsjavax.jcr.RepositoryException
- in case of exception accessing the Repositorypublic static Boolean getBooleanProperty(javax.jcr.Node baseNode, String relPath, Boolean defaultValue) throws javax.jcr.RepositoryException
relPath
from baseNode
or
defaultValue
if no such property exists.baseNode
- existing node that should be the base for the relative pathrelPath
- relative path to the property to getdefaultValue
- default value to return when the property does not existrelPath
from baseNode
or
defaultValue
if no such property existsjavax.jcr.RepositoryException
- in case of exception accessing the Repositorypublic static Calendar getDateProperty(javax.jcr.Node baseNode, String relPath, Calendar defaultValue) throws javax.jcr.RepositoryException
relPath
from baseNode
or defaultValue
if no such property exists.baseNode
- existing node that should be the base for the relative pathrelPath
- relative path to the property to getdefaultValue
- default value to return when the property does not existrelPath
from baseNode
or defaultValue
if no such property existsjavax.jcr.RepositoryException
- in case of exception accessing the Repositorypublic static BigDecimal getDecimalProperty(javax.jcr.Node baseNode, String relPath, BigDecimal defaultValue) throws javax.jcr.RepositoryException
relPath
from baseNode
or
defaultValue
if no such property exists.baseNode
- existing node that should be the base for the relative pathrelPath
- relative path to the property to getdefaultValue
- default value to return when the property does not existrelPath
from baseNode
or
defaultValue
if no such property existsjavax.jcr.RepositoryException
- in case of exception accessing the Repositorypublic static javax.jcr.Binary getBinaryProperty(javax.jcr.Node baseNode, String relPath, javax.jcr.Binary defaultValue) throws javax.jcr.RepositoryException
relPath
from baseNode
or defaultValue
if no such property exists.baseNode
- existing node that should be the base for the relative pathrelPath
- relative path to the property to getdefaultValue
- default value to return when the property does not existrelPath
from baseNode
or defaultValue
if no such property existsjavax.jcr.RepositoryException
- in case of exception accessing the Repositorypublic static javax.jcr.Node getNodeProperty(javax.jcr.Node baseNode, String relPath, javax.jcr.Node defaultValue) throws javax.jcr.RepositoryException
relPath
from baseNode
or defaultValue
if no such property exists.baseNode
- existing node that should be the base for the relative pathrelPath
- relative path to the property to getdefaultValue
- default value to return when the property does not existrelPath
from baseNode
or defaultValue
if no such property existsjavax.jcr.RepositoryException
- in case of exception accessing the Repositorypublic static String getStringProperty(javax.jcr.Session session, String absPath, String defaultValue) throws javax.jcr.RepositoryException
absPath
or defaultValue
if no such property
exists.session
- to useabsPath
- absolute path to the property to getdefaultValue
- default value to return when the property does not existabsPath
or defaultValue
if no such property
existsjavax.jcr.RepositoryException
- in case of exception accessing the Repositorypublic static Long getLongProperty(javax.jcr.Session session, String absPath, Long defaultValue) throws javax.jcr.RepositoryException
absPath
or defaultValue
if no such property exists.session
- to useabsPath
- absolute path to the property to getdefaultValue
- default value to return when the property does not existabsPath
or defaultValue
if no such property existsjavax.jcr.RepositoryException
- in case of exception accessing the Repositorypublic static Double getDoubleProperty(javax.jcr.Session session, String absPath, Double defaultValue) throws javax.jcr.RepositoryException
absPath
or defaultValue
if no such property
exists.session
- to useabsPath
- absolute path to the property to getdefaultValue
- default value to return when the property does not existabsPath
or defaultValue
if no such property
existsjavax.jcr.RepositoryException
- in case of exception accessing the Repositorypublic static Boolean getBooleanProperty(javax.jcr.Session session, String absPath, Boolean defaultValue) throws javax.jcr.RepositoryException
absPath
or defaultValue
if no such property
exists.session
- to useabsPath
- absolute path to the property to getdefaultValue
- default value to return when the property does not existabsPath
or defaultValue
if no such property
existsjavax.jcr.RepositoryException
- in case of exception accessing the Repositorypublic static Calendar getDateProperty(javax.jcr.Session session, String absPath, Calendar defaultValue) throws javax.jcr.RepositoryException
absPath
or defaultValue
if no such property exists.session
- to useabsPath
- absolute path to the property to getdefaultValue
- default value to return when the property does not existabsPath
or defaultValue
if no such property existsjavax.jcr.RepositoryException
- in case of exception accessing the Repositorypublic static BigDecimal getDecimalProperty(javax.jcr.Session session, String absPath, BigDecimal defaultValue) throws javax.jcr.RepositoryException
absPath
or defaultValue
if no such property
exists.session
- to useabsPath
- absolute path to the property to getdefaultValue
- default value to return when the property does not existabsPath
or defaultValue
if no such property
existsjavax.jcr.RepositoryException
- in case of exception accessing the Repositorypublic static javax.jcr.Binary getBinaryProperty(javax.jcr.Session session, String absPath, javax.jcr.Binary defaultValue) throws javax.jcr.RepositoryException
absPath
or defaultValue
if no such property
exists.session
- to useabsPath
- absolute path to the property to getdefaultValue
- default value to return when the property does not existabsPath
or defaultValue
if no such property
existsjavax.jcr.RepositoryException
- in case of exception accessing the Repositorypublic static javax.jcr.Node getNodeProperty(javax.jcr.Session session, String absPath, javax.jcr.Node defaultValue) throws javax.jcr.RepositoryException
absPath
or defaultValue
if no such property exists.session
- to useabsPath
- absolute path to the property to getdefaultValue
- default value to return when the property does not existabsPath
or defaultValue
if no such property existsjavax.jcr.RepositoryException
- in case of exception accessing the Repositorypublic static javax.jcr.Property getPropertyIfExists(javax.jcr.Node baseNode, String relPath) throws javax.jcr.RepositoryException
relPath
from baseNode
or null
if no such property
exists.baseNode
- existing node that should be the base for the relative pathrelPath
- relative path to the property to getrelPath
from baseNode
or null
if no such property
exists.javax.jcr.RepositoryException
- in case of exception accessing the Repositorypublic static javax.jcr.Property getPropertyIfExists(String absPath, javax.jcr.Session session) throws javax.jcr.RepositoryException
absPath
or null
if no such property exists.absPath
- the absolute path to the property to returnsession
- to useabsPath
or null
if no such property exists.javax.jcr.RepositoryException
- in case of exception accessing the Repositorypublic static javax.jcr.Node copy(javax.jcr.Session session, String srcAbsPath, String destAbsPath) throws javax.jcr.RepositoryException
srcAbsPath
to destAbsPath
as session operation.session
- to usesrcAbsPath
- the absolute path of the source nodedestAbsPath
- the absolute path of the resulting copyjavax.jcr.RepositoryException
IllegalArgumentException
- if srcNode is same as destParentNode or destParentNode is a descendant of srcNode
or destAbsPath is the root node path.public static javax.jcr.Node copy(javax.jcr.Node srcNode, String destNodeName, javax.jcr.Node destParentNode) throws javax.jcr.RepositoryException
Node
srcNode
to destParentNode
with name destNodeName
.srcNode
- the node to copydestNodeName
- the name of the to be newly created nodedestParentNode
- the parent of the to be newly created nodejavax.jcr.RepositoryException
IllegalArgumentException
- if srcNode is same as destParentNode or destParentNode is a descendant of srcNodepublic static void copyTo(javax.jcr.Node srcNode, javax.jcr.Node destNode) throws javax.jcr.RepositoryException
Node
srcNode
to destNode
.srcNode
- the node to copydestNode
- the node that the contents of srcNode will be copied tojavax.jcr.RepositoryException
IllegalArgumentException
- if scrNode is same as destNode or destNode is a descendant of srcNodepublic static javax.jcr.Node copyTo(javax.jcr.Node srcNode, CopyHandler chain) throws javax.jcr.RepositoryException
Node
srcNode
to destNode
with a handler
to rewrite content if necessary.srcNode
- the node to copychain
- the handler that intercepts node and property creation, can be nulljavax.jcr.RepositoryException
public static void copyToChain(javax.jcr.Node srcNode, CopyHandler chain) throws javax.jcr.RepositoryException
javax.jcr.RepositoryException
public static javax.jcr.nodetype.NodeType getPrimaryNodeType(javax.jcr.Node node) throws javax.jcr.RepositoryException
node
- javax.jcr.RepositoryException
public static javax.jcr.nodetype.NodeType[] getMixinNodeTypes(javax.jcr.Node node) throws javax.jcr.RepositoryException
node
- javax.jcr.RepositoryException
public static javax.jcr.Value createBinaryValueFromObject(javax.jcr.Session session, Object object) throws javax.jcr.RepositoryException
object
into a binary JCR value.session
- to useobject
- to serializejavax.jcr.RepositoryException
public static NodeIterable emptyNodeIterable()
NodeIterable
public static void ensureIsCheckedOut(javax.jcr.Node node) throws javax.jcr.RepositoryException
node
- the node to checkjavax.jcr.RepositoryException
public static boolean isVirtual(javax.jcr.Node node) throws javax.jcr.RepositoryException
node
- the node to checkjavax.jcr.RepositoryException
public static String getNodePathQuietly(javax.jcr.Node node)
Node
, or null
if the path cannot be retrieved.
This method is mainly provided for convenience of usage, so a developer does not have to worry about exception handling in case it is not of interest.
node
- - The Node
to get the path ofNode
, or null
if node
is null or an exception happens.public static String getNodeNameQuietly(javax.jcr.Node node)
Node
, or null
if the node cannot be retrieved.
This method is mainly provided for convenience of usage, so a developer does not have to worry about exception handling in case it is not of interest.
node
- - The Node
to get the name ofNode
, or null
if node
is null or an exception happens.public static Iterable<javax.jcr.Property> getProperties(javax.jcr.Node node) throws javax.jcr.RepositoryException
Node.getProperties()
on the given node and returns
the it as an Iterable
instance for use in a Java 5 for-each loop.node
- nodejavax.jcr.RepositoryException
- if the Node.getProperties()
call failspublic static boolean isPropertyEvent(javax.jcr.observation.Event event)
public static javax.jcr.Node getNextSiblingIfExists(javax.jcr.Node current) throws javax.jcr.RepositoryException
Returns the next sibling Node
of current
. If there is no next sibling it returns null
.
If the parent Node
of current
is not an orderable Node
, an
UnsupportedRepositoryOperationException
will be thrown. Checking whether the parent is orderable can be done easily as follows
Node parent = current.getParent(); parent.getPrimaryNodeType().hasOrderableChildNodes()
If the caller of this method uses this method to reorder nodes, then take into account whether the parent node allows same name siblings or not. If you do not know, use
Node parent = current.getParent(); if (parent.getDefinition().allowsSameNameSiblings()) { Node next = getNextSiblingIfExists(current); parent.orderBefore(current.getName() + "[" + current.getIndex() + "]", next.getName()+ "[" + next.getIndex() + "]"); } else { parent.orderBefore(current.getName(), getNextSiblingIfExists(current).getName()); }
current
- the Node
for which to find the next siblingnull
in case there is no next siblingjavax.jcr.UnsupportedRepositoryOperationException
- if the parent of current
is not orderablejavax.jcr.RepositoryException
- if some repository exception happensCopyright © 2007–2017 Hippo B.V. (http://www.onehippo.com). All rights reserved.