Change node name without move method | Adobe Higher Education
Skip to main content
Scott_Przy
October 30, 2018
Respondido

Change node name without move method

  • October 30, 2018
  • 4 respostas
  • 7295 Visualizações

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.

Este tópico foi fechado para respostas.
Melhor resposta por 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 Respostas

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