General Actions:
Log-in
Wiki:
Courses
▼
:
Document Index
»
Space:
Admin
▼
:
Document Index
»
Page:
ImportPage
Search
Page Actions:
Export
▼
:
Export as PDF
Export as RTF
Export as HTML
More actions
▼
:
Print preview
View Source
Import Page
Wiki source code of
Import Page
Last modified by
Hal Eden
on 2010/08/19 07:32
Content
·
Comments
(0)
·
Attachments
(0)
·
History
·
Information
Show line numbers
1.1 Import Page <% import com.xpn.xwiki.*; import com.xpn.xwiki.doc.*; import com.xpn.xwiki.plugin.packaging.*; finalPageName = "" def updateDoc(String newname, String xml, String type, XWikiContext context) { def prevDoc = context.getWiki().getDocument(newname, context); def prevArchive = prevDoc.getDocumentArchive(); if (prevDoc.isNew()||((type!="NOOVERVERSIONS")&&(type!="NOOVERNOVERSIONS"))) { def fdoc = new XWikiDocument() fdoc.fromXML(xml); // We need to verify the document has the right name // Otherwise we might override something we don't expect if ((newname!="")&&(fdoc.fullName!=newname)) { fdoc = fdoc.copyDocument(newname, context); } finalPageName = fdoc.getFullName() if (type=="ADDVERSION") { fdoc.setDocumentArchive(prevArchive); context.getWiki().saveDocument(fdoc, context); if (prevDoc.isNew()) { fdoc.resetArchive(context); } return 1; } else { def pack = new Package() if ((type=="NOOVERVERSIONS")||(type=="OVERVERSIONS")) pack.setWithVersions(true) else pack.setWithVersions(false) pack.setBackupPack(true) pack.add(fdoc, 0, context) return pack.install(context) } } else { return -1000; } } if (request.get("name")!=null) { def fupl= xwiki.get("fileupload"); def myfiles = fupl.getFileItems(); def xml = fupl.getFileItem("file"); def fName = fupl.getFileName("file"); def docName = fupl.getFileItem("name"); def type = fupl.getFileItem("type"); def ret = updateDoc(docName, xml, type, context.context); if (ret < 0) { if (ret==-1000) println "Document already exists and overwrite was not specified."; else println "Document could not be imported with error ${ret}."; } else { println "Document has been imported properly: [${finalPageName}]." } } else { %> <form action="" enctype="multipart/form-data" method="post"> <table border="0"> <tr> <td>Page Name to save to:</td><td><input type="text" name="name" size="60" /></td> </tr> <tr> <td>Type:</td><td> <input type="radio" name="type" value="NOOVERVERSIONS" checked /> Do Not overwrite with versions <input type="radio" name="type" value="NOOVERNOVERSIONS" /> Do Not overwrite without versions <br /> <input type="radio" name="type" value="ADDVERSION" /> Add version <input type="radio" name="type" value="OVERVERSIONS" /> Overwrite with version <input type="radio" name="type" value="OVERNOVERSIONS" /> Overwrite without versions </td> </tr> <tr> <td>File:</td><td><input type="file" name="file" size="60" /></td> </tr> <tr> <td colspan="2" align="center"> <input type="submit" name="Import" /> </td> </tr> </table> </form> <% } %>
Welcome
Welcome to this XWiki!
Quick Links
DSSF 2008
DCNM 2009
HCCF 2010
Document Index
Sandbox
My Recent Modifications
ASSIGNMENTNAME