How can you change the name of a JCR node?

joksy82 picture joksy82 · Nov 12, 2010 · Viewed 8.5k times · Source

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.

Answer

stacker picture stacker · Nov 12, 2010

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();
    }