5

I'm trying to change the name of a JCR node, but I have no idea how? Has someone of you some hints?

Many thanks.

user unknown
  • 35,537
  • 11
  • 75
  • 121
joksy82
  • 405
  • 2
  • 6
  • 13

1 Answers1

11

The Jackrabbit Wiki provides an example:

void rename(Node node, String newName) throws RepositoryException 
    {
        node.getSession().move(node.getPath(), node.getParent().getPath() + "/" + newName);
        // Don't forget - not necessarily here at this place:
        // node.getSession().save();
    }
stacker
  • 68,052
  • 28
  • 140
  • 210
  • 1
    Note that the rename method is *not* part of JCR. It is part of the Jackrabbit API though. If you want to be strictly JCR compliant you need to use the move method to move a node to a new name. In addition, if the parent node is orderable, you have to reorder the moved node to its previous place after moving. – michid Nov 16 '10 at 11:01
  • The wiki still maintains that code as the date of today, but testing that with JackRabbit's latest version throws an Exception. Removing the extra "/" is needed to make it work.. – Aritz Jan 08 '14 at 16:37