1

使用 Apache Sling 和 CRX/CQ5 和 JCR 等时...

是否可以遍历 JCR 中的 CQ5 页面节点并重命名页面。

我目前有一个脚本,可以更改特定路径的所有子页面中的属性。

我正在拼命寻找一种方法来使用 NodeIterator 和 Node 类在特定路径处重命名每个页面(不仅是标题和任意属性,而且是形成路径的名称)。

例子:

-content/xproject/shared/cars/a/abegro-assam
-content/xproject/shared/cars/m/motofuel-iss

我想做一些相当于:

while(cars.hasNext()) {
   Node node = cars.nextNode();

   //this is the functionality I want somehow...
   node.setName("some-other-name");

   //similar to how we would set JCR properties
   node.setProperty("someProperty", "someValue");
}

请告知我可以在 CQ5/Sling/Apache/CRX 堆栈中找到此功能的地方,因为这将非常有帮助。

我知道我可能能够适应该节点以外的其他一些类 - 但我非常不确定如何继续。

4

2 回答 2

4

要重命名 JCR 节点,请将它们移动到不同的路径,您可以使用需要调用 save() 的 Session.move(...) 或立即起作用的 Workspace.move(...)。

我不确定这些是否以及如何干扰当前的 NodeIterator - 如果有问题,您可以使用迭代将要重命名的节点的路径添加到列表,然后在该列表之外迭代NodeIterator 重命名节点。

于 2013-03-30T11:27:00.403 回答
0
void rename(Node node, String newName) throws RepositoryException 
{
    node.getSession().move(node.getPath(), node.getParent().getPath() + "/" + newName);
    // Don't forget - not necessarily here at this place:
    // node.getSession().save();
}
于 2015-02-12T12:51:07.050 回答