Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

SOLVED

Need java code to convert the page names to lower case

lakshmi_raghava
Level 3
Level 3

Hi All,

is there any API or java code to convert the page names to lower case pragmatically. 

1 Accepted Solution
leeasling
Correct answer by
Level 8
Level 8

I highly recommend using the Groovy Console (https://github.com/Citytechinc/cq-groovy-console) for this.

You can write a script like below:

getNode('/content/path/en').recurse { node -> rename node to node.name.toLowerCase() save() }

And that'll take care of it for you.

View solution in original post

0 Replies
lakshmi_raghava
Level 3
Level 3
        I need to convert page names not page title.  For page title, I know the approach,  I need for page names nothing but page paths.
lakshmi_raghava
Level 3
Level 3
        I need to convert page names not page title.  For page title, I know the approach,  I need for page names nothing but page paths.
Jörg_Hoh
Employee
Employee

Hi,

the page names are actually the name of the jcr nodes (which have a primary type of "cq:page"); so either traverse the tree you want to convert or use JCR SQL to determine the pages, and then use the JCR API to rename the pages (using session.move()).

Jörg

leeasling
Correct answer by
Level 8
Level 8

I highly recommend using the Groovy Console (https://github.com/Citytechinc/cq-groovy-console) for this.

You can write a script like below:

getNode('/content/path/en').recurse { node -> rename node to node.name.toLowerCase() save() }

And that'll take care of it for you.

kautuk_sahni
Employee
Employee

Hi 

Option 1:-

Using JCR API,

void rename(Node node, String newName) throws RepositoryException 
    {
        node.getSession().move(node.getPath(), node.getParent().getPath() + "/" + newName.toLowerCase());  //  
       
        node.getSession().save();
    }

Link:- http://stackoverflow.com/questions/19653046/how-to-rename-a-cq5-node-name-using-groovy-console

Option 2:- As mentioned by Lee, Use of Groovy console is good option..

//Move/Renaming in Groovy console

     getPage("/content/project").recurse { page ->
        def content = page.node
        if (content && "/apps/project/templates/club" == content.get("cq:template")) {
            content.set("cq:template", "/apps/project/templates/noclubs")
            println page.path
        }
    }
    save()

// to lower case 

    nodeName.toLowerCase()

Documentation link:- http://groovy-lang.org/single-page-documentation.html

I hope this will help you.

 

Thanks and Regards

Kautuk Sahni

pradeep_kumarr1
Level 1
Level 1

Can you give a sample example for renaming the node using groovy script

viveksachdeva
Level 7
Level 7

You can use something like code below:

resourceResolver.getResource("/content/geometrixx").listChildren().each {

    Node node = it.adaptTo(Node.class)

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

     node.getSession().save();  

}

P.S. : When you change node name, any place that you were referring it on also needs to change...

Jörg_Hoh
Employee
Employee

Please be also aware of the runtime implications of this. You are moving nodes, not just renaming.