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
Hide line numbers
1: <% 2: import org.xwiki.xml.html.HTMLCleaner 3: import org.xwiki.xml.internal.html.DefaultHTMLCleaner 4: import java.io.StringReader 5: import org.xwiki.component.manager.ComponentManager 6: import com.xpn.xwiki.web.Utils 7: import org.xwiki.xml.XMLUtils 8: import org.xwiki.rendering.parser.Syntax 9: import org.xwiki.rendering.parser.SyntaxType 10: import org.xwiki.rendering.parser.SyntaxFactory 11: import org.xwiki.rendering.parser.Parser 12: import org.xwiki.rendering.internal.parser.WikiModelXHTMLParser 13: import org.wikimodel.wem.IWikiParser 14: import org.xwiki.officeimporter.internal.DefaultOfficeImporter 15: import org.xwiki.rendering.block.XDOM; 16: import org.xwiki.rendering.listener.Listener; 17: import org.xwiki.rendering.renderer.printer.DefaultWikiPrinter; 18: import org.xwiki.rendering.renderer.printer.WikiPrinter; 19: import org.xwiki.rendering.parser.ParseException; 20: import org.xwiki.officeimporter.OfficeImporterException; 21: import org.xwiki.rendering.renderer.PrintRendererFactory; 22: import org.xwiki.bridge.DocumentAccessBridge; 23: import org.htmlcleaner.Utils 24: import java.net.URL 25: import java.net.URLConnection 26: import org.xwiki.rendering.block.LinkBlock 27: import org.xwiki.rendering.block.ImageBlock 28: import org.xwiki.rendering.block.SpaceBlock 29: import org.xwiki.rendering.block.HeaderBlock 30: import org.xwiki.rendering.block.FormatBlock 31: import java.io.InputStream 32: import java.io.ByteArrayInputStream 33: import org.xwiki.rendering.block.ImageBlock 34: import org.xwiki.rendering.listener.DocumentImage 35: import org.xwiki.rendering.listener.Image 36: import org.xwiki.rendering.listener.DefaultAttachement 37: 38: 39: def byte[] getBinaryURLContent(URL url) { 40: def InputStream inp 41: try { 42: def URLConnection conn = url.openConnection() 43: //return conn.content.text.bytes 44: 45: def length = conn.getContentLength() 46: if (length > 5000000) { 47: println "{code}" 48: println "file too large: " + length + "--should transfer by hand: " + url 49: //println "\#warning(file too large: \"" + length + "\"--should transfer by hand)" 50: println "{code}" 51: if (inp != null) { inp.close() } 52: return "" 53: } 54: 55: inp = new BufferedInputStream(conn.getInputStream()) 56: def ByteArrayOutputStream bout = new ByteArrayOutputStream() 57: def b = new byte[1024] 58: def int n 59: while ((n = inp.read(b, 0, 1024)) != -1) { 60: bout.write(b, 0, n) 61: } 62: return bout.toByteArray() 63: 64: } catch (Exception ex) { 65: if (inp != null) {inp.close()} 66: println "{code}"+"can't download url: "+ ex + "{code}" 67: return "" 68: } finally { if (inp != null) { inp.close() } } 69: } 70: 71: def noaccent(txt) { 72: temp = txt.replaceAll(/[\u00c0\u00c1\u00c2\u00c3\u00c4\u00c5\u0100\u0102\u0104\u01cd\u01de\u01e0\u01fa\u0200\u0202\u0226]/,"A"); 73: temp = temp.replaceAll(/[\u00e0\u00e1\u00e2\u00e3\u00e4\u00e5\u0101\u0103\u0105\u01ce\u01df\u01e1\u01fb\u0201\u0203\u0227]/,"a"); 74: temp = temp.replaceAll(/[\u00c6\u01e2\u01fc]/,"AE"); 75: temp = temp.replaceAll(/[\u00e6\u01e3\u01fd]/,"ae"); 76: temp = temp.replaceAll(/[\u008c\u0152]/,"OE"); 77: temp = temp.replaceAll(/[\u009c\u0153]/,"oe"); 78: temp = temp.replaceAll(/[\u00c7\u0106\u0108\u010a\u010c]/,"C"); 79: temp = temp.replaceAll(/[\u00e7\u0107\u0109\u010b\u010d]/,"c"); 80: temp = temp.replaceAll(/[\u00d0\u010e\u0110]/,"D"); 81: temp = temp.replaceAll(/[\u00f0\u010f\u0111]/,"d"); 82: temp = temp.replaceAll(/[\u00c8\u00c9\u00ca\u00cb\u0112\u0114\u0116\u0118\u011a\u0204\u0206\u0228]/,"E"); 83: temp = temp.replaceAll(/[\u00e8\u00e9\u00ea\u00eb\u0113\u0115\u0117\u0119\u011b\u01dd\u0205\u0207\u0229]/,"e"); 84: temp = temp.replaceAll(/[\u011c\u011e\u0120\u0122\u01e4\u01e6\u01f4]/,"G"); 85: temp = temp.replaceAll(/[\u011d\u011f\u0121\u0123\u01e5\u01e7\u01f5]/,"g"); 86: temp = temp.replaceAll(/[\u0124\u0126\u021e]/,"H"); 87: temp = temp.replaceAll(/[\u0125\u0127\u021f]/,"h"); 88: temp = temp.replaceAll(/[\u00cc\u00cd\u00ce\u00cf\u0128\u012a\u012c\u012e\u0130\u01cf\u0208\u020a]/,"I"); 89: temp = temp.replaceAll(/[\u00ec\u00ed\u00ee\u00ef\u0129\u012b\u012d\u012f\u0131\u01d0\u0209\u020b]/,"i"); 90: temp = temp.replaceAll(/[\u0132]/,"IJ"); 91: temp = temp.replaceAll(/[\u0133]/,"ij"); 92: temp = temp.replaceAll(/[\u0134]/,"J"); 93: temp = temp.replaceAll(/[\u0135]/,"j"); 94: temp = temp.replaceAll(/[\u0136\u01e8]/,"K"); 95: temp = temp.replaceAll(/[\u0137\u0138\u01e9]/,"k"); 96: temp = temp.replaceAll(/[\u0139\u013b\u013d\u013f\u0141]/,"L"); 97: temp = temp.replaceAll(/[\u013a\u013c\u013e\u0140\u0142\u0234]/,"l"); 98: temp = temp.replaceAll(/[\u00d1\u0143\u0145\u0147\u014a\u01f8]/,"N"); 99: temp = temp.replaceAll(/[\u00f1\u0144\u0146\u0148\u0149\u014b\u01f9\u0235]/,"n"); 100: temp = temp.replaceAll(/[\u00d2\u00d3\u00d4\u00d5\u00d6\u00d8\u014c\u014e\u0150\u01d1\u01ea\u01ec\u01fe\u020c\u020e\u022a\u022c\u022e\u0230]/,"O"); 101: temp = temp.replaceAll(/[\u00f2\u00f3\u00f4\u00f5\u00f6\u00f8\u014d\u014f\u0151\u01d2\u01eb\u01ed\u01ff\u020d\u020f\u022b\u022d\u022f\u0231]/,"o"); 102: temp = temp.replaceAll(/[\u0156\u0158\u0210\u0212]/,"R"); 103: temp = temp.replaceAll(/[\u0157\u0159\u0211\u0213]/,"r"); 104: temp = temp.replaceAll(/[\u015a\u015c\u015e\u0160\u0218]/,"S"); 105: temp = temp.replaceAll(/[\u015b\u015d\u015f\u0161\u0219]/,"s"); 106: temp = temp.replaceAll(/[\u00de\u0162\u0164\u0166\u021a]/,"T"); 107: temp = temp.replaceAll(/[\u00fe\u0163\u0165\u0167\u021b\u0236]/,"t"); 108: temp = temp.replaceAll(/[\u00d9\u00da\u00db\u00dc\u0168\u016a\u016c\u016e\u0170\u0172\u01d3\u01d5\u01d7\u01d9\u01db\u0214\u0216]/,"U"); 109: temp = temp.replaceAll(/[\u00f9\u00fa\u00fb\u00fc\u0169\u016b\u016d\u016f\u0171\u0173\u01d4\u01d6\u01d8\u01da\u01dc\u0215\u0217]/,"u"); 110: temp = temp.replaceAll(/[\u0174]/,"W"); 111: temp = temp.replaceAll(/[\u0175]/,"w"); 112: temp = temp.replaceAll(/[\u00dd\u0176\u0178\u0232]/,"Y"); 113: temp = temp.replaceAll(/[\u00fd\u00ff\u0177\u0233]/,"y"); 114: temp = temp.replaceAll(/[\u0179\u017b\u017d]/,"Z"); 115: temp = temp.replaceAll(/[\u017a\u017c\u017e]/,"z"); 116: temp = temp.replaceAll(/[\u00df]/,"SS"); 117: temp = temp.replaceAll(/[\[\]>'":.?\/+&]/,"-"); 118: return temp; 119: } 120: 121: import java.util.StringTokenizer 122: import java.util.Map 123: import java.util.HashMap 124: import com.xpn.xwiki.doc.XWikiAttachment 125: import com.xpn.xwiki.api.XWiki 126: 127: def loadfile(filename) { 128: def attachmentName = filename 129: def attachment = doc.getAttachment(attachmentName) 130: if (!attachment){ 131: println "file not found." 132: } else { 133: def content = attachment.getContentAsString() 134: def reader = new BufferedReader(new StringReader(content)) 135: def users = [] 136: def thisLine 137: def map = [:] 138: def userListStr 139: def pagenum 140: def pagename 141: def username 142: def firstname 143: def lastname 144: def spacename 145: try { 146: while ((thisLine = reader.readLine()) != null) { 147: userListStr = thisLine.split("\t") 148: pagenum = userListStr[0] 149: pagename = userListStr[1] 150: if (userListStr.length > 2) { username = userListStr[2] } else { username = "" } 151: if (userListStr.length > 3) { firstname = userListStr[3] } else { firstname = "" } 152: if (userListStr.length > 4) { lastname = userListStr[4] } else { lastname = "" } 153: if (userListStr.length > 5) { spacename = userListStr[5] } else { spacename = "" } 154: if (userListStr.length > 6) { parent = userListStr[6] } else { parent = ""} 155: map.put(pagenum, [pagename: pagename, username: username, firstname: firstname, lastname: lastname, spacename: spacename, parent: parent ]) 156: } 157: println "{code}" 158: println map 159: println "{code}" 160: out.flush() 161: } catch (Exception e) { 162: println("Error: " + e) 163: } 164: return map 165: } 166: } 167: 168: 169: def HTMLCleaner ooHtmlCleaner = (HTMLCleaner) com.xpn.xwiki.web.Utils.getComponentManager().lookup(HTMLCleaner.ROLE, "wysiwyg") 170: def Syntax XWIKI_20 = new Syntax(SyntaxType.XWIKI, "2.0"); 171: def Syntax XHTML_10 = new Syntax(SyntaxType.XHTML, "1.0"); 172: def PrintRendererFactory rendererFactory = (PrintRendererFactory) com.xpn.xwiki.web.Utils.getComponentManager().lookup(PrintRendererFactory.ROLE) 173: def Parser xHtmlParser = (Parser) com.xpn.xwiki.web.Utils.getComponentManager().lookup(Parser.ROLE, "xhtml/1.0") 174: def DocumentAccessBridge docBridge = (DocumentAccessBridge) com.xpn.xwiki.web.Utils.getComponentManager().lookup(DocumentAccessBridge.ROLE) 175: def targetWikiDocument = "XWiki.gtestout" 176: def pmap 177: def space 178: 179: def pagetoload = "" // not a number, but a string of numerals representing one 180: pagetoload = 272..291 181: 182: if (xwiki.hasAdminRights()){ 183: try { 184: if(request.get("test") != null) { 185: def map = loadfile("pagemap.txt") 186: def pagestoprocess = map 187: if (pagetoload != null && pagetoload != "") { 188: if (pagetoload instanceof java.util.List) { 189: pagestoprocess = [:] 190: for (page in pagetoload) { 191: pagestoprocess.put(page.toString(), map.get(page.toString())) 192: } 193: } else { 194: pagestoprocess = [:] 195: pagestoprocess.put(pagetoload, map.get(pagetoload)) 196: } 197: } 198: 199: for (page in pagestoprocess) { 200: def pnumtoload = page.key 201: System.err.println "migration: page number: "+ pnumtoload 202: if (pnumtoload ==~ /[0-9]*/){ //make sure we have page number 203: pmap = map.get(pnumtoload) 204: } 205: def username = map.get(pnumtoload).get("username") 206: if (username=="") { 207: space = pmap.get("spacename") 208: if (space == "") {space = "Main"} 209: targetWikiDocument=space+"."+noaccent(map.get(pnumtoload).get("pagename")) 210: } else { 211: targetWikiDocument="XWiki."+noaccent(username) 212: } 213: 214: println "["+targetWikiDocument+"]" 215: 216: def java.net.URL url = new java.net.URL( "http://swiki.cs.colorado.edu/CreativeIT/"+pnumtoload+".print") 217: 218: println "{code}" 219: println url 220: println "{code}" 221: 222: StringBuffer content = org.htmlcleaner.Utils.readUrl(url, System.getProperty("file.encoding")); 223: String htmlContent = content.toString() 224: 225: // 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 226: Reader reader = new StringReader( htmlContent.replaceAll(/[\n\r]/, "") ); 227: 228: /* 229: //******** 230: 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>' 231: 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' 232: 233: //def offset = testString.compareTo(htmlContent) 234: //def count = 0 235: //def len = [testString.size(), htmlContent.size()].min() 236: //while (count < len) { 237: // if (testString.charAt(count) != htmlContent.charAt(count) ) { break } 238: // count ++ 239: //} 240: 241: //println "{code}" 242: //println offset 243: //println count 244: //println len 245: //println testString.charAt(offset) 246: //println htmlContent.charAt(offset) 247: //println testString.substring(0) 248: //println htmlContent.substring(0) 249: //println "{code}" 250: */ 251: //reader = new StringReader(testString.replaceAll(/[\n\r]/, "")) 252: /* 253: // println "{code}" 254: // println htmlContent 255: // println "{code}" 256: */ 257: //******** 258: def options = ["filterStyles":"none"] 259: 260: def xhtmlDoc = ooHtmlCleaner.clean(reader)//, options) 261: 262: XMLUtils.stripHTMLEnvelope(xhtmlDoc); 263: // unfortunately, convert is private, so we steal some of it here 264: // def String xwikiCode = DefaultOfficeImporter.convert((Reader) new StringReader( XMLUtils.toString(xhtmlDoc)), 265: // (Parser) xHtmlParser, (Syntax) XWIKI_20); 266: 267: def String xhtmlstring = XMLUtils.toString(xhtmlDoc) 268: 269: def XDOM xdom = xHtmlParser.parse(new StringReader(xhtmlstring)); 270: // // def XDOM xdom = xHtmlParser.parse(new StringReader(htmlContent)); 271: 272: 273: //********** 274: // printer = new DefaultWikiPrinter() 275: // listener = rendererFactory.createRenderer(XWIKI_20, printer) 276: // xdom.traverse(listener); 277: // println "{code}" 278: // println printer.toString(); 279: // println "{code}" 280: //********** 281: 282: 283: SyntaxFactory syntaxFactory = (SyntaxFactory) com.xpn.xwiki.web.Utils.getComponentManager().lookup(SyntaxFactory.ROLE); 284: 285: def WikiPrinter printer = new DefaultWikiPrinter() 286: 287: def Listener listener = rendererFactory.createRenderer(XWIKI_20, printer) 288: 289: def List anchors = xdom.getChildrenByType(LinkBlock.class, true) 290: def List images = xdom.getChildrenByType(ImageBlock.class, true) 291: def List headers = xdom.getChildrenByType(HeaderBlock.class, true) 292: def List formats = xdom.getChildrenByType(FormatBlock.class, true) 293: 294: // need to fix up some problems created by ?parser? 295: // we are missing spaces after formats and anchors 296: 297: // want to get rid of "title" entry for document 298: if (headers != null) { 299: headers.get(0).replace([SpaceBlock.SPACE_BLOCK]) 300: } 301: 302: // println("------") 303: 304: def filename 305: def avatarfilename = "" 306: def avatarurl = "" 307: def url2 308: 309: images = xdom.getChildrenByType(ImageBlock.class, true) 310: 311: // println "{code} images" 312: // println images 313: 314: if (images != null && images != []) { //are there any images 315: for (imageitem in images) { 316: def image = imageitem.getImage() 317: if (image.class == DocumentImage) { //image as document attachment 318: def attach = image.getAttachmentName() 319: if (attach != null) { //do we have an attachment for the image 320: //println attach 321: filename = attach.substring(attach.lastIndexOf("/")+1) 322: def attachpagenum = attach =~ /.*?uploads\/([0-9]*)\// 323: //println attachpagenum.size() 324: if (attachpagenum != null && attachpagenum != [] && attachpagenum.size() > 0){ 325: //println attachpagenum 326: //println attachpagenum[0] 327: attachpagenum = attachpagenum[0][1] 328: def attpmap = map.get(attachpagenum) 329: def attspace = attpmap.get("spacename") 330: def uname = attpmap.get("username") 331: if (attspace == "") { if (uname == "") {attspace = "Main"} else {attspace = "XWiki"}} 332: def attachdocname = attspace+"."+noaccent(map.get(attachpagenum).get("pagename")) 333: url2 = new java.net.URL( url.getProtocol(), url.getHost(), url.getPort(), attach) 334: //println "url2: " + url2 335: if (username !="" && avatarfilename == "") { 336: // we don't have an avatar yet, but first check for the real image in an anchor rather than reduced one swiki created 337: if (anchors != null && anchors != []) { //check the first anchor for an image 338: def anchorlink = anchors.get(0).getLink() 339: def anchorpath = anchorlink.getReference() 340: if (anchorpath.indexOf("/CreativeIT/") >= 0) { // is it relative to the server? 341: def anchorfilename = anchorpath.substring(anchorpath.lastIndexOf("/")+1) 342: def dotpos = anchorfilename.indexOf(".") 343: if (dotpos > 0 && dotpos < filename.size() && filename.substring(0, dotpos - 1) == anchorfilename.substring(0, dotpos - 1)) { 344: avatarfilename = anchorfilename 345: avatarurl = new java.net.URL( url.getProtocol(), url.getHost(), url.getPort(), anchorpath) 346: anchors.get(0).replace([SpaceBlock.SPACE_BLOCK.clone()]) 347: } 348: } 349: } 350: if (avatarfilename == ""){ 351: avatarfilename = filename 352: avatarurl = url2 353: imageitem.replace([SpaceBlock.SPACE_BLOCK.clone()]) 354: } 355: } else { 356: if (attachpagenum == pnumtoload){ 357: imageitem.replace( [new ImageBlock((Image) new DocumentImage(new DefaultAttachement( targetWikiDocument, filename)), false)]) 358: docBridge.setAttachmentContent(targetWikiDocument, filename, getBinaryURLContent(url2)) 359: //doc.addAttachment(filename, url2.openStream()) 360: } else { 361: imageitem.replace( [new ImageBlock((Image) new DocumentImage(new DefaultAttachement( attachdocname, filename)), false)]) 362: docBridge.setAttachmentContent(attachdocname, filename, getBinaryURLContent(url2)); 363: } 364: } 365: } 366: } // do we have attachment for image 367: } else { // assume it is a URLImage--don't really have to do anything, leave ref 368: def imageurl = image.getURL() 369: //println "imageurl: "+imageurl 370: 371: } 372: } 373: } 374: //println "anchors" 375: // need to rescan anchors cause we might have changed them 376: anchors = xdom.getChildrenByType(LinkBlock.class, true); 377: /* 378: for ( anchor in anchors ){ 379: link = anchor.getLink() 380: path = link.getReference() 381: if (path.indexOf('/CreativeIT')>=0) { 382: if( path.indexOf('uploads')>=0) { 383: def fn = path.substring(path.lastIndexOf("/")+1) 384: link.setReference("attach:"+fn) 385: def lurl = new java.net.URL( url.getProtocol(), url.getHost(), url.getPort(), path) 386: if (avatarfilename == "") { 387: avatarfilename = fn 388: avatarurl = lurl 389: } 390: } 391: } 392: } 393: */ 394: 395: //anchors = xdom.getChildrenByType(LinkBlock.class, true); 396: //println "{code}anchors:" 397: for ( anchor in anchors ){ 398: //def newmap = new HashMap(anchor.getParameters()) 399: //newmap.remove("title") 400: //println newmap 401: //anchor.setParameters(newmap) 402: anchor.setParameter("title","") 403: link = anchor.getLink() 404: path = link.getReference() 405: //println "found path: " + path 406: if (path.indexOf('http:') <0) { 407: if (path.indexOf('/CreativeIT')==0) { 408: if( path.indexOf('uploads')>=0) { 409: def fn = path.substring(path.lastIndexOf("/")+1) 410: //println "link to "+fn+": "+path 411: def lurl = new java.net.URL( url.getProtocol(), url.getHost(), url.getPort(), path) 412: link.setReference("attach:"+fn) 413: docBridge.setAttachmentContent(targetWikiDocument, fn, getBinaryURLContent(lurl)); 414: // docBridge.getDocument().addAttachment( fn, lurl.openStream(), context.getContext()); 415: } else { 416: //def attachpagenum = (path.substring(path.lastIndexOf("/")+1))=~/([0-9]*)/ 417: def attachpagenum = path.substring(path.lastIndexOf("/")+1) 418: //if (attachpagenum != null && attachpagenum != [] && attachpagenum.size() > 0){ 419: 420: //attachpagenum = attachpagenum[0][1] 421: 422: if (attachpagenum ==~ /[0-9]*/){ 423: println attachpagenum 424: def attpmap = map.get(attachpagenum) 425: def attspace = attpmap.get("spacename") 426: def uname = attpmap.get("username") 427: if (attspace == "") { if (uname == "") {attspace = "Main"} else {attspace = "XWiki"}} 428: def pname 429: if (attpmap != null) { //do we have a page entry in map 430: // println pmap 431: if( attpmap.get("username") == "") { 432: pname = attspace+"."+noaccent(attpmap.get("pagename")) 433: } else { 434: pname = attspace+"."+noaccent(attpmap.get("username")) 435: } 436: //println path + ":" + pname 437: link.setReference(pname) 438: } //do we have a page entry in map 439: } //make sure we have a page number 440: } 441: } 442: } 443: } 444: //println "{code}" 445: 446: //println "{code}" 447: //def patterns = content =~ /\/CreativeIT(\/uploads){0}\/([0-9]+)/ 448: //println "{code} patterns:" 449: //for (pattern in patterns){ 450: // println pattern 451: //} 452: //println "{code}" 453: 454: if (username == "") { 455: println "{code}" 456: println "no username" 457: println "{code}" 458: out.flush() 459: } else { 460: println "{code}" 461: println "username" 462: /* 463: images = xdom.getChildrenByType(ImageBlock.class, true) 464: if (images != null && images != []) { //are there any images 465: //println images 466: def imageitem = images.get(0) 467: //println imageitem 468: def image = imageitem.getImage() 469: //println image 470: if (image.class == DocumentImage) { //image as document attachment 471: def attach = image.getAttachmentName() 472: //println attach 473: if (attach != null) { //do we have an attachment for the image 474: filename = attach.substring(attach.lastIndexOf("/")+1) 475: //images.get(0).replace( [new ImageBlock((Image) new DocumentImage(new DefaultAttachement(targetWikiDocument, filename)), false)]) 476: 477: imageitem.replace( [SpaceBlock.SPACE_BLOCK.clone()]) 478: 479: url2 = new java.net.URL( url.getProtocol(), url.getHost(), url.getPort(), attach) 480: } else { 481: filename = "" 482: url2 = "" 483: } 484: } else { // assume it is a URLImage--don't really have to do anything, leave ref 485: def imageurl = image.getURL() 486: 487: //println "imageurl: "+imageurl 488: 489: } 490: } else { // there are noimages 491: // println "first image not appropriate" 492: } //checking images 493: */ 494: /* 495: if (filename == null || filename == "") { // no filename yet 496: if (anchors != null && anchors != []) { //check the first anchor for an image 497: def link = anchors.get(0).getLink() 498: //println link 499: 500: def path = link.getReference() 501: //println path 502: 503: if (path.indexOf("/CreativeIT/") >= 0) { // is it relative to the server? 504: filename = path.substring(path.lastIndexOf("/")+1) 505: //println filename 506: link.setReference("attach:"+filename) 507: url2 = new java.net.URL( url.getProtocol(), url.getHost(), url.getPort(), path) 508: //println(url2.toString()) 509: //anchors.get(0).replace([SpaceBlock.SPACE_BLOCK]) 510: } // relative to server 511: } 512: 513: } // end no file name yet 514: */ 515: println "{code}" 516: 517: } //username or not 518: 519: printer = new DefaultWikiPrinter() 520: 521: listener = rendererFactory.createRenderer(XWIKI_20, printer) 522: 523: xdom.traverse(listener); 524: xwikiCode = printer.toString(); 525: // println "{code} xwikiCode" 526: //println xwikiCode 527: // println "{code}" 528: out.flush() 529: def doc = xwiki.getDocument(targetWikiDocument) 530: def mdoc = doc.getDocument() 531: println "{code}" 532: //println pmap 533: println "{code}" 534: def parent = pmap.get("parent") 535: println parent 536: if (parent != ""){ 537: def parentpmap = map.get(parent) 538: def parspace = parentpmap.get("spacename") 539: def uname = parentpmap.get("username") 540: if (parspace == "") { if (uname == "") {parspace = "Main"} else {parspace = "XWiki"}} 541: def pname 542: if (parentpmap != null) { //do we have a page entry in map 543: if ( parentpmap.get("username") == "") { 544: pname = parspace+"."+noaccent(parentpmap.get("pagename")) 545: } else { 546: pname = parspace+"."+noaccent(parentpmap.get("username")) 547: } 548: doc.setParent(pname) 549: println "parent: "+pname 550: doc.save() 551: } 552: } 553: docBridge.setDocumentSyntaxId(targetWikiDocument, XWIKI_20.toIdString()); 554: //mdoc.setSyntaxId(XWIKI_20.toIdString()); 555: 556: if (username == "") { 557: 558: if (space == "ASU Workshop") { 559: 560: def Reader asureader = new StringReader( htmlContent ); 561: def asuxhtmlDoc = ooHtmlCleaner.clean(asureader)//, options) 562: 563: XMLUtils.stripHTMLEnvelope(asuxhtmlDoc); 564: def String asuxhtmlstring = XMLUtils.toString(xhtmlDoc) 565: def newcontent = ((String) htmlContent).replaceAll( 566: /\/CreativeIT(\/uploads){0}\/([0-9]+)/, 567: {match,group1, group2 -> "/xwiki/bin/view/"+space+"/"+noaccent(map.get(group2).get("pagename"))}) 568: newcontent = newcontent.replaceAll( 569: /http:\/\/swiki.cs.colorado.edu:3232/, 570: {match->""}) 571: newcontent = newcontent.replaceAll( 572: /\/CreativeIT(\/uploads){1}\/([0-9]+)/, 573: {match,group1, group2 ->"/xwiki/bin/download/"+space+"/"+noaccent(map.get(group2).get("pagename"))}) 574: newcontent = newcontent.replaceAll( 575: /<!DOCTYPE.*>/, 576: {match -> ""}) 577: newcontent = newcontent.replaceAll( 578: /(?s)<head.*<\/head>/, 579: {match -> ""}) 580: //doc.setContent("{{html}}"+htmlContent+"{{/html}}") 581: docBridge.setDocumentContent( 582: targetWikiDocument, 583: "{{html}}"+newcontent+"{{/html}}", 584: "Content created by swiki importer", false); 585: 586: } else { 587: def WikiPrinter newprinter = new DefaultWikiPrinter(); 588: def Listener newlistener = rendererFactory.createRenderer(XWIKI_20, newprinter); 589: xdom.traverse(newlistener); 590: xwikiCode = newprinter.toString(); 591: //println "{code}" 592: //println xwikiCode 593: //println "{code}" 594: //doc.setContent(xwikiCode) 595: docBridge.setDocumentContent( 596: targetWikiDocument, 597: xwikiCode, 598: "Content created by swiki importer", false); 599: } 600: //println "{code}" 601: //println newcontent 602: //println "{code}" 603: //doc.save() 604: //doc.getDocument().saveAllAttachments(context.getContext()) 605: 606: } else { // username not blank 607: //doc.setContent("{{include document=\"XWiki.XWikiUserSheet\"/}}\n"+xwikiCode) 608: docBridge.setDocumentContent( 609: targetWikiDocument, 610: "{{include document=\"XWiki.XWikiUserSheet\"/}}\n"+xwikiCode, 611: "Content created by swiki importer", false); 612: //println "{code}" 613: //println filename + ":" + url2 614: //println "{code}" 615: 616: if (avatarfilename != "" && avatarfilename != null) { 617: //doc.addAttachment(filename, getBinaryURLContent(url2)) 618: //doc.addAttachment(filename, url2.openStream()) 619: 620: docBridge.setAttachmentContent(targetWikiDocument, avatarfilename, getBinaryURLContent(avatarurl)); 621: //docBridge.setAttachmentContent(targetWikiDocument, filename2, getBinaryURLContent(url3)); 622: } 623: 624: //def doc = docBridge.getDocument(targetWikiDocument) 625: def userObj = doc.getObject("XWiki.XWikiUsers") 626: if (userObj == null) { 627: //println "no obj, creating one" 628: doc.createNewObject("XWiki.XWikiUsers") 629: userObj = doc.getObject("XWiki.XWikiUsers") 630: } 631: //println "{code}" 632: //println userObj 633: //println "{code}" 634: 635: userObj.getBaseObject().setStringValue("avatar", avatarfilename) 636: userObj.getBaseObject().setStringValue("first_name", map.get(pnumtoload).get("firstname")) 637: userObj.getBaseObject().setStringValue("last_name", map.get(pnumtoload).get("lastname")) 638: //userObj.set("comment", xwikiCode, context.getContext()) 639: doc.save() 640: //doc.getDocument().saveAllAttachments(context.getContext()) 641: } // user is blank or not 642: } // for page in map 643: } else { // request != test 644: println "[run test>" + doc.fullName + "?test=1]\n" 645: } 646: } catch (Exception e) { 647: println "{code} Error: " 648: println e.printStackTrace(out) + "{code}"} 649: }//admin rights 650: %>
Quick Links
Home
Index
What's New
Blog
Calendar
Photo Albums
Sandbox
Tags
Bulletin Board
My Recent Modifications
PamelaJennings
|
rwakkary
|
HaledenSands
|
ByronLahey