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
Hide line numbers
1: 1.1 Import Page 2: 3: <% 4: 5: import com.xpn.xwiki.*; 6: import com.xpn.xwiki.doc.*; 7: import com.xpn.xwiki.plugin.packaging.*; 8: 9: finalPageName = "" 10: 11: def updateDoc(String newname, String xml, String type, XWikiContext context) { 12: def prevDoc = context.getWiki().getDocument(newname, context); 13: def prevArchive = prevDoc.getDocumentArchive(); 14: if (prevDoc.isNew()||((type!="NOOVERVERSIONS")&&(type!="NOOVERNOVERSIONS"))) { 15: def fdoc = new XWikiDocument() 16: fdoc.fromXML(xml); 17: // We need to verify the document has the right name 18: // Otherwise we might override something we don't expect 19: if ((newname!="")&&(fdoc.fullName!=newname)) { 20: fdoc = fdoc.copyDocument(newname, context); 21: } 22: finalPageName = fdoc.getFullName() 23: 24: if (type=="ADDVERSION") { 25: fdoc.setDocumentArchive(prevArchive); 26: context.getWiki().saveDocument(fdoc, context); 27: if (prevDoc.isNew()) { 28: fdoc.resetArchive(context); 29: } 30: return 1; 31: } else { 32: def pack = new Package() 33: if ((type=="NOOVERVERSIONS")||(type=="OVERVERSIONS")) 34: pack.setWithVersions(true) 35: else 36: pack.setWithVersions(false) 37: pack.setBackupPack(true) 38: pack.add(fdoc, 0, context) 39: return pack.install(context) 40: } 41: } else { 42: return -1000; 43: } 44: } 45: 46: if (request.get("name")!=null) { 47: def fupl= xwiki.get("fileupload"); 48: def myfiles = fupl.getFileItems(); 49: def xml = fupl.getFileItem("file"); 50: def fName = fupl.getFileName("file"); 51: def docName = fupl.getFileItem("name"); 52: def type = fupl.getFileItem("type"); 53: def ret = updateDoc(docName, xml, type, context.context); 54: if (ret < 0) { 55: if (ret==-1000) 56: println "Document already exists and overwrite was not specified."; 57: else 58: println "Document could not be imported with error ${ret}."; 59: } else { 60: println "Document has been imported properly: [${finalPageName}]." 61: } 62: } else { 63: %> 64: <form action="" enctype="multipart/form-data" method="post"> 65: <table border="0"> 66: <tr> 67: <td>Page Name to save to:</td><td><input type="text" name="name" size="60" /></td> 68: </tr> 69: <tr> 70: <td>Type:</td><td> 71: <input type="radio" name="type" value="NOOVERVERSIONS" checked /> Do Not overwrite with versions 72: <input type="radio" name="type" value="NOOVERNOVERSIONS" /> Do Not overwrite without versions 73: <br /> 74: <input type="radio" name="type" value="ADDVERSION" /> Add version 75: <input type="radio" name="type" value="OVERVERSIONS" /> Overwrite with version 76: <input type="radio" name="type" value="OVERNOVERSIONS" /> Overwrite without versions </td> 77: </tr> 78: <tr> 79: <td>File:</td><td><input type="file" name="file" size="60" /></td> 80: </tr> 81: <tr> 82: <td colspan="2" align="center"> 83: <input type="submit" name="Import" /> 84: </td> 85: </tr> 86: </table> 87: </form> 88: <% 89: } 90: %>
Welcome
Welcome to this XWiki!
Quick Links
DSSF 2008
DCNM 2009
HCCF 2010
Document Index
Sandbox
My Recent Modifications
ASSIGNMENTNAME