Class JcrUtils
- java.lang.Object
-
- org.hippoecm.repository.util.JcrUtils
-
public class JcrUtils extends Object
Some utility methods for writing code against JCR API. This code can be removed when we upgrade to JR 2.6...
-
-
Field Summary
Fields Modifier and Type Field Description static int
ALL_EVENTS
-
Constructor Summary
Constructors Constructor Description JcrUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static javax.jcr.Node
copy(javax.jcr.Node srcNode, String destNodeName, javax.jcr.Node destParentNode)
CopiesNode
srcNode
todestParentNode
with namedestNodeName
.static javax.jcr.Node
copy(javax.jcr.Session session, String srcAbsPath, String destAbsPath)
Copies node atsrcAbsPath
todestAbsPath
as session operation.static void
copyTo(javax.jcr.Node srcNode, javax.jcr.Node destNode)
CopiesNode
srcNode
todestNode
.static javax.jcr.Node
copyTo(javax.jcr.Node srcNode, CopyHandler chain)
CopiesNode
srcNode
todestNode
with ahandler
to rewrite content if necessary.static void
copyToChain(javax.jcr.Node srcNode, CopyHandler chain)
static javax.jcr.Value
createBinaryValueFromObject(javax.jcr.Session session, Object object)
Serialize the givenobject
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 atrelPath
frombaseNode
ordefaultValue
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 atabsPath
ordefaultValue
if no such property exists.static Boolean
getBooleanProperty(javax.jcr.Node baseNode, String relPath, Boolean defaultValue)
Returns the boolean property value atrelPath
frombaseNode
ordefaultValue
if no such property exists.static Boolean
getBooleanProperty(javax.jcr.Session session, String absPath, Boolean defaultValue)
Returns the boolean property value atabsPath
ordefaultValue
if no such property exists.static Calendar
getDateProperty(javax.jcr.Node baseNode, String relPath, Calendar defaultValue)
Returns the date property value atrelPath
frombaseNode
ordefaultValue
if no such property exists.static Calendar
getDateProperty(javax.jcr.Session session, String absPath, Calendar defaultValue)
Returns the date property value atabsPath
ordefaultValue
if no such property exists.static BigDecimal
getDecimalProperty(javax.jcr.Node baseNode, String relPath, BigDecimal defaultValue)
Returns the decimal property value atrelPath
frombaseNode
ordefaultValue
if no such property exists.static BigDecimal
getDecimalProperty(javax.jcr.Session session, String absPath, BigDecimal defaultValue)
Returns the decimal property value atabsPath
ordefaultValue
if no such property exists.static List<javax.jcr.Node>
getDescendants(javax.jcr.Node source, String nodeType, boolean prune)
Returns the list of jcr nodes which are descendants ofsource
and of typenodeType
, wheresource
is never included in the result.static String
getDisplayNameQuietly(javax.jcr.Node node)
Get the display name of aNode
, ornull
if the node cannot be retrieved.static Double
getDoubleProperty(javax.jcr.Node baseNode, String relPath, Double defaultValue)
Returns the double property value atrelPath
frombaseNode
ordefaultValue
if no such property exists.static Double
getDoubleProperty(javax.jcr.Session session, String absPath, Double defaultValue)
Returns the double property value atabsPath
ordefaultValue
if no such property exists.static <E extends Enum<E>>
EgetEnumProperty(javax.jcr.Node baseNode, String relPath, E defaultValue)
Returns the enum value of a string property atrelPath
frombaseNode
ordefaultValue
if no such property exists.static javax.jcr.Node
getLastNodeIfExists(String absPath, javax.jcr.Session session)
Gets the node atabsPath
ornull
if no such node exists.static Long
getLongProperty(javax.jcr.Node baseNode, String relPath, Long defaultValue)
Returns the long property value atrelPath
frombaseNode
ordefaultValue
if no such property exists.static Long
getLongProperty(javax.jcr.Session session, String absPath, Long defaultValue)
Returns the long property value atabsPath
ordefaultValue
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 values atrelPath
frombaseNode
ordefaultValue
if no such property exists.static javax.jcr.Node
getNextSiblingIfExists(javax.jcr.Node current)
Returns the next siblingNode
ofcurrent
.static javax.jcr.Node
getNodeIfExists(String absPath, javax.jcr.Session session)
Gets the node atabsPath
ornull
if no such node exists.static javax.jcr.Node
getNodeIfExists(javax.jcr.Node baseNode, String relPath)
Get the node atrelPath
frombaseNode
ornull
if no such node exists.static String
getNodeNameQuietly(javax.jcr.Node node)
Get the name of aNode
, ornull
if the node cannot be retrieved.static String
getNodePathQuietly(javax.jcr.Node node)
Get the path of aNode
, ornull
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 atrelPath
frombaseNode
ordefaultValue
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 atabsPath
ordefaultValue
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)
CallsNode.getProperties()
on the given node and returns the it as anIterable
instance for use in a Java 5 for-each loop.static javax.jcr.Property
getPropertyIfExists(String absPath, javax.jcr.Session session)
Gets the property atabsPath
ornull
if no such property exists.static javax.jcr.Property
getPropertyIfExists(javax.jcr.Node baseNode, String relPath)
Get the property atrelPath
frombaseNode
ornull
if no such property exists.static List<String>
getStringListProperty(javax.jcr.Node baseNode, String relPath, List<String> defaultValue)
Returns the multiple string property values atrelPath
frombaseNode
ordefaultValue
if no such property exists.static String
getStringProperty(javax.jcr.Node baseNode, String relPath, String defaultValue)
Returns the string property value atrelPath
frombaseNode
ordefaultValue
if no such property exists.static String
getStringProperty(javax.jcr.Session session, String absPath, String defaultValue)
Returns the string property value atabsPath
ordefaultValue
if no such property exists.static Set<String>
getStringSetProperty(javax.jcr.Node baseNode, String relPath, Set<String> defaultValue)
Returns the unique and unordered multiple string property values atrelPath
frombaseNode
ordefaultValue
if no such property exists.static boolean
isAncestor(javax.jcr.Node ancestor, javax.jcr.Node descendant)
static boolean
isPropertyEvent(javax.jcr.observation.Event event)
static boolean
isVirtual(javax.jcr.Node node)
-
-
-
Field Detail
-
ALL_EVENTS
public static final int ALL_EVENTS
- See Also:
- Constant Field Values
-
-
Method Detail
-
getNodeIfExists
public static javax.jcr.Node getNodeIfExists(javax.jcr.Node baseNode, String relPath) throws javax.jcr.RepositoryException
Get the node atrelPath
frombaseNode
ornull
if no such node exists.- Parameters:
baseNode
- existing node that should be the base for the relative pathrelPath
- relative path to the node to get- Returns:
- the node at
relPath
frombaseNode
ornull
if no such node exists. - Throws:
javax.jcr.RepositoryException
- in case of exception accessing the Repository
-
getNodeIfExists
public static javax.jcr.Node getNodeIfExists(String absPath, javax.jcr.Session session) throws javax.jcr.RepositoryException
Gets the node atabsPath
ornull
if no such node exists.- Parameters:
absPath
- the absolute path to the node to returnsession
- to use- Returns:
- the node at
absPath
ornull
if no such node exists. - Throws:
javax.jcr.RepositoryException
- in case of exception accessing the Repository
-
getLastNodeIfExists
public static javax.jcr.Node getLastNodeIfExists(String absPath, javax.jcr.Session session) throws javax.jcr.RepositoryException
Gets the node atabsPath
ornull
if no such node exists. In case there are more nodes atabsPath
, the last node is returned.- Parameters:
absPath
- the absolute path to the node to returnsession
- to use- Returns:
- the node at
absPath
ornull
if no such node exists. - Throws:
javax.jcr.RepositoryException
-
getStringProperty
public static String getStringProperty(javax.jcr.Node baseNode, String relPath, String defaultValue) throws javax.jcr.RepositoryException
Returns the string property value atrelPath
frombaseNode
ordefaultValue
if no such property exists.- Parameters:
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 exist- Returns:
- the string property value at
relPath
frombaseNode
ordefaultValue
if no such property exists - Throws:
javax.jcr.RepositoryException
- in case of exception accessing the Repository
-
getEnumProperty
public static <E extends Enum<E>> E getEnumProperty(javax.jcr.Node baseNode, String relPath, E defaultValue) throws javax.jcr.RepositoryException
Returns the enum value of a string property atrelPath
frombaseNode
ordefaultValue
if no such property exists.- Parameters:
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 exist- Returns:
- the enum value of a string property at
relPath
frombaseNode
ordefaultValue
if no such property exists or property doesn't have any enum value - Throws:
javax.jcr.RepositoryException
- in case of exception accessing the Repository
-
getMultipleStringProperty
public static String[] getMultipleStringProperty(javax.jcr.Node baseNode, String relPath, String[] defaultValue) throws javax.jcr.RepositoryException
Returns the multiple string property values atrelPath
frombaseNode
ordefaultValue
if no such property exists.- Parameters:
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 exist- Returns:
- the multiple string property value at
relPath
frombaseNode
ordefaultValue
if no such property exists - Throws:
javax.jcr.RepositoryException
- in case of exception accessing the Repository
-
getStringListProperty
public static List<String> getStringListProperty(javax.jcr.Node baseNode, String relPath, List<String> defaultValue) throws javax.jcr.RepositoryException
Returns the multiple string property values atrelPath
frombaseNode
ordefaultValue
if no such property exists.- Parameters:
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 exist- Returns:
- the multiple string property value at
relPath
frombaseNode
ordefaultValue
if no such property exists - Throws:
javax.jcr.RepositoryException
- in case of exception accessing the Repository
-
getStringSetProperty
public static Set<String> getStringSetProperty(javax.jcr.Node baseNode, String relPath, Set<String> defaultValue) throws javax.jcr.RepositoryException
Returns the unique and unordered multiple string property values atrelPath
frombaseNode
ordefaultValue
if no such property exists.- Parameters:
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 exist- Returns:
- the unique and unordered multiple string property value at
relPath
frombaseNode
ordefaultValue
if no such property exists - Throws:
javax.jcr.RepositoryException
- in case of exception accessing the Repository
-
getLongProperty
public static Long getLongProperty(javax.jcr.Node baseNode, String relPath, Long defaultValue) throws javax.jcr.RepositoryException
Returns the long property value atrelPath
frombaseNode
ordefaultValue
if no such property exists.- Parameters:
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 exist- Returns:
- the long property value at
relPath
frombaseNode
ordefaultValue
if no such property exists - Throws:
javax.jcr.RepositoryException
- in case of exception accessing the Repository
-
getDoubleProperty
public static Double getDoubleProperty(javax.jcr.Node baseNode, String relPath, Double defaultValue) throws javax.jcr.RepositoryException
Returns the double property value atrelPath
frombaseNode
ordefaultValue
if no such property exists.- Parameters:
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 exist- Returns:
- the double property value at
relPath
frombaseNode
ordefaultValue
if no such property exists - Throws:
javax.jcr.RepositoryException
- in case of exception accessing the Repository
-
getBooleanProperty
public static Boolean getBooleanProperty(javax.jcr.Node baseNode, String relPath, Boolean defaultValue) throws javax.jcr.RepositoryException
Returns the boolean property value atrelPath
frombaseNode
ordefaultValue
if no such property exists.- Parameters:
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 exist- Returns:
- the boolean property value at
relPath
frombaseNode
ordefaultValue
if no such property exists - Throws:
javax.jcr.RepositoryException
- in case of exception accessing the Repository
-
getDateProperty
public static Calendar getDateProperty(javax.jcr.Node baseNode, String relPath, Calendar defaultValue) throws javax.jcr.RepositoryException
Returns the date property value atrelPath
frombaseNode
ordefaultValue
if no such property exists.- Parameters:
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 exist- Returns:
- the date property value at
relPath
frombaseNode
ordefaultValue
if no such property exists - Throws:
javax.jcr.RepositoryException
- in case of exception accessing the Repository
-
getDecimalProperty
public static BigDecimal getDecimalProperty(javax.jcr.Node baseNode, String relPath, BigDecimal defaultValue) throws javax.jcr.RepositoryException
Returns the decimal property value atrelPath
frombaseNode
ordefaultValue
if no such property exists.- Parameters:
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 exist- Returns:
- the decimal property value at
relPath
frombaseNode
ordefaultValue
if no such property exists - Throws:
javax.jcr.RepositoryException
- in case of exception accessing the Repository
-
getBinaryProperty
public static javax.jcr.Binary getBinaryProperty(javax.jcr.Node baseNode, String relPath, javax.jcr.Binary defaultValue) throws javax.jcr.RepositoryException
Returns the binary property value atrelPath
frombaseNode
ordefaultValue
if no such property exists.- Parameters:
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 exist- Returns:
- the binary property value at
relPath
frombaseNode
ordefaultValue
if no such property exists - Throws:
javax.jcr.RepositoryException
- in case of exception accessing the Repository
-
getNodeProperty
public static javax.jcr.Node getNodeProperty(javax.jcr.Node baseNode, String relPath, javax.jcr.Node defaultValue) throws javax.jcr.RepositoryException
Returns the node property value atrelPath
frombaseNode
ordefaultValue
if no such property exists.- Parameters:
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 exist- Returns:
- the node property value at
relPath
frombaseNode
ordefaultValue
if no such property exists - Throws:
javax.jcr.RepositoryException
- in case of exception accessing the Repository
-
getStringProperty
public static String getStringProperty(javax.jcr.Session session, String absPath, String defaultValue) throws javax.jcr.RepositoryException
Returns the string property value atabsPath
ordefaultValue
if no such property exists.- Parameters:
session
- to useabsPath
- absolute path to the property to getdefaultValue
- default value to return when the property does not exist- Returns:
- the string property value at
absPath
ordefaultValue
if no such property exists - Throws:
javax.jcr.RepositoryException
- in case of exception accessing the Repository
-
getLongProperty
public static Long getLongProperty(javax.jcr.Session session, String absPath, Long defaultValue) throws javax.jcr.RepositoryException
Returns the long property value atabsPath
ordefaultValue
if no such property exists.- Parameters:
session
- to useabsPath
- absolute path to the property to getdefaultValue
- default value to return when the property does not exist- Returns:
- the long property value at
absPath
ordefaultValue
if no such property exists - Throws:
javax.jcr.RepositoryException
- in case of exception accessing the Repository
-
getDoubleProperty
public static Double getDoubleProperty(javax.jcr.Session session, String absPath, Double defaultValue) throws javax.jcr.RepositoryException
Returns the double property value atabsPath
ordefaultValue
if no such property exists.- Parameters:
session
- to useabsPath
- absolute path to the property to getdefaultValue
- default value to return when the property does not exist- Returns:
- the double property value at
absPath
ordefaultValue
if no such property exists - Throws:
javax.jcr.RepositoryException
- in case of exception accessing the Repository
-
getBooleanProperty
public static Boolean getBooleanProperty(javax.jcr.Session session, String absPath, Boolean defaultValue) throws javax.jcr.RepositoryException
Returns the boolean property value atabsPath
ordefaultValue
if no such property exists.- Parameters:
session
- to useabsPath
- absolute path to the property to getdefaultValue
- default value to return when the property does not exist- Returns:
- the boolean property value at
absPath
ordefaultValue
if no such property exists - Throws:
javax.jcr.RepositoryException
- in case of exception accessing the Repository
-
getDateProperty
public static Calendar getDateProperty(javax.jcr.Session session, String absPath, Calendar defaultValue) throws javax.jcr.RepositoryException
Returns the date property value atabsPath
ordefaultValue
if no such property exists.- Parameters:
session
- to useabsPath
- absolute path to the property to getdefaultValue
- default value to return when the property does not exist- Returns:
- the date property value at
absPath
ordefaultValue
if no such property exists - Throws:
javax.jcr.RepositoryException
- in case of exception accessing the Repository
-
getDecimalProperty
public static BigDecimal getDecimalProperty(javax.jcr.Session session, String absPath, BigDecimal defaultValue) throws javax.jcr.RepositoryException
Returns the decimal property value atabsPath
ordefaultValue
if no such property exists.- Parameters:
session
- to useabsPath
- absolute path to the property to getdefaultValue
- default value to return when the property does not exist- Returns:
- the decimal property value at
absPath
ordefaultValue
if no such property exists - Throws:
javax.jcr.RepositoryException
- in case of exception accessing the Repository
-
getBinaryProperty
public static javax.jcr.Binary getBinaryProperty(javax.jcr.Session session, String absPath, javax.jcr.Binary defaultValue) throws javax.jcr.RepositoryException
Returns the binary property value atabsPath
ordefaultValue
if no such property exists.- Parameters:
session
- to useabsPath
- absolute path to the property to getdefaultValue
- default value to return when the property does not exist- Returns:
- the binary property value at
absPath
ordefaultValue
if no such property exists - Throws:
javax.jcr.RepositoryException
- in case of exception accessing the Repository
-
getNodeProperty
public static javax.jcr.Node getNodeProperty(javax.jcr.Session session, String absPath, javax.jcr.Node defaultValue) throws javax.jcr.RepositoryException
Returns the node property value atabsPath
ordefaultValue
if no such property exists.- Parameters:
session
- to useabsPath
- absolute path to the property to getdefaultValue
- default value to return when the property does not exist- Returns:
- the node property value at
absPath
ordefaultValue
if no such property exists - Throws:
javax.jcr.RepositoryException
- in case of exception accessing the Repository
-
getPropertyIfExists
public static javax.jcr.Property getPropertyIfExists(javax.jcr.Node baseNode, String relPath) throws javax.jcr.RepositoryException
Get the property atrelPath
frombaseNode
ornull
if no such property exists.- Parameters:
baseNode
- existing node that should be the base for the relative pathrelPath
- relative path to the property to get- Returns:
- the property at
relPath
frombaseNode
ornull
if no such property exists. - Throws:
javax.jcr.RepositoryException
- in case of exception accessing the Repository
-
getPropertyIfExists
public static javax.jcr.Property getPropertyIfExists(String absPath, javax.jcr.Session session) throws javax.jcr.RepositoryException
Gets the property atabsPath
ornull
if no such property exists.- Parameters:
absPath
- the absolute path to the property to returnsession
- to use- Returns:
- the property at
absPath
ornull
if no such property exists. - Throws:
javax.jcr.RepositoryException
- in case of exception accessing the Repository
-
copy
public static javax.jcr.Node copy(javax.jcr.Session session, String srcAbsPath, String destAbsPath) throws javax.jcr.RepositoryException
Copies node atsrcAbsPath
todestAbsPath
as session operation.- Parameters:
session
- to usesrcAbsPath
- the absolute path of the source nodedestAbsPath
- the absolute path of the resulting copy- Returns:
- the created node
- Throws:
javax.jcr.RepositoryException
IllegalArgumentException
- if srcNode is same as destParentNode or destParentNode is a descendant of srcNode or destAbsPath is the root node path.
-
copy
public static javax.jcr.Node copy(javax.jcr.Node srcNode, String destNodeName, javax.jcr.Node destParentNode) throws javax.jcr.RepositoryException
CopiesNode
srcNode
todestParentNode
with namedestNodeName
.- Parameters:
srcNode
- the node to copydestNodeName
- the name of the to be newly created nodedestParentNode
- the parent of the to be newly created node- Returns:
- the created node
- Throws:
javax.jcr.RepositoryException
IllegalArgumentException
- if srcNode is same as destParentNode or destParentNode is a descendant of srcNode
-
copyTo
public static void copyTo(javax.jcr.Node srcNode, javax.jcr.Node destNode) throws javax.jcr.RepositoryException
CopiesNode
srcNode
todestNode
.- Parameters:
srcNode
- the node to copydestNode
- the node that the contents of srcNode will be copied to- Throws:
javax.jcr.RepositoryException
IllegalArgumentException
- if scrNode is same as destNode or destNode is a descendant of srcNode
-
copyTo
public static javax.jcr.Node copyTo(javax.jcr.Node srcNode, CopyHandler chain) throws javax.jcr.RepositoryException
CopiesNode
srcNode
todestNode
with ahandler
to rewrite content if necessary.- Parameters:
srcNode
- the node to copychain
- the handler that intercepts node and property creation, can be null- Throws:
javax.jcr.RepositoryException
-
copyToChain
public static void copyToChain(javax.jcr.Node srcNode, CopyHandler chain) throws javax.jcr.RepositoryException
- Throws:
javax.jcr.RepositoryException
-
getPrimaryNodeType
public static javax.jcr.nodetype.NodeType getPrimaryNodeType(javax.jcr.Node node) throws javax.jcr.RepositoryException
Retrieve the primary node type. Can handle frozen nodes as well as regular nodes.- Parameters:
node
-- Returns:
- the primary node type
- Throws:
javax.jcr.RepositoryException
-
getMixinNodeTypes
public static javax.jcr.nodetype.NodeType[] getMixinNodeTypes(javax.jcr.Node node) throws javax.jcr.RepositoryException
Retrieve the mixin node types present on a node. Can handle frozen nodes as well as regular nodes.- Parameters:
node
-- Returns:
- the mixin node types present on a node
- Throws:
javax.jcr.RepositoryException
-
createBinaryValueFromObject
public static javax.jcr.Value createBinaryValueFromObject(javax.jcr.Session session, Object object) throws javax.jcr.RepositoryException
Serialize the givenobject
into a binary JCR value.- Parameters:
session
- to useobject
- to serialize- Returns:
- a binary value containing the serialized object
- Throws:
javax.jcr.RepositoryException
-
emptyNodeIterable
public static NodeIterable emptyNodeIterable()
- Returns:
- an empty
NodeIterable
-
ensureIsCheckedOut
public static void ensureIsCheckedOut(javax.jcr.Node node) throws javax.jcr.RepositoryException
Make sure the node is in checked out state. If the node is not in checked out state it will get checked out- Parameters:
node
- the node to check- Throws:
javax.jcr.RepositoryException
-
isVirtual
public static boolean isVirtual(javax.jcr.Node node) throws javax.jcr.RepositoryException
- Parameters:
node
- the node to check- Returns:
- whether the node is virtual
- Throws:
javax.jcr.RepositoryException
-
getNodePathQuietly
public static String getNodePathQuietly(javax.jcr.Node node)
Get the path of aNode
, ornull
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.
- Parameters:
node
- - TheNode
to get the path of- Returns:
- The path of the
Node
, ornull
ifnode
is null or an exception happens.
-
getNodeNameQuietly
public static String getNodeNameQuietly(javax.jcr.Node node)
Get the name of aNode
, ornull
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.
- Parameters:
node
- - TheNode
to get the name of- Returns:
- The name of the
Node
, ornull
ifnode
is null or an exception happens.
-
getDisplayNameQuietly
public static String getDisplayNameQuietly(javax.jcr.Node node)
Get the display name of aNode
, ornull
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.
- Parameters:
node
- - TheNode
to get the name of- Returns:
- The display name of the
Node
, ornull
ifnode
is null or an exception happens.
-
getProperties
public static Iterable<javax.jcr.Property> getProperties(javax.jcr.Node node) throws javax.jcr.RepositoryException
CallsNode.getProperties()
on the given node and returns the it as anIterable
instance for use in a Java 5 for-each loop.- Parameters:
node
- node- Returns:
- properties of the node as an iterable
- Throws:
javax.jcr.RepositoryException
- if theNode.getProperties()
call fails
-
isPropertyEvent
public static boolean isPropertyEvent(javax.jcr.observation.Event event)
-
getNextSiblingIfExists
public static javax.jcr.Node getNextSiblingIfExists(javax.jcr.Node current) throws javax.jcr.RepositoryException
Returns the next sibling
Node
ofcurrent
. If there is no next sibling it returnsnull
. If the parentNode
ofcurrent
is not an orderableNode
, anUnsupportedRepositoryOperationException
will be thrown. Checking whether the parent is orderable can be done easily as followsNode 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()); }
- Parameters:
current
- theNode
for which to find the next sibling- Returns:
- the next sibling of current if there is a next one and
null
in case there is no next sibling - Throws:
javax.jcr.UnsupportedRepositoryOperationException
- if the parent ofcurrent
is not orderablejavax.jcr.RepositoryException
- if some repository exception happens
-
isAncestor
public static boolean isAncestor(javax.jcr.Node ancestor, javax.jcr.Node descendant) throws javax.jcr.RepositoryException
- Throws:
javax.jcr.RepositoryException
-
getDescendants
public static List<javax.jcr.Node> getDescendants(javax.jcr.Node source, String nodeType, boolean prune) throws javax.jcr.RepositoryException
Returns the list of jcr nodes which are descendants of
source
and of typenodeType
, wheresource
is never included in the result. Whenprune
istrue
, matching descendants are added and the descendants of a matching descendant are not scanned (and thus also not added)- Parameters:
source
-nodeType
-- Returns:
- Throws:
javax.jcr.RepositoryException
-
-