Hi All,
is there any API or java code to convert the page names to lower case pragmatically.
Solved! Go to Solution.
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.
Views
Replies
Total Likes
Views
Replies
Total Likes
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
Views
Replies
Total Likes
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.
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
Views
Replies
Total Likes
Can you give a sample example for renaming the node using groovy script
Views
Replies
Total Likes
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...
Please be also aware of the runtime implications of this. You are moving nodes, not just renaming.
Views
Replies
Total Likes
Views
Likes
Replies
Views
Likes
Replies