Return-Path: X-Original-To: apmail-geronimo-scm-archive@www.apache.org Delivered-To: apmail-geronimo-scm-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id E2A37DD2C for ; Sat, 22 Dec 2012 07:47:54 +0000 (UTC) Received: (qmail 8646 invoked by uid 500); 22 Dec 2012 07:47:54 -0000 Delivered-To: apmail-geronimo-scm-archive@geronimo.apache.org Received: (qmail 8496 invoked by uid 500); 22 Dec 2012 07:47:53 -0000 Mailing-List: contact scm-help@geronimo.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: List-Post: Reply-To: dev@geronimo.apache.org List-Id: Delivered-To: mailing list scm@geronimo.apache.org Received: (qmail 8462 invoked by uid 99); 22 Dec 2012 07:47:52 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 22 Dec 2012 07:47:52 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 22 Dec 2012 07:47:50 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 10DC82388847; Sat, 22 Dec 2012 07:47:30 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1425253 - in /geronimo/site/trunk/wiki-export/src/main/java/org/apache/cxf/cwiki: AbstractPage.java BlogEntrySummary.java ConfluenceCleanupWriter.java Page.java SiteExporter.java Date: Sat, 22 Dec 2012 07:47:29 -0000 To: scm@geronimo.apache.org From: gawor@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20121222074730.10DC82388847@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: gawor Date: Sat Dec 22 07:47:29 2012 New Revision: 1425253 URL: http://svn.apache.org/viewvc?rev=1425253&view=rev Log: get basic blog rendering working Added: geronimo/site/trunk/wiki-export/src/main/java/org/apache/cxf/cwiki/AbstractPage.java (with props) geronimo/site/trunk/wiki-export/src/main/java/org/apache/cxf/cwiki/BlogEntrySummary.java (with props) Modified: geronimo/site/trunk/wiki-export/src/main/java/org/apache/cxf/cwiki/ConfluenceCleanupWriter.java geronimo/site/trunk/wiki-export/src/main/java/org/apache/cxf/cwiki/Page.java geronimo/site/trunk/wiki-export/src/main/java/org/apache/cxf/cwiki/SiteExporter.java Added: geronimo/site/trunk/wiki-export/src/main/java/org/apache/cxf/cwiki/AbstractPage.java URL: http://svn.apache.org/viewvc/geronimo/site/trunk/wiki-export/src/main/java/org/apache/cxf/cwiki/AbstractPage.java?rev=1425253&view=auto ============================================================================== --- geronimo/site/trunk/wiki-export/src/main/java/org/apache/cxf/cwiki/AbstractPage.java (added) +++ geronimo/site/trunk/wiki-export/src/main/java/org/apache/cxf/cwiki/AbstractPage.java Sat Dec 22 07:47:29 2012 @@ -0,0 +1,91 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.cxf.cwiki; + +import java.io.Serializable; + +import org.apache.cxf.helpers.DOMUtils; +import org.w3c.dom.Element; + +/** + * + */ +public class AbstractPage implements Serializable { + + private static final long serialVersionUID = 1L; + + final String id; + final String title; + final String url; + + public AbstractPage(Element root) throws Exception { + // org.apache.cxf.helpers.XMLUtils.printDOM(doc.getDocumentElement()); + + id = DOMUtils.getChildContent(root, "id"); + title = DOMUtils.getChildContent(root, "title"); + url = DOMUtils.getChildContent(root, "url"); + } + + public String getDirectory() { + return ""; + } + + public String getPath() { + return getDirectory() + createFileName(); + } + + public String createFileName() { + StringBuffer buffer = new StringBuffer(); + char array[] = title.toLowerCase().toCharArray(); + boolean separated = true; + for (int x = 0; x < array.length; x++) { + if ("abcdefghijklmnopqrstuvwxyz0123456789".indexOf(array[x]) >= 0) { + buffer.append(Character.toLowerCase(array[x])); + separated = false; + } else if ("\r\n\t -".indexOf(array[x]) >= 0) { + if (separated) { + continue; + } + buffer.append('-'); + separated = true; + } + } + if (buffer.length() == 0) { + return id + ".html"; + } + return buffer.append(".html").toString(); + } + + public String getId() { + return id; + } + + public String getTitle() { + return title; + } + + public String getURL() { + return url; + } + + public String toString() { + return "AbstractPage[id=" + id + ",title=" + title + ",url=" + url + "]"; + } +} Propchange: geronimo/site/trunk/wiki-export/src/main/java/org/apache/cxf/cwiki/AbstractPage.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: geronimo/site/trunk/wiki-export/src/main/java/org/apache/cxf/cwiki/AbstractPage.java ------------------------------------------------------------------------------ svn:keywords = Date Revision Propchange: geronimo/site/trunk/wiki-export/src/main/java/org/apache/cxf/cwiki/AbstractPage.java ------------------------------------------------------------------------------ svn:mime-type = text/plain Added: geronimo/site/trunk/wiki-export/src/main/java/org/apache/cxf/cwiki/BlogEntrySummary.java URL: http://svn.apache.org/viewvc/geronimo/site/trunk/wiki-export/src/main/java/org/apache/cxf/cwiki/BlogEntrySummary.java?rev=1425253&view=auto ============================================================================== --- geronimo/site/trunk/wiki-export/src/main/java/org/apache/cxf/cwiki/BlogEntrySummary.java (added) +++ geronimo/site/trunk/wiki-export/src/main/java/org/apache/cxf/cwiki/BlogEntrySummary.java Sat Dec 22 07:47:29 2012 @@ -0,0 +1,77 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.cxf.cwiki; + +import java.io.Serializable; + +import javax.xml.datatype.DatatypeFactory; +import javax.xml.datatype.XMLGregorianCalendar; + +import org.apache.cxf.helpers.DOMUtils; +import org.w3c.dom.Element; + +/** + * + */ +public class BlogEntrySummary extends AbstractPage implements Serializable { + + private static final long serialVersionUID = 1L; + + final XMLGregorianCalendar published; + final String version; + + public BlogEntrySummary(Element root) throws Exception { + super(root); + + String mod = DOMUtils.getChildContent(root, "publishDate"); + published = DatatypeFactory.newInstance().newXMLGregorianCalendar(mod); + String v = DOMUtils.getChildContent(root, "version"); + version = (v == null) ? "0" : v; + } + + public String getDirectory() { + StringBuilder builder = new StringBuilder(); + builder.append(String.valueOf(published.getYear())); + builder.append("/"); + if (published.getMonth() < 10) { + builder.append("0"); + } + builder.append(String.valueOf(published.getMonth())); + builder.append("/"); + if (published.getDay() < 10) { + builder.append("0"); + } + builder.append(String.valueOf(published.getDay())); + builder.append("/"); + return builder.toString(); + } + + public String getVersion() { + return version; + } + + public XMLGregorianCalendar getPublished() { + return published; + } + + public String toString() { + return "BlogEntrySummary[id=" + id + ",title=" + title + ",version=" + version + ",url=" + url + "]"; + } +} Propchange: geronimo/site/trunk/wiki-export/src/main/java/org/apache/cxf/cwiki/BlogEntrySummary.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: geronimo/site/trunk/wiki-export/src/main/java/org/apache/cxf/cwiki/BlogEntrySummary.java ------------------------------------------------------------------------------ svn:keywords = Date Revision Propchange: geronimo/site/trunk/wiki-export/src/main/java/org/apache/cxf/cwiki/BlogEntrySummary.java ------------------------------------------------------------------------------ svn:mime-type = text/plain Modified: geronimo/site/trunk/wiki-export/src/main/java/org/apache/cxf/cwiki/ConfluenceCleanupWriter.java URL: http://svn.apache.org/viewvc/geronimo/site/trunk/wiki-export/src/main/java/org/apache/cxf/cwiki/ConfluenceCleanupWriter.java?rev=1425253&r1=1425252&r2=1425253&view=diff ============================================================================== --- geronimo/site/trunk/wiki-export/src/main/java/org/apache/cxf/cwiki/ConfluenceCleanupWriter.java (original) +++ geronimo/site/trunk/wiki-export/src/main/java/org/apache/cxf/cwiki/ConfluenceCleanupWriter.java Sat Dec 22 07:47:29 2012 @@ -37,14 +37,14 @@ import org.ccil.cowan.tagsoup.XMLWriter; */ public class ConfluenceCleanupWriter extends XMLWriter { - private final Page page; + private final AbstractPage page; private final SiteExporter exporter; private final String divId; private final String divCls; private final Stack trStack = new Stack(); private int curTrCount; - public ConfluenceCleanupWriter(SiteExporter exp, Writer writer, Page page, + public ConfluenceCleanupWriter(SiteExporter exp, Writer writer, AbstractPage page, String id, String divCls) { super(writer); this.page = page; @@ -53,28 +53,51 @@ public class ConfluenceCleanupWriter ext this.divCls = divCls; } + private File getPageDirectory() { + String pageDir = page.getDirectory(); + if (pageDir.length() > 0) { + return new File(exporter.outputDir, pageDir); + } else { + return exporter.outputDir; + } + } + private String findPageWithURL(String url) throws Exception { - Page p = exporter.findPageByURL(url); - if (p != null) { - return p.createFileName(); - } - for (SiteExporter siteExporter : SiteExporter.siteExporters) { - if (exporter == siteExporter) { - continue; - } - if (siteExporter.getSpace().getURL().endsWith(url)) { - String prefix = getRelativePath(SiteExporter.rootOutputDir, exporter.outputDir, siteExporter.outputDir); - String location = prefix + "index.html";; + String location = findPageWithURL(exporter, url); + if (location == null) { + for (SiteExporter siteExporter : SiteExporter.siteExporters) { + if (exporter == siteExporter) { + continue; + } + location = findPageWithURL(siteExporter, url); + if (location != null) { + break; + } + } + } + return location; + } + + private String findPageWithURL(SiteExporter siteExporter, String url) throws Exception { + if (siteExporter.getSpace().getURL().endsWith(url)) { + String prefix = getRelativePath(SiteExporter.rootOutputDir, getPageDirectory(), siteExporter.outputDir); + String location = prefix + "index.html";; + if (exporter != siteExporter) { System.out.println("Cross space link to " + location); - return location; - } else { - p = siteExporter.findPageByURL(url); - if (p != null) { - String prefix = getRelativePath(SiteExporter.rootOutputDir, exporter.outputDir, siteExporter.outputDir); - String location = prefix + p.createFileName(); + } + return location; + } else { + AbstractPage p = siteExporter.findPageByURL(url); + if (p == null) { + p = siteExporter.findBlogEntryByURL(url); + } + if (p != null) { + String prefix = getRelativePath(SiteExporter.rootOutputDir, getPageDirectory(), siteExporter.outputDir); + String location = prefix + p.getPath(); + if (exporter != siteExporter) { System.out.println("Cross space link to " + location); - return location; } + return location; } } return null; @@ -342,13 +365,16 @@ public class ConfluenceCleanupWriter ext if (current.equals(other)) { return ""; } + + String rootPath = root.getCanonicalPath(); + String currentPath = current.getCanonicalPath(); StringBuilder builder = new StringBuilder(); - while (!root.equals(current)) { + while (!rootPath.equals(currentPath)) { current = current.getParentFile(); + currentPath = current.getCanonicalPath(); builder.append("../"); } - String rootPath = root.getCanonicalPath(); String otherPath = other.getCanonicalPath(); if (rootPath.equals(otherPath)) { Modified: geronimo/site/trunk/wiki-export/src/main/java/org/apache/cxf/cwiki/Page.java URL: http://svn.apache.org/viewvc/geronimo/site/trunk/wiki-export/src/main/java/org/apache/cxf/cwiki/Page.java?rev=1425253&r1=1425252&r2=1425253&view=diff ============================================================================== --- geronimo/site/trunk/wiki-export/src/main/java/org/apache/cxf/cwiki/Page.java (original) +++ geronimo/site/trunk/wiki-export/src/main/java/org/apache/cxf/cwiki/Page.java Sat Dec 22 07:47:29 2012 @@ -31,20 +31,19 @@ import javax.xml.datatype.DatatypeFactor import javax.xml.datatype.XMLGregorianCalendar; import org.w3c.dom.Document; +import org.w3c.dom.Element; import org.apache.cxf.helpers.DOMUtils; /** * */ -public class Page implements Serializable { +public class Page extends AbstractPage implements Serializable { + private static final long serialVersionUID = 1L; XMLGregorianCalendar modified; - final String id; final String parent; - final String title; - final String url; final String spaceKey; Map attachments; Set includes; @@ -56,18 +55,20 @@ public class Page implements Serializabl transient SiteExporter exporter; public Page(Document doc) throws Exception { + this(DOMUtils.getFirstElement(doc.getDocumentElement())); + } + + public Page(Element root) throws Exception { + super(root); //org.apache.cxf.helpers.XMLUtils.printDOM(doc.getDocumentElement()); - id = DOMUtils.getChildContent(doc.getDocumentElement().getFirstChild(), "id"); - parent = DOMUtils.getChildContent(doc.getDocumentElement().getFirstChild(), "parentId"); - title = DOMUtils.getChildContent(doc.getDocumentElement().getFirstChild(), "title"); - url = DOMUtils.getChildContent(doc.getDocumentElement().getFirstChild(), "url"); - spaceKey = DOMUtils.getChildContent(doc.getDocumentElement().getFirstChild(), "space"); + parent = DOMUtils.getChildContent(root, "parentId"); + spaceKey = DOMUtils.getChildContent(root, "space"); - String mod = DOMUtils.getChildContent(doc.getDocumentElement().getFirstChild(), "modified"); + String mod = DOMUtils.getChildContent(root, "modified"); modified = DatatypeFactory.newInstance().newXMLGregorianCalendar(mod); - String c = DOMUtils.getChildContent(doc.getDocumentElement().getFirstChild(), "content"); + String c = DOMUtils.getChildContent(root, "content"); if (c != null) { int idx = c.indexOf("{children"); while (idx != -1) { @@ -130,15 +131,11 @@ public class Page implements Serializabl return includes.contains(s); } - public String getId() { - return id; - } + public String getParentId() { return parent; } - public String getTitle() { - return title; - } + public XMLGregorianCalendar getModifiedTime() { return modified; } @@ -146,39 +143,15 @@ public class Page implements Serializabl public void setContent(String c) { renderedContent = c; } + public String getContent() { return renderedContent; } - public String getURL() { - return url; - } public String getSpaceKey() { return spaceKey; } - public String createFileName() { - StringBuffer buffer = new StringBuffer(); - char array[] = getTitle().toLowerCase().toCharArray(); - boolean separated = true; - for (int x = 0; x < array.length; x++) { - if ("abcdefghijklmnopqrstuvwxyz0123456789".indexOf(array[x]) >= 0) { - buffer.append(Character.toLowerCase(array[x])); - separated = false; - } else if ("\r\n\t -".indexOf(array[x]) >= 0) { - if (separated) { - continue; - } - buffer.append('-'); - separated = true; - } - } - if (buffer.length() == 0) { - return getId() + ".html"; - } - return buffer.append(".html").toString(); - } - public void addAttachment(String aid, String filename) { if (attachments == null) { attachments = new HashMap(); Modified: geronimo/site/trunk/wiki-export/src/main/java/org/apache/cxf/cwiki/SiteExporter.java URL: http://svn.apache.org/viewvc/geronimo/site/trunk/wiki-export/src/main/java/org/apache/cxf/cwiki/SiteExporter.java?rev=1425253&r1=1425252&r2=1425253&view=diff ============================================================================== --- geronimo/site/trunk/wiki-export/src/main/java/org/apache/cxf/cwiki/SiteExporter.java (original) +++ geronimo/site/trunk/wiki-export/src/main/java/org/apache/cxf/cwiki/SiteExporter.java Sat Dec 22 07:47:29 2012 @@ -19,7 +19,6 @@ package org.apache.cxf.cwiki; - import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; @@ -53,6 +52,7 @@ import java.util.concurrent.atomic.Atomi import javax.xml.datatype.DatatypeFactory; import javax.xml.datatype.XMLGregorianCalendar; import javax.xml.namespace.QName; +import javax.xml.parsers.ParserConfigurationException; import javax.xml.ws.AsyncHandler; import javax.xml.ws.Dispatch; import javax.xml.ws.Response; @@ -81,7 +81,6 @@ import org.apache.cxf.transport.http.HTT import org.apache.cxf.transports.http.configuration.HTTPClientPolicy; import org.apache.velocity.Template; import org.apache.velocity.VelocityContext; -import org.apache.velocity.app.Velocity; import org.apache.velocity.app.VelocityEngine; import org.apache.velocity.runtime.resource.loader.URLResourceLoader; import org.ccil.cowan.tagsoup.Parser; @@ -96,7 +95,9 @@ public class SiteExporter implements Run static final String ROOT = HOST + "/confluence"; static final String RPC_ROOT = "/rpc/soap-axis/confluenceservice-v1"; static final String SOAPNS = "http://soap.rpc.confluence.atlassian.com"; - + + static final String SEPARATOR = " > "; + static boolean debug; @@ -116,6 +117,9 @@ public class SiteExporter implements Run Collection modifiedPages = new ConcurrentLinkedQueue(); Set globalPages = new CopyOnWriteArraySet(); + Map blog = new ConcurrentHashMap(); + Set modifiedBlog = new CopyOnWriteArraySet(); + static Map spaces = new ConcurrentHashMap(); String spaceKey = "CXF"; @@ -234,7 +238,7 @@ public class SiteExporter implements Run */ public boolean initialize() throws Exception { if (!forceAll) { - loadPagesCache(); + loadCache(); } // debug stuff, force regen of a page @@ -252,6 +256,7 @@ public class SiteExporter implements Run getSpace(); breadCrumbRoot = space.getName(); + loadBlog(); loadPages(); return true; @@ -277,8 +282,9 @@ public class SiteExporter implements Run if (!modifiedPages.isEmpty()) { + renderBlog(); renderPages(); - savePages(); + saveCache(); } } @@ -322,12 +328,13 @@ public class SiteExporter implements Run return true; } - private void savePages() throws Exception { + private void saveCache() throws Exception { File file = new File(rootOutputDir, pageCacheFile); file.getParentFile().mkdirs(); FileOutputStream fout = new FileOutputStream(file); ObjectOutputStream oout = new ObjectOutputStream(fout); oout.writeObject(pages); + oout.writeObject(blog); oout.close(); } @@ -367,6 +374,45 @@ public class SiteExporter implements Run p.setContent(null); } } + + private void renderBlog() throws Exception { + int total = modifiedBlog.size(); + int count = 0; + for (BlogEntrySummary entry : modifiedBlog) { + count++; + System.out.println("(" + spaceKey + ") Rendering Blog Entry " + entry.getTitle() + + " (" + count + "/" + total + ")"); + + String body = renderPage(entry); + body = updateContentLinks(entry, body, null, mainDivClass); + + + VelocityContext ctx = new VelocityContext(); + ctx.put("autoexport", this); + ctx.put("page", entry); + ctx.put("body", body); + ctx.put("confluenceUri", ROOT); + ctx.put("pageManager", new PageManager(this)); + ctx.put("renderer", new Renderer(this)); + + File file = new File(outputDir, entry.getPath()); + file.getParentFile().mkdirs(); + boolean isNew = !file.exists(); + + FileWriter writer = new FileWriter(file); + ctx.put("out", writer); + template.merge(ctx, writer); + writer.close(); + if (isNew) { + //call "svn add" + callSvn("add", file.getAbsolutePath()); + svnCommitMessage.append("Adding: " + file.getName() + "\n"); + } else { + svnCommitMessage.append("Modified: " + file.getName() + "\n"); + } + } + } + void callSvn(String ... commands) throws Exception { callSvn(outputDir, commands); } @@ -434,13 +480,13 @@ public class SiteExporter implements Run el = DOMUtils.getNextElement(el); } } - String loadUserImage(Page p, String href) throws Exception { + String loadUserImage(AbstractPage p, String href) throws Exception { return loadPageBinaryData(p, href, "userimage", true); } - String loadThumbnail(Page p, String href) throws Exception { + String loadThumbnail(AbstractPage p, String href) throws Exception { return loadPageBinaryData(p, href, "thumbs", false); } - String loadPageBinaryData(Page p, String href, String type, boolean auth) throws Exception { + String loadPageBinaryData(AbstractPage p, String href, String type, boolean auth) throws Exception { String filename = href.substring(href.lastIndexOf('/') + 1); filename = filename.replace(' ', '_'); if (filename.indexOf('?') != -1) { @@ -514,10 +560,38 @@ public class SiteExporter implements Run return null; } + public String breadcrumbs(BlogEntrySummary page) { + StringBuffer buffer = new StringBuffer(); + if (breadCrumbRoot != null) { + buffer.append(""); + buffer.append(breadCrumbRoot); + buffer.append(""); + buffer.append(SEPARATOR); + } + XMLGregorianCalendar published = page.getPublished(); + buffer.append(String.valueOf(published.getYear())); + buffer.append(SEPARATOR); + if (published.getMonth() < 10) { + buffer.append("0"); + } + buffer.append(String.valueOf(published.getMonth())); + buffer.append(SEPARATOR); + if (published.getDay() < 10) { + buffer.append("0"); + } + buffer.append(String.valueOf(published.getDay())); + buffer.append(SEPARATOR); + buffer.append(""); + buffer.append(page.getTitle()); + buffer.append(""); + return buffer.toString(); + } + public String breadcrumbs(Page page) { - String separator = ">"; - String s = " " + separator + " "; - StringBuffer buffer = new StringBuffer(); List p = new LinkedList(); String parentId = page.getParentId(); @@ -533,7 +607,7 @@ public class SiteExporter implements Run buffer.append("\">"); buffer.append(breadCrumbRoot); buffer.append(""); - buffer.append(s); + buffer.append(SEPARATOR); } for (Page p2 : p) { buffer.append(""); buffer.append(p2.getTitle()); buffer.append(""); - buffer.append(s); + buffer.append(SEPARATOR); } buffer.append(")oin.readObject()); + blog = CastUtils.cast((Map)oin.readObject()); oin.close(); for (Page p : pages.values()) { @@ -666,6 +746,58 @@ public class SiteExporter implements Run } } + public void loadBlog() throws Exception { + Document doc = XMLUtils.newDocument(); + Element el = doc.createElementNS(SOAPNS, "ns1:getBlogEntries"); + Element el2 = doc.createElement("in0"); + el.appendChild(el2); + el2.setTextContent(loginToken); + el2 = doc.createElement("in1"); + el.appendChild(el2); + el2.setTextContent(spaceKey); + doc.appendChild(el); + doc = getDispatch().invoke(doc); + + Map oldBlog = new ConcurrentHashMap(blog); + + Node nd = doc.getDocumentElement().getFirstChild().getFirstChild(); + while (nd != null) { + if (nd instanceof Element) { + BlogEntrySummary entry = new BlogEntrySummary((Element)nd); + BlogEntrySummary oldEntry = blog.put(entry.getId(), entry); + System.out.println(entry + " " + oldEntry); + if (oldEntry == null || !oldEntry.getVersion().equals(entry.getVersion())) { + System.out.println("modified: " + entry); + modifiedBlog.add(entry); + } + oldBlog.remove(entry.getId()); + } + nd = nd.getNextSibling(); + } + + for (String id : oldBlog.keySet()) { + //these pages have been deleted + BlogEntrySummary p = blog.remove(id); + File file = new File(outputDir, p.getPath()); + if (file.exists()) { + callSvn("rm", file.getAbsolutePath()); + svnCommitMessage.append("Deleted: " + file.getName() + "\n"); + } + if (file.exists()) { + file.delete(); + } + } + } + + public BlogEntrySummary findBlogEntryByURL(String url) throws Exception { + for (BlogEntrySummary p : blog.values()) { + if (p.getURL().endsWith(url)) { + return p; + } + } + return null; + } + public void loadPages() throws Exception { Document doc = XMLUtils.newDocument(); Element el = doc.createElementNS(SOAPNS, "ns1:getPages"); @@ -823,7 +955,7 @@ public class SiteExporter implements Run return f; } - private String updateContentLinks(Page page, String content, + private String updateContentLinks(AbstractPage page, String content, String id, String divCls) throws Exception { XMLReader parser = createTagSoupParser(); StringWriter w = new StringWriter(); @@ -847,7 +979,7 @@ public class SiteExporter implements Run return reader; } - protected ContentHandler createContentHandler(final Page page, Writer w, + protected ContentHandler createContentHandler(AbstractPage page, Writer w, String id, String divCls) { XMLWriter xmlWriter = new ConfluenceCleanupWriter(this, w, page, id, divCls); xmlWriter.setOutputProperty(XMLWriter.OMIT_XML_DECLARATION, "yes");