Change node name without move method | Community
Skip to main content
Scott_Przy
October 30, 2018
Solved

Change node name without move method

  • October 30, 2018
  • 4 replies
  • 7295 views

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.

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by arunpatidar

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)

4 replies

smacdonald2008
Level 10
October 31, 2018

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...

arunpatidar
Community Advisor
arunpatidarCommunity AdvisorAccepted solution
Community Advisor
October 31, 2018

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
Scott_Przy
October 31, 2018

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.

Scott_Przy
October 31, 2018

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

is exactly what I needed.