General Actions:
Log-in
Wiki:
CreativeIT
▼
:
Document Index
»
Space:
Main
▼
:
Document Index
»
Page:
migration
Search
Page Actions:
Export
▼
:
Export as PDF
Export as RTF
Export as HTML
More actions
▼
:
Print preview
View Source
migration
Wiki source code of
migration
Last modified by
Hal Eden
on 2009/04/17 09:39
Content
·
Comments
(0)
·
Attachments
(1)
·
History
·
Information
Show line numbers
<% import org.xwiki.xml.html.HTMLCleaner import org.xwiki.xml.internal.html.DefaultHTMLCleaner import java.io.StringReader import org.xwiki.component.manager.ComponentManager import com.xpn.xwiki.web.Utils import org.xwiki.xml.XMLUtils import org.xwiki.rendering.parser.Syntax import org.xwiki.rendering.parser.SyntaxType import org.xwiki.rendering.parser.SyntaxFactory import org.xwiki.rendering.parser.Parser import org.xwiki.rendering.internal.parser.WikiModelXHTMLParser import org.wikimodel.wem.IWikiParser import org.xwiki.officeimporter.internal.DefaultOfficeImporter import org.xwiki.rendering.block.XDOM; import org.xwiki.rendering.listener.Listener; import org.xwiki.rendering.renderer.printer.DefaultWikiPrinter; import org.xwiki.rendering.renderer.printer.WikiPrinter; import org.xwiki.rendering.parser.ParseException; import org.xwiki.officeimporter.OfficeImporterException; import org.xwiki.rendering.renderer.PrintRendererFactory; import org.xwiki.bridge.DocumentAccessBridge; import org.htmlcleaner.Utils import java.net.URL import java.net.URLConnection import org.xwiki.rendering.block.LinkBlock import org.xwiki.rendering.block.ImageBlock import org.xwiki.rendering.block.SpaceBlock import org.xwiki.rendering.block.HeaderBlock import org.xwiki.rendering.block.FormatBlock import java.io.InputStream import java.io.ByteArrayInputStream import org.xwiki.rendering.block.ImageBlock import org.xwiki.rendering.listener.DocumentImage import org.xwiki.rendering.listener.Image import org.xwiki.rendering.listener.DefaultAttachement def byte[] getBinaryURLContent(URL url) { def InputStream inp try { def URLConnection conn = url.openConnection() //return conn.content.text.bytes def length = conn.getContentLength() if (length > 5000000) { println "{code}" println "file too large: " + length + "--should transfer by hand: " + url //println "\#warning(file too large: \"" + length + "\"--should transfer by hand)" println "{code}" if (inp != null) { inp.close() } return "" } inp = new BufferedInputStream(conn.getInputStream()) def ByteArrayOutputStream bout = new ByteArrayOutputStream() def b = new byte[1024] def int n while ((n = inp.read(b, 0, 1024)) != -1) { bout.write(b, 0, n) } return bout.toByteArray() } catch (Exception ex) { if (inp != null) {inp.close()} println "{code}"+"can't download url: "+ ex + "{code}" return "" } finally { if (inp != null) { inp.close() } } } def noaccent(txt) { temp = txt.replaceAll(/[\u00c0\u00c1\u00c2\u00c3\u00c4\u00c5\u0100\u0102\u0104\u01cd\u01de\u01e0\u01fa\u0200\u0202\u0226]/,"A"); temp = temp.replaceAll(/[\u00e0\u00e1\u00e2\u00e3\u00e4\u00e5\u0101\u0103\u0105\u01ce\u01df\u01e1\u01fb\u0201\u0203\u0227]/,"a"); temp = temp.replaceAll(/[\u00c6\u01e2\u01fc]/,"AE"); temp = temp.replaceAll(/[\u00e6\u01e3\u01fd]/,"ae"); temp = temp.replaceAll(/[\u008c\u0152]/,"OE"); temp = temp.replaceAll(/[\u009c\u0153]/,"oe"); temp = temp.replaceAll(/[\u00c7\u0106\u0108\u010a\u010c]/,"C"); temp = temp.replaceAll(/[\u00e7\u0107\u0109\u010b\u010d]/,"c"); temp = temp.replaceAll(/[\u00d0\u010e\u0110]/,"D"); temp = temp.replaceAll(/[\u00f0\u010f\u0111]/,"d"); temp = temp.replaceAll(/[\u00c8\u00c9\u00ca\u00cb\u0112\u0114\u0116\u0118\u011a\u0204\u0206\u0228]/,"E"); temp = temp.replaceAll(/[\u00e8\u00e9\u00ea\u00eb\u0113\u0115\u0117\u0119\u011b\u01dd\u0205\u0207\u0229]/,"e"); temp = temp.replaceAll(/[\u011c\u011e\u0120\u0122\u01e4\u01e6\u01f4]/,"G"); temp = temp.replaceAll(/[\u011d\u011f\u0121\u0123\u01e5\u01e7\u01f5]/,"g"); temp = temp.replaceAll(/[\u0124\u0126\u021e]/,"H"); temp = temp.replaceAll(/[\u0125\u0127\u021f]/,"h"); temp = temp.replaceAll(/[\u00cc\u00cd\u00ce\u00cf\u0128\u012a\u012c\u012e\u0130\u01cf\u0208\u020a]/,"I"); temp = temp.replaceAll(/[\u00ec\u00ed\u00ee\u00ef\u0129\u012b\u012d\u012f\u0131\u01d0\u0209\u020b]/,"i"); temp = temp.replaceAll(/[\u0132]/,"IJ"); temp = temp.replaceAll(/[\u0133]/,"ij"); temp = temp.replaceAll(/[\u0134]/,"J"); temp = temp.replaceAll(/[\u0135]/,"j"); temp = temp.replaceAll(/[\u0136\u01e8]/,"K"); temp = temp.replaceAll(/[\u0137\u0138\u01e9]/,"k"); temp = temp.replaceAll(/[\u0139\u013b\u013d\u013f\u0141]/,"L"); temp = temp.replaceAll(/[\u013a\u013c\u013e\u0140\u0142\u0234]/,"l"); temp = temp.replaceAll(/[\u00d1\u0143\u0145\u0147\u014a\u01f8]/,"N"); temp = temp.replaceAll(/[\u00f1\u0144\u0146\u0148\u0149\u014b\u01f9\u0235]/,"n"); temp = temp.replaceAll(/[\u00d2\u00d3\u00d4\u00d5\u00d6\u00d8\u014c\u014e\u0150\u01d1\u01ea\u01ec\u01fe\u020c\u020e\u022a\u022c\u022e\u0230]/,"O"); temp = temp.replaceAll(/[\u00f2\u00f3\u00f4\u00f5\u00f6\u00f8\u014d\u014f\u0151\u01d2\u01eb\u01ed\u01ff\u020d\u020f\u022b\u022d\u022f\u0231]/,"o"); temp = temp.replaceAll(/[\u0156\u0158\u0210\u0212]/,"R"); temp = temp.replaceAll(/[\u0157\u0159\u0211\u0213]/,"r"); temp = temp.replaceAll(/[\u015a\u015c\u015e\u0160\u0218]/,"S"); temp = temp.replaceAll(/[\u015b\u015d\u015f\u0161\u0219]/,"s"); temp = temp.replaceAll(/[\u00de\u0162\u0164\u0166\u021a]/,"T"); temp = temp.replaceAll(/[\u00fe\u0163\u0165\u0167\u021b\u0236]/,"t"); temp = temp.replaceAll(/[\u00d9\u00da\u00db\u00dc\u0168\u016a\u016c\u016e\u0170\u0172\u01d3\u01d5\u01d7\u01d9\u01db\u0214\u0216]/,"U"); temp = temp.replaceAll(/[\u00f9\u00fa\u00fb\u00fc\u0169\u016b\u016d\u016f\u0171\u0173\u01d4\u01d6\u01d8\u01da\u01dc\u0215\u0217]/,"u"); temp = temp.replaceAll(/[\u0174]/,"W"); temp = temp.replaceAll(/[\u0175]/,"w"); temp = temp.replaceAll(/[\u00dd\u0176\u0178\u0232]/,"Y"); temp = temp.replaceAll(/[\u00fd\u00ff\u0177\u0233]/,"y"); temp = temp.replaceAll(/[\u0179\u017b\u017d]/,"Z"); temp = temp.replaceAll(/[\u017a\u017c\u017e]/,"z"); temp = temp.replaceAll(/[\u00df]/,"SS"); temp = temp.replaceAll(/[\[\]>'":.?\/+&]/,"-"); return temp; } import java.util.StringTokenizer import java.util.Map import java.util.HashMap import com.xpn.xwiki.doc.XWikiAttachment import com.xpn.xwiki.api.XWiki def loadfile(filename) { def attachmentName = filename def attachment = doc.getAttachment(attachmentName) if (!attachment){ println "file not found." } else { def content = attachment.getContentAsString() def reader = new BufferedReader(new StringReader(content)) def users = [] def thisLine def map = [:] def userListStr def pagenum def pagename def username def firstname def lastname def spacename try { while ((thisLine = reader.readLine()) != null) { userListStr = thisLine.split("\t") pagenum = userListStr[0] pagename = userListStr[1] if (userListStr.length > 2) { username = userListStr[2] } else { username = "" } if (userListStr.length > 3) { firstname = userListStr[3] } else { firstname = "" } if (userListStr.length > 4) { lastname = userListStr[4] } else { lastname = "" } if (userListStr.length > 5) { spacename = userListStr[5] } else { spacename = "" } if (userListStr.length > 6) { parent = userListStr[6] } else { parent = ""} map.put(pagenum, [pagename: pagename, username: username, firstname: firstname, lastname: lastname, spacename: spacename, parent: parent ]) } println "{code}" println map println "{code}" out.flush() } catch (Exception e) { println("Error: " + e) } return map } } def HTMLCleaner ooHtmlCleaner = (HTMLCleaner) com.xpn.xwiki.web.Utils.getComponentManager().lookup(HTMLCleaner.ROLE, "wysiwyg") def Syntax XWIKI_20 = new Syntax(SyntaxType.XWIKI, "2.0"); def Syntax XHTML_10 = new Syntax(SyntaxType.XHTML, "1.0"); def PrintRendererFactory rendererFactory = (PrintRendererFactory) com.xpn.xwiki.web.Utils.getComponentManager().lookup(PrintRendererFactory.ROLE) def Parser xHtmlParser = (Parser) com.xpn.xwiki.web.Utils.getComponentManager().lookup(Parser.ROLE, "xhtml/1.0") def DocumentAccessBridge docBridge = (DocumentAccessBridge) com.xpn.xwiki.web.Utils.getComponentManager().lookup(DocumentAccessBridge.ROLE) def targetWikiDocument = "XWiki.gtestout" def pmap def space def pagetoload = "" // not a number, but a string of numerals representing one pagetoload = 272..291 if (xwiki.hasAdminRights()){ try { if(request.get("test") != null) { def map = loadfile("pagemap.txt") def pagestoprocess = map if (pagetoload != null && pagetoload != "") { if (pagetoload instanceof java.util.List) { pagestoprocess = [:] for (page in pagetoload) { pagestoprocess.put(page.toString(), map.get(page.toString())) } } else { pagestoprocess = [:] pagestoprocess.put(pagetoload, map.get(pagetoload)) } } for (page in pagestoprocess) { def pnumtoload = page.key System.err.println "migration: page number: "+ pnumtoload if (pnumtoload ==~ /[0-9]*/){ //make sure we have page number pmap = map.get(pnumtoload) } def username = map.get(pnumtoload).get("username") if (username=="") { space = pmap.get("spacename") if (space == "") {space = "Main"} targetWikiDocument=space+"."+noaccent(map.get(pnumtoload).get("pagename")) } else { targetWikiDocument="XWiki."+noaccent(username) } println "["+targetWikiDocument+"]" def java.net.URL url = new java.net.URL( "http://swiki.cs.colorado.edu/CreativeIT/"+pnumtoload+".print") println "{code}" println url println "{code}" StringBuffer content = org.htmlcleaner.Utils.readUrl(url, System.getProperty("file.encoding")); String htmlContent = content.toString() // for some reason, the parser elides spaces after links and formats if there are cr & lf (maybe one or other)--works fine if we remove them Reader reader = new StringReader( htmlContent.replaceAll(/[\n\r]/, "") ); /* //******** testString ='<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html><head><title>new page</title><link rel=stylesheet href="/CreativeIT/uploads/style.css" type="text/css"><script type="text/javascript" src="/schemesAni/black/scripts.js" charset="ISO-8859-1"></script></head><body class="print"><h2>new page</h2><b>Hal Eden</b> is blah blah blah<br></body></html>' def testString ='<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">\r\n<html>\r\n<head>\r\n<title>new page</title>\r\n<link rel=stylesheet href="/CreativeIT/uploads/style.css" type="text/css">\r\n<script type="text/javascript" src="/schemesAni/black/scripts.js" charset="ISO-8859-1"></script>\r\n</head>\r\n<body class="print">\r\n<h2>new page</h2>\r\n<b>Hal Eden</b> is blah blah blah<br>\r\n\r\n</body>\r\n</html>\r\n' //def offset = testString.compareTo(htmlContent) //def count = 0 //def len = [testString.size(), htmlContent.size()].min() //while (count < len) { // if (testString.charAt(count) != htmlContent.charAt(count) ) { break } // count ++ //} //println "{code}" //println offset //println count //println len //println testString.charAt(offset) //println htmlContent.charAt(offset) //println testString.substring(0) //println htmlContent.substring(0) //println "{code}" */ //reader = new StringReader(testString.replaceAll(/[\n\r]/, "")) /* // println "{code}" // println htmlContent // println "{code}" */ //******** def options = ["filterStyles":"none"] def xhtmlDoc = ooHtmlCleaner.clean(reader)//, options) XMLUtils.stripHTMLEnvelope(xhtmlDoc); // unfortunately, convert is private, so we steal some of it here // def String xwikiCode = DefaultOfficeImporter.convert((Reader) new StringReader( XMLUtils.toString(xhtmlDoc)), // (Parser) xHtmlParser, (Syntax) XWIKI_20); def String xhtmlstring = XMLUtils.toString(xhtmlDoc) def XDOM xdom = xHtmlParser.parse(new StringReader(xhtmlstring)); // // def XDOM xdom = xHtmlParser.parse(new StringReader(htmlContent)); //********** // printer = new DefaultWikiPrinter() // listener = rendererFactory.createRenderer(XWIKI_20, printer) // xdom.traverse(listener); // println "{code}" // println printer.toString(); // println "{code}" //********** SyntaxFactory syntaxFactory = (SyntaxFactory) com.xpn.xwiki.web.Utils.getComponentManager().lookup(SyntaxFactory.ROLE); def WikiPrinter printer = new DefaultWikiPrinter() def Listener listener = rendererFactory.createRenderer(XWIKI_20, printer) def List anchors = xdom.getChildrenByType(LinkBlock.class, true) def List images = xdom.getChildrenByType(ImageBlock.class, true) def List headers = xdom.getChildrenByType(HeaderBlock.class, true) def List formats = xdom.getChildrenByType(FormatBlock.class, true) // need to fix up some problems created by ?parser? // we are missing spaces after formats and anchors // want to get rid of "title" entry for document if (headers != null) { headers.get(0).replace([SpaceBlock.SPACE_BLOCK]) } // println("------") def filename def avatarfilename = "" def avatarurl = "" def url2 images = xdom.getChildrenByType(ImageBlock.class, true) // println "{code} images" // println images if (images != null && images != []) { //are there any images for (imageitem in images) { def image = imageitem.getImage() if (image.class == DocumentImage) { //image as document attachment def attach = image.getAttachmentName() if (attach != null) { //do we have an attachment for the image //println attach filename = attach.substring(attach.lastIndexOf("/")+1) def attachpagenum = attach =~ /.*?uploads\/([0-9]*)\// //println attachpagenum.size() if (attachpagenum != null && attachpagenum != [] && attachpagenum.size() > 0){ //println attachpagenum //println attachpagenum[0] attachpagenum = attachpagenum[0][1] def attpmap = map.get(attachpagenum) def attspace = attpmap.get("spacename") def uname = attpmap.get("username") if (attspace == "") { if (uname == "") {attspace = "Main"} else {attspace = "XWiki"}} def attachdocname = attspace+"."+noaccent(map.get(attachpagenum).get("pagename")) url2 = new java.net.URL( url.getProtocol(), url.getHost(), url.getPort(), attach) //println "url2: " + url2 if (username !="" && avatarfilename == "") { // we don't have an avatar yet, but first check for the real image in an anchor rather than reduced one swiki created if (anchors != null && anchors != []) { //check the first anchor for an image def anchorlink = anchors.get(0).getLink() def anchorpath = anchorlink.getReference() if (anchorpath.indexOf("/CreativeIT/") >= 0) { // is it relative to the server? def anchorfilename = anchorpath.substring(anchorpath.lastIndexOf("/")+1) def dotpos = anchorfilename.indexOf(".") if (dotpos > 0 && dotpos < filename.size() && filename.substring(0, dotpos - 1) == anchorfilename.substring(0, dotpos - 1)) { avatarfilename = anchorfilename avatarurl = new java.net.URL( url.getProtocol(), url.getHost(), url.getPort(), anchorpath) anchors.get(0).replace([SpaceBlock.SPACE_BLOCK.clone()]) } } } if (avatarfilename == ""){ avatarfilename = filename avatarurl = url2 imageitem.replace([SpaceBlock.SPACE_BLOCK.clone()]) } } else { if (attachpagenum == pnumtoload){ imageitem.replace( [new ImageBlock((Image) new DocumentImage(new DefaultAttachement( targetWikiDocument, filename)), false)]) docBridge.setAttachmentContent(targetWikiDocument, filename, getBinaryURLContent(url2)) //doc.addAttachment(filename, url2.openStream()) } else { imageitem.replace( [new ImageBlock((Image) new DocumentImage(new DefaultAttachement( attachdocname, filename)), false)]) docBridge.setAttachmentContent(attachdocname, filename, getBinaryURLContent(url2)); } } } } // do we have attachment for image } else { // assume it is a URLImage--don't really have to do anything, leave ref def imageurl = image.getURL() //println "imageurl: "+imageurl } } } //println "anchors" // need to rescan anchors cause we might have changed them anchors = xdom.getChildrenByType(LinkBlock.class, true); /* for ( anchor in anchors ){ link = anchor.getLink() path = link.getReference() if (path.indexOf('/CreativeIT')>=0) { if( path.indexOf('uploads')>=0) { def fn = path.substring(path.lastIndexOf("/")+1) link.setReference("attach:"+fn) def lurl = new java.net.URL( url.getProtocol(), url.getHost(), url.getPort(), path) if (avatarfilename == "") { avatarfilename = fn avatarurl = lurl } } } } */ //anchors = xdom.getChildrenByType(LinkBlock.class, true); //println "{code}anchors:" for ( anchor in anchors ){ //def newmap = new HashMap(anchor.getParameters()) //newmap.remove("title") //println newmap //anchor.setParameters(newmap) anchor.setParameter("title","") link = anchor.getLink() path = link.getReference() //println "found path: " + path if (path.indexOf('http:') <0) { if (path.indexOf('/CreativeIT')==0) { if( path.indexOf('uploads')>=0) { def fn = path.substring(path.lastIndexOf("/")+1) //println "link to "+fn+": "+path def lurl = new java.net.URL( url.getProtocol(), url.getHost(), url.getPort(), path) link.setReference("attach:"+fn) docBridge.setAttachmentContent(targetWikiDocument, fn, getBinaryURLContent(lurl)); // docBridge.getDocument().addAttachment( fn, lurl.openStream(), context.getContext()); } else { //def attachpagenum = (path.substring(path.lastIndexOf("/")+1))=~/([0-9]*)/ def attachpagenum = path.substring(path.lastIndexOf("/")+1) //if (attachpagenum != null && attachpagenum != [] && attachpagenum.size() > 0){ //attachpagenum = attachpagenum[0][1] if (attachpagenum ==~ /[0-9]*/){ println attachpagenum def attpmap = map.get(attachpagenum) def attspace = attpmap.get("spacename") def uname = attpmap.get("username") if (attspace == "") { if (uname == "") {attspace = "Main"} else {attspace = "XWiki"}} def pname if (attpmap != null) { //do we have a page entry in map // println pmap if( attpmap.get("username") == "") { pname = attspace+"."+noaccent(attpmap.get("pagename")) } else { pname = attspace+"."+noaccent(attpmap.get("username")) } //println path + ":" + pname link.setReference(pname) } //do we have a page entry in map } //make sure we have a page number } } } } //println "{code}" //println "{code}" //def patterns = content =~ /\/CreativeIT(\/uploads){0}\/([0-9]+)/ //println "{code} patterns:" //for (pattern in patterns){ // println pattern //} //println "{code}" if (username == "") { println "{code}" println "no username" println "{code}" out.flush() } else { println "{code}" println "username" /* images = xdom.getChildrenByType(ImageBlock.class, true) if (images != null && images != []) { //are there any images //println images def imageitem = images.get(0) //println imageitem def image = imageitem.getImage() //println image if (image.class == DocumentImage) { //image as document attachment def attach = image.getAttachmentName() //println attach if (attach != null) { //do we have an attachment for the image filename = attach.substring(attach.lastIndexOf("/")+1) //images.get(0).replace( [new ImageBlock((Image) new DocumentImage(new DefaultAttachement(targetWikiDocument, filename)), false)]) imageitem.replace( [SpaceBlock.SPACE_BLOCK.clone()]) url2 = new java.net.URL( url.getProtocol(), url.getHost(), url.getPort(), attach) } else { filename = "" url2 = "" } } else { // assume it is a URLImage--don't really have to do anything, leave ref def imageurl = image.getURL() //println "imageurl: "+imageurl } } else { // there are noimages // println "first image not appropriate" } //checking images */ /* if (filename == null || filename == "") { // no filename yet if (anchors != null && anchors != []) { //check the first anchor for an image def link = anchors.get(0).getLink() //println link def path = link.getReference() //println path if (path.indexOf("/CreativeIT/") >= 0) { // is it relative to the server? filename = path.substring(path.lastIndexOf("/")+1) //println filename link.setReference("attach:"+filename) url2 = new java.net.URL( url.getProtocol(), url.getHost(), url.getPort(), path) //println(url2.toString()) //anchors.get(0).replace([SpaceBlock.SPACE_BLOCK]) } // relative to server } } // end no file name yet */ println "{code}" } //username or not printer = new DefaultWikiPrinter() listener = rendererFactory.createRenderer(XWIKI_20, printer) xdom.traverse(listener); xwikiCode = printer.toString(); // println "{code} xwikiCode" //println xwikiCode // println "{code}" out.flush() def doc = xwiki.getDocument(targetWikiDocument) def mdoc = doc.getDocument() println "{code}" //println pmap println "{code}" def parent = pmap.get("parent") println parent if (parent != ""){ def parentpmap = map.get(parent) def parspace = parentpmap.get("spacename") def uname = parentpmap.get("username") if (parspace == "") { if (uname == "") {parspace = "Main"} else {parspace = "XWiki"}} def pname if (parentpmap != null) { //do we have a page entry in map if ( parentpmap.get("username") == "") { pname = parspace+"."+noaccent(parentpmap.get("pagename")) } else { pname = parspace+"."+noaccent(parentpmap.get("username")) } doc.setParent(pname) println "parent: "+pname doc.save() } } docBridge.setDocumentSyntaxId(targetWikiDocument, XWIKI_20.toIdString()); //mdoc.setSyntaxId(XWIKI_20.toIdString()); if (username == "") { if (space == "ASU Workshop") { def Reader asureader = new StringReader( htmlContent ); def asuxhtmlDoc = ooHtmlCleaner.clean(asureader)//, options) XMLUtils.stripHTMLEnvelope(asuxhtmlDoc); def String asuxhtmlstring = XMLUtils.toString(xhtmlDoc) def newcontent = ((String) htmlContent).replaceAll( /\/CreativeIT(\/uploads){0}\/([0-9]+)/, {match,group1, group2 -> "/xwiki/bin/view/"+space+"/"+noaccent(map.get(group2).get("pagename"))}) newcontent = newcontent.replaceAll( /http:\/\/swiki.cs.colorado.edu:3232/, {match->""}) newcontent = newcontent.replaceAll( /\/CreativeIT(\/uploads){1}\/([0-9]+)/, {match,group1, group2 ->"/xwiki/bin/download/"+space+"/"+noaccent(map.get(group2).get("pagename"))}) newcontent = newcontent.replaceAll( /<!DOCTYPE.*>/, {match -> ""}) newcontent = newcontent.replaceAll( /(?s)<head.*<\/head>/, {match -> ""}) //doc.setContent("{{html}}"+htmlContent+"{{/html}}") docBridge.setDocumentContent( targetWikiDocument, "{{html}}"+newcontent+"{{/html}}", "Content created by swiki importer", false); } else { def WikiPrinter newprinter = new DefaultWikiPrinter(); def Listener newlistener = rendererFactory.createRenderer(XWIKI_20, newprinter); xdom.traverse(newlistener); xwikiCode = newprinter.toString(); //println "{code}" //println xwikiCode //println "{code}" //doc.setContent(xwikiCode) docBridge.setDocumentContent( targetWikiDocument, xwikiCode, "Content created by swiki importer", false); } //println "{code}" //println newcontent //println "{code}" //doc.save() //doc.getDocument().saveAllAttachments(context.getContext()) } else { // username not blank //doc.setContent("{{include document=\"XWiki.XWikiUserSheet\"/}}\n"+xwikiCode) docBridge.setDocumentContent( targetWikiDocument, "{{include document=\"XWiki.XWikiUserSheet\"/}}\n"+xwikiCode, "Content created by swiki importer", false); //println "{code}" //println filename + ":" + url2 //println "{code}" if (avatarfilename != "" && avatarfilename != null) { //doc.addAttachment(filename, getBinaryURLContent(url2)) //doc.addAttachment(filename, url2.openStream()) docBridge.setAttachmentContent(targetWikiDocument, avatarfilename, getBinaryURLContent(avatarurl)); //docBridge.setAttachmentContent(targetWikiDocument, filename2, getBinaryURLContent(url3)); } //def doc = docBridge.getDocument(targetWikiDocument) def userObj = doc.getObject("XWiki.XWikiUsers") if (userObj == null) { //println "no obj, creating one" doc.createNewObject("XWiki.XWikiUsers") userObj = doc.getObject("XWiki.XWikiUsers") } //println "{code}" //println userObj //println "{code}" userObj.getBaseObject().setStringValue("avatar", avatarfilename) userObj.getBaseObject().setStringValue("first_name", map.get(pnumtoload).get("firstname")) userObj.getBaseObject().setStringValue("last_name", map.get(pnumtoload).get("lastname")) //userObj.set("comment", xwikiCode, context.getContext()) doc.save() //doc.getDocument().saveAllAttachments(context.getContext()) } // user is blank or not } // for page in map } else { // request != test println "[run test>" + doc.fullName + "?test=1]\n" } } catch (Exception e) { println "{code} Error: " println e.printStackTrace(out) + "{code}"} }//admin rights %>
Quick Links
Home
Index
What's New
Blog
Calendar
Photo Albums
Sandbox
Tags
Bulletin Board
My Recent Modifications
PamelaJennings
|
rwakkary
|
HaledenSands
|
ByronLahey