geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ga...@apache.org
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 GMT
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<Integer> trStack = new Stack<Integer>(); 
     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<String, String> attachments;
     Set<String> 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<String, String>();

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 = "&nbsp;&gt;&nbsp;";
+    
     
     
     static boolean debug;
@@ -116,6 +117,9 @@ public class SiteExporter implements Run
     Collection<Page> modifiedPages = new ConcurrentLinkedQueue<Page>();
     Set<String> globalPages = new CopyOnWriteArraySet<String>();
     
+    Map<String, BlogEntrySummary> blog = new ConcurrentHashMap<String, BlogEntrySummary>();
+    Set<BlogEntrySummary> modifiedBlog = new CopyOnWriteArraySet<BlogEntrySummary>();
+    
     static Map<String, Space> spaces = new ConcurrentHashMap<String, Space>();
 
     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("<a href=\"");
+            buffer.append("../../../index.html");
+            buffer.append("\">");
+            buffer.append(breadCrumbRoot);
+            buffer.append("</a>");
+            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("<a href=\"");
+        buffer.append(page.createFileName());
+        buffer.append("\">");
+        buffer.append(page.getTitle());
+        buffer.append("</a>");
+        return buffer.toString();
+    }
+    
     public String breadcrumbs(Page page) {
-        String separator = "&gt;";
-        String s = "&nbsp;" + separator + "&nbsp;";
-
         StringBuffer buffer = new StringBuffer();
         List<Page> p = new LinkedList<Page>();
         String parentId = page.getParentId();
@@ -533,7 +607,7 @@ public class SiteExporter implements Run
             buffer.append("\">");
             buffer.append(breadCrumbRoot);
             buffer.append("</a>");
-            buffer.append(s);
+            buffer.append(SEPARATOR);
         }
         for (Page p2 : p) {
             buffer.append("<a href=\"");
@@ -541,7 +615,7 @@ public class SiteExporter implements Run
             buffer.append("\">");
             buffer.append(p2.getTitle());
             buffer.append("</a>");
-            buffer.append(s);
+            buffer.append(SEPARATOR);
         }
         buffer.append("<a href=\"");
         buffer.append(page.createFileName());
@@ -577,6 +651,18 @@ public class SiteExporter implements Run
         return p.getContent();
     }
     protected String loadPageContent(Page p, String divId, String divCls) throws Exception
{
+        String content = renderPage(p);
+        content = updateContentLinks(p, content, divId, 
+                                     divCls == null && divId == null ? mainDivClass
: divCls);
+        if (divId == null) {
+            p.setContent(content);
+        } else {
+            p.setContentForDivId(divId, content);
+        }
+        return content;
+    }
+
+    private String renderPage(AbstractPage p) throws ParserConfigurationException {
         Document doc = XMLUtils.newDocument();
         Element el = doc.createElementNS(SOAPNS, "ns1:renderContent");
         Element el2 = doc.createElement("in0");
@@ -611,13 +697,6 @@ public class SiteExporter implements Run
         doc = getDispatch().invoke(doc);
         
         String content = doc.getDocumentElement().getFirstChild().getTextContent().trim();
-        content = updateContentLinks(p, content, divId, 
-                                     divCls == null && divId == null ? mainDivClass
: divCls);
-        if (divId == null) {
-            p.setContent(content);
-        } else {
-            p.setContentForDivId(divId, content);
-        }
         return content;
     }
 
@@ -652,12 +731,13 @@ public class SiteExporter implements Run
         }
     }
 
-    public void loadPagesCache() throws Exception {
+    public void loadCache() throws Exception {
         File file = new File(rootOutputDir, pageCacheFile);
         if (file.exists()) {
             FileInputStream fin = new FileInputStream(file);
             ObjectInputStream oin = new ObjectInputStream(fin);
             pages = CastUtils.cast((Map<?, ?>)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<String, BlogEntrySummary> oldBlog = new ConcurrentHashMap<String, BlogEntrySummary>(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");



Mime
View raw message