On Mon, Jan 26, 2009 at 6:08 PM, Jean Couteau <couteau(a)codelutin.com> wrote:
Dear all,
I am trying to create a document from a page, with a template and an
object attached, but without having to quit the said page.
I generate fine the new document and the object with the values i want
for the properties, but i did not succeed in putting text in the
document, i tried using $newDoc.setDefaultTemplate and
$newDoc.insertText but no success at all.
All the available methods are described (well, at least listed) in our javadoc.
http://platform.xwiki.org/xwiki/bin/download/DevGuide/API/xwiki-core-1.7.1-…
-> Document > void setContent(java.lang.String content)
I post here my piece of code, any hint will be appreciated (after a few
hours on this, i am a bit lost):
#if($createDomain!="")
#set($newDoc=$xwiki.createDocument())
#set($newName="Project."+$newDomainId)
You can't manipulate strings like this with velocity, see bellow.
$newDoc.rename($newName)
You don't have to create then rename a document, see bellow.
$newDoc.insertText("#includeForm(\"XWiki.DomainClassSheet\")","")
#set($newDoc=$xwiki.getDocument($newName))
#set($newObject=$newDoc.newObject("XWiki.DomainClass"))
$newObject.set("id",$newDomainId)
$newObject.set("name",$createDomain)
$newDoc.save()
#end
You should try:
#if($createDomain!="")
#set($newDoc=$xwiki.getDocument("Project.${newDomainId}"))
$newDoc.setContent("#includeForm(\"XWiki.DomainClassSheet\")")
#set($newObject=$newDoc.newObject("XWiki.DomainClass"))
$newObject.set("id", $newDomainId)
$newObject.set("name",$createDomain)
$newDoc.save()
#end
But I'm pretty sure you'll have a problem with the # in setContent,
IIRW I had this problem in the past.
Anyway what you should do here is creating a page with the default
content and object (and call it a template) and copy it in your
script.
#if($createDomain!="")
$xwiki.copyDocument("Project.ProjectTemplate",
"Project.${newDomainId}")
#set($domainDoc = $xwiki."Project.${newDomainId}")
#set($domainObj = $newDoc.getObject("XWiki.DomainClass"))
$domainObj.set("id", $newDomainId)
$domainObj.set("name",$createDomain)
$domainDoc.save()
#end
JV.