Expand my Community achievements bar.

SOLVED

Change node name without move method

Avatar

Level 1

Found a similar thread here: Need java code to convert the page names to lower case which a staff member posted this bit of code:

void rename(Node node, String newName) throws RepositoryException

    {

        node.getSession().move(node.getPath(), node.getParent().getPath() + "/" + newName.toLowerCase());  //

      

        node.getSession().save();

    }

which is close to what I need except that when its executed the node structure is changed and the newly named node is pushed to the bottom and I need it to maintain position in the structure.

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

Hi,

There is no explicit method to rename node in JCR, It can be done only by move method.

Since move method change the order of node but It can be reorder.

JCR 2.0: 23 Orderable Child Nodes (Content Repository for Java Technology API v2.0)



Arun Patidar

View solution in original post

4 Replies

Avatar

Level 10

See this thread here - it may help. I have never tried renaming a node via code.

java - How can you change the name of a JCR node? - Stack Overflow

Hope this helps...

Avatar

Correct answer by
Community Advisor

Hi,

There is no explicit method to rename node in JCR, It can be done only by move method.

Since move method change the order of node but It can be reorder.

JCR 2.0: 23 Orderable Child Nodes (Content Repository for Java Technology API v2.0)



Arun Patidar

Avatar

Level 1

Yeah there is too many nodes to change manual for us so we us groovy scripts to do so. This code in your link is the same i have posted above. Which apparently is the only way to do it but I have found a way to reorder after the fact.

Avatar

Level 1

Thank you the Node.OrderBefore(String srcChildRelPath, String destChildRelPath)

is exactly what I needed.