How can you change the name of a JCR node?
Asked Answered
Z

1

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.

Zuckerman answered 12/11, 2010 at 13:17 Comment(1)
are you trying to change the node's name "property" or the node's "type" name?Prologue
K
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();
    }
Kramer answered 12/11, 2010 at 13:28 Comment(2)
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.Decided
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..Circumvent

© 2022 - 2024 — McMap. All rights reserved.