[xwiki-users] Rename document with dot in groovy
Hi, I try to rename document to put them in the same space. I did it with a groovy script but i have a problem ; documents which contain dot are not renamed. This is my script : {{groovy}} def context = xcontext.getContext(); def xwiki = context.getWiki(); String spaceDestination = "NewSpace" def spaceNameList = ["Space1","Space2","Space3"]; def document = ""; for (spaceName in spaceNameList) { for(docName in xwiki.getSpaceDocsName(spaceName, context)) { document = xwiki.getDocument(spaceName+"."+docName, context); if (docName=="WebHome") { document.setParent(spaceDestination+".WebHome"); document.rename(spaceDestination+"."+spaceName, context); } else { //The problem appears here document.rename(spaceDestination+"."+docName, context); } } } {{/groovy}} I have already tried to espace the dot on the docName but it didn't work. Thank you, Quentin -- View this message in context: http://xwiki.475771.n2.nabble.com/Rename-document-with-dot-in-groovy-tp75958... Sent from the XWiki- Users mailing list archive at Nabble.com.
Hi, On 3 Sep 2015 at 15:49:55, qvendeville (quentin.vendeville@capgemini.com(mailto:quentin.vendeville@capgemini.com)) wrote:
Hi,
I try to rename document to put them in the same space. I did it with a groovy script but i have a problem ; documents which contain dot are not renamed.
This is my script :
{{groovy}} def context = xcontext.getContext(); def xwiki = context.getWiki(); String spaceDestination = "NewSpace" def spaceNameList = ["Space1","Space2","Space3"]; def document = ""; for (spaceName in spaceNameList) { for(docName in xwiki.getSpaceDocsName(spaceName, context)) { document = xwiki.getDocument(spaceName+"."+docName, context); if (docName=="WebHome") { document.setParent(spaceDestination+".WebHome"); document.rename(spaceDestination+"."+spaceName, context); } else { //The problem appears here document.rename(spaceDestination+"."+docName, context); } } }
{{/groovy}}
Two comments: 1) If you’re a on recent version of XWiki you should use the Refactoring script service: http://extensions.xwiki.org/xwiki/bin/view/Extension/Refactoring+Module 2) You should not manually create references, you should use the model script service for this, see http://extensions.xwiki.org/xwiki/bin/view/Extension/Model+Module#HScriptSer... Thanks -Vincent
I have already tried to espace the dot on the docName but it didn't work.
Thank you,
Quentin
-- View this message in context: http://xwiki.475771.n2.nabble.com/Rename-document-with-dot-in-groovy-tp75958... Sent from the XWiki- Users mailing list archive at Nabble.com. _______________________________________________ users mailing list users@xwiki.org http://lists.xwiki.org/mailman/listinfo/users
Thanks Vincent for your answer, but I found a solution :) I must espace the dot in the docName when I get my document, not in the rename method : document = xwiki.getDocument(spaceName+"."+docName.replace(".","\\."),context); -- View this message in context: http://xwiki.475771.n2.nabble.com/Rename-document-with-dot-in-groovy-tp75958... Sent from the XWiki- Users mailing list archive at Nabble.com.
You also need to escape \ itself to be complete. If you were using model script service as Vincent suggested you would not need to worry about escaping. On Thu, Sep 3, 2015 at 5:10 PM, qvendeville <quentin.vendeville@capgemini.com> wrote:
Thanks Vincent for your answer, but I found a solution :)
I must espace the dot in the docName when I get my document, not in the rename method :
document = xwiki.getDocument(spaceName+"."+docName.replace(".","\\."),context);
-- View this message in context: http://xwiki.475771.n2.nabble.com/Rename-document-with-dot-in-groovy-tp75958... Sent from the XWiki- Users mailing list archive at Nabble.com. _______________________________________________ users mailing list users@xwiki.org http://lists.xwiki.org/mailman/listinfo/users
-- Thomas Mortagne
participants (3)
-
qvendeville -
Thomas Mortagne -
vincent@massol.net