Brian Thompson wrote:

In my case, it was a web app where each sibling node corresponded to a page
being displayed, and we needed a paging mechanism (the pages formed a
training course).

Since a child node does not know anything about its siblings you will have to ask the parent which means essentially you have to call childNode.getParent().getNodes() and use the resulting iterator to find your specific child node and then identify its neighbors.
If you use same name siblings you could also use something like this:

public class GetNeighbour {
  public static void main(String[] args) throws Exception {
    TransientRepository repository = new TransientRepository();
    Session session = repository.login(
      new SimpleCredentials("username", "password".toCharArray()));
    try {
      Node testRoot = session.getRootNode().addNode("test");
      testRoot.addNode("child");
      testRoot.addNode("child");
      Node node = testRoot.getNode("child[1]");
      String nextSiblingsPath = node.getName() + "["
          + (node.getIndex() + 1) + "]";
      if (testRoot.hasNode(nextSiblingsPath)) {
        System.out.println(
          testRoot.getNode(nextSiblingsPath).getPath());
      }
      testRoot.remove();
    } finally {
      session.logout();
    }
  }
}


BR,
Chris

Reply via email to