Class 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)
      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 void copyTo​(javax.jcr.Node srcNode, javax.jcr.Node destNode)
      Copies Node srcNode to destNode.
      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 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 List<javax.jcr.Node> getDescendants​(javax.jcr.Node source, String nodeType, boolean prune)
      Returns the list of jcr nodes which are descendants of source and of type nodeType, where source is never included in the result.
      static String getDisplayNameQuietly​(javax.jcr.Node node)
      Get the display name of a Node, or null if the node cannot be retrieved.
      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 <E extends Enum<E>>
      E
      getEnumProperty​(javax.jcr.Node baseNode, String relPath, E defaultValue)
      Returns the enum value of a string property at relPath from baseNode 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 values 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​(String absPath, javax.jcr.Session session)
      Gets the node at absPath or null if no such node exists.
      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 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​(String absPath, javax.jcr.Session session)
      Gets the property at absPath or null if no such property exists.
      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 List<String> getStringListProperty​(javax.jcr.Node baseNode, String relPath, List<String> defaultValue)
      Returns the multiple string property values at relPath from baseNode or defaultValue 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 Set<String> getStringSetProperty​(javax.jcr.Node baseNode, String relPath, Set<String> defaultValue)
      Returns the unique and unordered multiple string property values at relPath from baseNode or defaultValue 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)  
    • Constructor Detail

      • JcrUtils

        public JcrUtils()
    • Method Detail

      • getNodeIfExists

        public static javax.jcr.Node getNodeIfExists​(javax.jcr.Node baseNode,
                                                     String relPath)
                                              throws javax.jcr.RepositoryException
        Get the node at relPath from baseNode or null if no such node exists.
        Parameters:
        baseNode - existing node that should be the base for the relative path
        relPath - relative path to the node to get
        Returns:
        the node at relPath from baseNode or null 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 at absPath or null if no such node exists.
        Parameters:
        absPath - the absolute path to the node to return
        session - to use
        Returns:
        the node at absPath or null 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 at absPath or null if no such node exists. In case there are more nodes at absPath, the last node is returned.
        Parameters:
        absPath - the absolute path to the node to return
        session - to use
        Returns:
        the node at absPath or null 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 at relPath from baseNode or defaultValue if no such property exists.
        Parameters:
        baseNode - existing node that should be the base for the relative path
        relPath - relative path to the property to get
        defaultValue - default value to return when the property does not exist
        Returns:
        the string property value at relPath from baseNode or defaultValue 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 at relPath from baseNode or defaultValue if no such property exists.
        Parameters:
        baseNode - existing node that should be the base for the relative path
        relPath - relative path to the property to get
        defaultValue - default value to return when the property does not exist
        Returns:
        the enum value of a string property at relPath from baseNode or defaultValue 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 at relPath from baseNode or defaultValue if no such property exists.
        Parameters:
        baseNode - existing node that should be the base for the relative path
        relPath - relative path to the property to get
        defaultValue - default value to return when the property does not exist
        Returns:
        the multiple string property value at relPath from baseNode or defaultValue 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 at relPath from baseNode or defaultValue if no such property exists.
        Parameters:
        baseNode - existing node that should be the base for the relative path
        relPath - relative path to the property to get
        defaultValue - default value to return when the property does not exist
        Returns:
        the multiple string property value at relPath from baseNode or defaultValue 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 at relPath from baseNode or defaultValue if no such property exists.
        Parameters:
        baseNode - existing node that should be the base for the relative path
        relPath - relative path to the property to get
        defaultValue - default value to return when the property does not exist
        Returns:
        the unique and unordered multiple string property value at relPath from baseNode or defaultValue 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 at relPath from baseNode or defaultValue if no such property exists.
        Parameters:
        baseNode - existing node that should be the base for the relative path
        relPath - relative path to the property to get
        defaultValue - default value to return when the property does not exist
        Returns:
        the long property value at relPath from baseNode or defaultValue 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 at relPath from baseNode or defaultValue if no such property exists.
        Parameters:
        baseNode - existing node that should be the base for the relative path
        relPath - relative path to the property to get
        defaultValue - default value to return when the property does not exist
        Returns:
        the double property value at relPath from baseNode or defaultValue 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 at relPath from baseNode or defaultValue if no such property exists.
        Parameters:
        baseNode - existing node that should be the base for the relative path
        relPath - relative path to the property to get
        defaultValue - default value to return when the property does not exist
        Returns:
        the boolean property value at relPath from baseNode or defaultValue 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 at relPath from baseNode or defaultValue if no such property exists.
        Parameters:
        baseNode - existing node that should be the base for the relative path
        relPath - relative path to the property to get
        defaultValue - default value to return when the property does not exist
        Returns:
        the date property value at relPath from baseNode or defaultValue 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 at relPath from baseNode or defaultValue if no such property exists.
        Parameters:
        baseNode - existing node that should be the base for the relative path
        relPath - relative path to the property to get
        defaultValue - default value to return when the property does not exist
        Returns:
        the decimal property value at relPath from baseNode or defaultValue 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 at relPath from baseNode or defaultValue if no such property exists.
        Parameters:
        baseNode - existing node that should be the base for the relative path
        relPath - relative path to the property to get
        defaultValue - default value to return when the property does not exist
        Returns:
        the binary property value at relPath from baseNode or defaultValue 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 at relPath from baseNode or defaultValue if no such property exists.
        Parameters:
        baseNode - existing node that should be the base for the relative path
        relPath - relative path to the property to get
        defaultValue - default value to return when the property does not exist
        Returns:
        the node property value at relPath from baseNode or defaultValue 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 at absPath or defaultValue if no such property exists.
        Parameters:
        session - to use
        absPath - absolute path to the property to get
        defaultValue - default value to return when the property does not exist
        Returns:
        the string property value at absPath or defaultValue 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 at absPath or defaultValue if no such property exists.
        Parameters:
        session - to use
        absPath - absolute path to the property to get
        defaultValue - default value to return when the property does not exist
        Returns:
        the long property value at absPath or defaultValue 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 at absPath or defaultValue if no such property exists.
        Parameters:
        session - to use
        absPath - absolute path to the property to get
        defaultValue - default value to return when the property does not exist
        Returns:
        the double property value at absPath or defaultValue 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 at absPath or defaultValue if no such property exists.
        Parameters:
        session - to use
        absPath - absolute path to the property to get
        defaultValue - default value to return when the property does not exist
        Returns:
        the boolean property value at absPath or defaultValue 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 at absPath or defaultValue if no such property exists.
        Parameters:
        session - to use
        absPath - absolute path to the property to get
        defaultValue - default value to return when the property does not exist
        Returns:
        the date property value at absPath or defaultValue 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 at absPath or defaultValue if no such property exists.
        Parameters:
        session - to use
        absPath - absolute path to the property to get
        defaultValue - default value to return when the property does not exist
        Returns:
        the decimal property value at absPath or defaultValue 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 at absPath or defaultValue if no such property exists.
        Parameters:
        session - to use
        absPath - absolute path to the property to get
        defaultValue - default value to return when the property does not exist
        Returns:
        the binary property value at absPath or defaultValue 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 at absPath or defaultValue if no such property exists.
        Parameters:
        session - to use
        absPath - absolute path to the property to get
        defaultValue - default value to return when the property does not exist
        Returns:
        the node property value at absPath or defaultValue 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 at relPath from baseNode or null if no such property exists.
        Parameters:
        baseNode - existing node that should be the base for the relative path
        relPath - relative path to the property to get
        Returns:
        the property at relPath from baseNode or null 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 at absPath or null if no such property exists.
        Parameters:
        absPath - the absolute path to the property to return
        session - to use
        Returns:
        the property at absPath or null 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 at srcAbsPath to destAbsPath as session operation.
        Parameters:
        session - to use
        srcAbsPath - the absolute path of the source node
        destAbsPath - 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
        Copies Node srcNode to destParentNode with name destNodeName.
        Parameters:
        srcNode - the node to copy
        destNodeName - the name of the to be newly created node
        destParentNode - 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
        Copies Node srcNode to destNode.
        Parameters:
        srcNode - the node to copy
        destNode - 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
        Copies Node srcNode to destNode with a handler to rewrite content if necessary.
        Parameters:
        srcNode - the node to copy
        chain - 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 given object into a binary JCR value.
        Parameters:
        session - to use
        object - to serialize
        Returns:
        a binary value containing the serialized object
        Throws:
        javax.jcr.RepositoryException
      • 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 a 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.

        Parameters:
        node - - The Node to get the path of
        Returns:
        The path of the Node, or null if node is null or an exception happens.
      • getNodeNameQuietly

        public static String getNodeNameQuietly​(javax.jcr.Node node)
        Get the name of a 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.

        Parameters:
        node - - The Node to get the name of
        Returns:
        The name of the Node, or null if node is null or an exception happens.
      • getDisplayNameQuietly

        public static String getDisplayNameQuietly​(javax.jcr.Node node)
        Get the display name of a 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.

        Parameters:
        node - - The Node to get the name of
        Returns:
        The display name of the Node, or null if node is null or an exception happens.
      • getProperties

        public static Iterable<javax.jcr.Property> getProperties​(javax.jcr.Node node)
                                                          throws javax.jcr.RepositoryException
        Calls Node.getProperties() on the given node and returns the it as an Iterable 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 the Node.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 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());
                 }
         

        Parameters:
        current - the Node 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 of current is not orderable
        javax.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 type nodeType, where source is never included in the result. When prune is true, 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