1 Reply Latest reply on Aug 7, 2012 8:10 PM by klcodanr85

    x-path query to get all versions of  a node at a given path in JSP


      hi need a xpath query so that i can list all the versions of a selected node which can be used for restoring the version to that particular one??

        • 1. Re: x-path query to get all versions of  a node at a given path in JSP
          klcodanr85 Level 1

          I'm not sure about an xpath query (which was deprecated in JCR 2.0), but here's how you could use the JCR API to retrieve all of the versions from a path:



               * Returns all of the versions at the specified path as a List of Versions.


               * @param session

               *            the currect JCR session, must not be null

               * @param path

               *            the absolute path of the node to retrieve

               * @return the list of versions at the specified path

               * @throws UnsupportedRepositoryOperationException

               *             thrown if the node at the specified path is not versionable

               * @throws RepositoryException

               *             an unexpected exception occurs interacting with the JCR

               *             repository


              public List<javax.jcr.version.Version> getVersions(final Session session,

                  final String path) throws UnsupportedRepositoryOperationException,

                  RepositoryException {

              final List<Version> versions = new ArrayList<Version>();

              final VersionManager versionMgr = session.getWorkspace()


              final VersionHistory versionHistory = versionMgr


              final VersionIterator versionIterator = versionHistory.getAllVersions();

              while (versionIterator.hasNext()) {



              return versions;


          1 person found this helpful