You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by dk...@apache.org on 2013/01/31 19:20:36 UTC
svn commit: r1441099 - in /cxf/web: src/main/java/org/apache/cxf/cwiki/
template/
Author: dkulp
Date: Thu Jan 31 18:20:35 2013
New Revision: 1441099
URL: http://svn.apache.org/viewvc?rev=1441099&view=rev
Log:
Merge in changes from Geronimo
Added:
cxf/web/src/main/java/org/apache/cxf/cwiki/AbstractPage.java
cxf/web/src/main/java/org/apache/cxf/cwiki/BlogEntrySummary.java
cxf/web/src/main/java/org/apache/cxf/cwiki/PageManager.java
cxf/web/src/main/java/org/apache/cxf/cwiki/Renderer.java
cxf/web/src/main/java/org/apache/cxf/cwiki/Space.java
Modified:
cxf/web/src/main/java/org/apache/cxf/cwiki/ConfluenceCleanupWriter.java
cxf/web/src/main/java/org/apache/cxf/cwiki/Page.java
cxf/web/src/main/java/org/apache/cxf/cwiki/SiteExporter.java
cxf/web/template/template.vm
Added: cxf/web/src/main/java/org/apache/cxf/cwiki/AbstractPage.java
URL: http://svn.apache.org/viewvc/cxf/web/src/main/java/org/apache/cxf/cwiki/AbstractPage.java?rev=1441099&view=auto
==============================================================================
--- cxf/web/src/main/java/org/apache/cxf/cwiki/AbstractPage.java (added)
+++ cxf/web/src/main/java/org/apache/cxf/cwiki/AbstractPage.java Thu Jan 31 18:20:35 2013
@@ -0,0 +1,100 @@
+/**
+ * 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.w3c.dom.Element;
+
+import org.apache.cxf.helpers.DOMUtils;
+
+/**
+ *
+ */
+public class AbstractPage implements Serializable {
+
+ private static final long serialVersionUID = 1L;
+
+ final String id;
+ final String title;
+ final String url;
+
+ transient String directory;
+
+ 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 AbstractPage(AbstractPage source) {
+ this.id = source.id;
+ this.title = source.title;
+ this.url = source.url;
+ this.directory = source.directory;
+ }
+
+ public String getDirectory() {
+ return directory == null ? "" : directory;
+ }
+
+ 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 + "]";
+ }
+}
Added: cxf/web/src/main/java/org/apache/cxf/cwiki/BlogEntrySummary.java
URL: http://svn.apache.org/viewvc/cxf/web/src/main/java/org/apache/cxf/cwiki/BlogEntrySummary.java?rev=1441099&view=auto
==============================================================================
--- cxf/web/src/main/java/org/apache/cxf/cwiki/BlogEntrySummary.java (added)
+++ cxf/web/src/main/java/org/apache/cxf/cwiki/BlogEntrySummary.java Thu Jan 31 18:20:35 2013
@@ -0,0 +1,83 @@
+/**
+ * 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.w3c.dom.Element;
+
+import org.apache.cxf.helpers.DOMUtils;
+
+/**
+ *
+ */
+public class BlogEntrySummary extends AbstractPage implements Serializable {
+
+ private static final long serialVersionUID = 1L;
+
+ final XMLGregorianCalendar published;
+
+ // BlogEntrySummary does not have version field but the BlogEntry does.
+ // We load and set the version separately. It will be used to decide
+ // whether the blog entry needs to be re-rendered or not.
+ int version;
+
+ public BlogEntrySummary(Element root) throws Exception {
+ super(root);
+
+ String mod = DOMUtils.getChildContent(root, "publishDate");
+ published = DatatypeFactory.newInstance().newXMLGregorianCalendar(mod);
+ }
+
+ 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 int getVersion() {
+ return version;
+ }
+
+ void setVersion(int version) {
+ this.version = version;
+ }
+
+ public XMLGregorianCalendar getPublished() {
+ return published;
+ }
+
+ public String toString() {
+ return "BlogEntrySummary[id=" + id + ",title=" + title + ",version=" + version + ",url=" + url + "]";
+ }
+}
Modified: cxf/web/src/main/java/org/apache/cxf/cwiki/ConfluenceCleanupWriter.java
URL: http://svn.apache.org/viewvc/cxf/web/src/main/java/org/apache/cxf/cwiki/ConfluenceCleanupWriter.java?rev=1441099&r1=1441098&r2=1441099&view=diff
==============================================================================
--- cxf/web/src/main/java/org/apache/cxf/cwiki/ConfluenceCleanupWriter.java (original)
+++ cxf/web/src/main/java/org/apache/cxf/cwiki/ConfluenceCleanupWriter.java Thu Jan 31 18:20:35 2013
@@ -19,6 +19,7 @@
package org.apache.cxf.cwiki;
+import java.io.File;
import java.io.Writer;
import java.net.MalformedURLException;
import java.net.URL;
@@ -36,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;
@@ -52,6 +53,85 @@ 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 {
+ 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 {
+ 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 null;
+ }
+
+ private String findPageByID(String id) throws Exception {
+ String location = findPageByID(exporter, id);
+ if (location == null) {
+ for (SiteExporter siteExporter : SiteExporter.siteExporters) {
+ if (exporter == siteExporter) {
+ continue;
+ }
+ location = findPageByID(siteExporter, id);
+ if (location != null) {
+ break;
+ }
+ }
+ }
+ return location;
+ }
+
+ private String findPageByID(SiteExporter siteExporter, String url) throws Exception {
+ AbstractPage p = siteExporter.findPageByID(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 (via id) to " + location);
+ }
+ return location;
+ }
+ return null;
+ }
+
//CHECKSTYLE:OFF
public void startElement(String uri, String localName, String qName, final Attributes atts)
throws SAXException {
@@ -76,9 +156,9 @@ public class ConfluenceCleanupWriter ext
href = href.substring(0, href.indexOf('?'));
}
try {
- final Page p = exporter.findPageByURL(href);
+ String p = findPageWithURL(href);
if (p != null) {
- newAtts.addMapping("href", p.createFileName() + params);
+ newAtts.addMapping("href", p + params);
} else {
if (href.indexOf('~') == -1) {
//link to a user page is OK, don't warn about it
@@ -93,14 +173,23 @@ public class ConfluenceCleanupWriter ext
} else if (href != null && href.startsWith("/confluence/plugins/")) {
newAtts.addMapping("href", SiteExporter.ROOT + href.substring(11));
} else if (href != null && href.contains("/confluence/pages/viewpage.action")) {
+ String params = "";
+ if (href.indexOf('#') != -1) {
+ params = href.substring(href.indexOf('#'));
+ href = href.substring(0, href.indexOf('#'));
+ }
int idx = href.indexOf("pageId=");
String id = href.substring(idx + 7);
- Page p = exporter.findPageByID(id);
- if (p != null) {
- newAtts.addMapping("href", p.createFileName());
- } else {
- System.out.println("Could not find page for id: " + id
- + " linked from " + page.getTitle());
+ try {
+ String location = findPageByID(id);
+ if (location != null) {
+ newAtts.addMapping("href", location + params);
+ } else {
+ System.out.println("Could not find page for id: " + id
+ + " linked from " + page.getTitle());
+ }
+ } catch (Exception e) {
+ throw new SAXException(e);
}
} else if (href != null && href.contains("/confluence/download/attachments")) {
href = href.substring(href.lastIndexOf("/"));
@@ -310,4 +399,32 @@ public class ConfluenceCleanupWriter ext
}
}
+ private static String getRelativePath(File root, File current, File other) throws Exception {
+ if (current.equals(other)) {
+ return "";
+ }
+
+ String rootPath = root.getCanonicalPath();
+ String currentPath = current.getCanonicalPath();
+ StringBuilder builder = new StringBuilder();
+ while (!rootPath.equals(currentPath)) {
+ current = current.getParentFile();
+ currentPath = current.getCanonicalPath();
+ builder.append("../");
+ }
+
+ String otherPath = other.getCanonicalPath();
+
+ if (rootPath.equals(otherPath)) {
+ // nothing to do
+ } else if (otherPath.startsWith(rootPath)) {
+ String name = otherPath.substring(rootPath.length() + 1);
+ builder.append(name);
+ builder.append("/");
+ } else {
+ throw new RuntimeException("Non-relative locations: " + rootPath + " " + otherPath);
+ }
+
+ return builder.toString();
+ }
}
Modified: cxf/web/src/main/java/org/apache/cxf/cwiki/Page.java
URL: http://svn.apache.org/viewvc/cxf/web/src/main/java/org/apache/cxf/cwiki/Page.java?rev=1441099&r1=1441098&r2=1441099&view=diff
==============================================================================
--- cxf/web/src/main/java/org/apache/cxf/cwiki/Page.java (original)
+++ cxf/web/src/main/java/org/apache/cxf/cwiki/Page.java Thu Jan 31 18:20:35 2013
@@ -22,6 +22,7 @@ package org.apache.cxf.cwiki;
import java.io.Serializable;
import java.util.HashMap;
+import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.CopyOnWriteArraySet;
@@ -30,20 +31,20 @@ 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 XMLGregorianCalendar modified;
final String parent;
- final String title;
- final String url;
+ final String spaceKey;
Map<String, String> attachments;
Set<String> includes;
Map<String, Integer> childrenOf;
@@ -51,20 +52,24 @@ public class Page implements Serializabl
transient String renderedContent;
transient String renderedDivContent;
transient String divIdForContent;
+
+ 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");
- String mod = DOMUtils.getChildContent(doc.getDocumentElement().getFirstChild(), "modified");
- if (mod == null) {
- mod = DOMUtils.getChildContent(doc.getDocumentElement().getFirstChild(), "publishDate");
- }
+
+ parent = DOMUtils.getChildContent(root, "parentId");
+ spaceKey = DOMUtils.getChildContent(root, "space");
+
+ 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) {
@@ -109,6 +114,20 @@ public class Page implements Serializabl
}
}
+ /*
+ * Makes a shallow copy without any content
+ */
+ public Page(Page source) {
+ super(source);
+ this.modified = source.modified;
+ this.parent = source.parent;
+ this.spaceKey = source.spaceKey;
+ this.attachments = source.attachments;
+ this.includes = source.includes;
+ this.childrenOf = source.childrenOf;
+ this.exporter = source.exporter;
+ }
+
public boolean hasChildrenOf(String t, int d) {
if (childrenOf == null) {
return false;
@@ -127,15 +146,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;
}
@@ -143,33 +158,13 @@ public class Page implements Serializabl
public void setContent(String c) {
renderedContent = c;
}
+
public String getContent() {
return renderedContent;
}
- public String getURL() {
- return url;
- }
-
- 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 String getSpaceKey() {
+ return spaceKey;
}
public void addAttachment(String aid, String filename) {
@@ -199,4 +194,37 @@ public class Page implements Serializabl
}
return null;
}
+
+ public String getLink() {
+ StringBuffer buffer = new StringBuffer();
+ buffer.append("<a href=\"");
+ buffer.append(url);
+ buffer.append("\" title=\"");
+ buffer.append(title);
+ buffer.append("\">");
+ buffer.append(title);
+ buffer.append("</a>");
+ return buffer.toString();
+ }
+
+ public Space getSpace() {
+ return SiteExporter.getSpace(spaceKey);
+ }
+
+ public boolean hasChildren() {
+ return exporter.hasChildren(this);
+ }
+
+ public List<Page> getChildren() {
+ return exporter.getChildren(this);
+ }
+
+ protected void setExporter(SiteExporter exporter) {
+ this.exporter = exporter;
+ }
+
+ protected SiteExporter getExporter() {
+ return exporter;
+ }
+
}
Added: cxf/web/src/main/java/org/apache/cxf/cwiki/PageManager.java
URL: http://svn.apache.org/viewvc/cxf/web/src/main/java/org/apache/cxf/cwiki/PageManager.java?rev=1441099&view=auto
==============================================================================
--- cxf/web/src/main/java/org/apache/cxf/cwiki/PageManager.java (added)
+++ cxf/web/src/main/java/org/apache/cxf/cwiki/PageManager.java Thu Jan 31 18:20:35 2013
@@ -0,0 +1,63 @@
+/**
+ * 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.util.HashMap;
+import java.util.Map;
+
+/**
+ *
+ */
+public class PageManager {
+
+ private SiteExporter exporter;
+ private String dir;
+ private Map<String, Page> pages = new HashMap<String, Page>();
+
+ public PageManager(SiteExporter exporter) {
+ this.exporter = exporter;
+ }
+
+ public void setDirectory(String d) {
+ this.dir = d;
+ }
+
+ public Page getPage(String spaceKey, String title) throws Exception {
+ // XXX: spaceKey must match exporter.getSpace().getKey()
+
+ // lookup cached page
+ Page cachedPage = pages.get(title);
+ if (cachedPage == null) {
+ // lookup real page
+ Page page = exporter.findPage(title);
+ if (page != null) {
+ cachedPage = new Page(page);
+ cachedPage.directory = dir;
+ exporter.loadPageContent(cachedPage, null, null);
+ pages.put(title, cachedPage);
+ } else {
+ System.err.println("Page not found: " + title);
+ }
+ }
+
+ return cachedPage;
+ }
+
+}
Added: cxf/web/src/main/java/org/apache/cxf/cwiki/Renderer.java
URL: http://svn.apache.org/viewvc/cxf/web/src/main/java/org/apache/cxf/cwiki/Renderer.java?rev=1441099&view=auto
==============================================================================
--- cxf/web/src/main/java/org/apache/cxf/cwiki/Renderer.java (added)
+++ cxf/web/src/main/java/org/apache/cxf/cwiki/Renderer.java Thu Jan 31 18:20:35 2013
@@ -0,0 +1,52 @@
+/**
+ * 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;
+
+/**
+ *
+ */
+public class Renderer {
+
+ protected SiteExporter exporter;
+
+ public Renderer(SiteExporter exporter) {
+ this.exporter = exporter;
+ }
+
+ public String convertWikiToXHtml(Object context, String content) {
+ if (content != null) {
+ int start = 0;
+ if (content.startsWith("<div")) {
+ int pos = content.indexOf(">", 1);
+ if (pos != -1) {
+ start = pos + 1;
+ }
+ }
+ int end = content.length();
+ if (content.endsWith("</div>")) {
+ end -= "</div>".length();
+ }
+ content = content.substring(start, end);
+ }
+
+ return content;
+ }
+
+}
Modified: cxf/web/src/main/java/org/apache/cxf/cwiki/SiteExporter.java
URL: http://svn.apache.org/viewvc/cxf/web/src/main/java/org/apache/cxf/cwiki/SiteExporter.java?rev=1441099&r1=1441098&r2=1441099&view=diff
==============================================================================
--- cxf/web/src/main/java/org/apache/cxf/cwiki/SiteExporter.java (original)
+++ cxf/web/src/main/java/org/apache/cxf/cwiki/SiteExporter.java Thu Jan 31 18:20:35 2013
@@ -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,7 @@ 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;
import org.ccil.cowan.tagsoup.XMLWriter;
@@ -95,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;
@@ -110,10 +112,16 @@ public class SiteExporter implements Run
static String loginToken;
static Dispatch<Document> dispatch;
static AtomicInteger asyncCount = new AtomicInteger();
+ static Map<String, Space> spaces = new ConcurrentHashMap<String, Space>();
+ static List<SiteExporter> siteExporters;
Map<String, Page> pages = new ConcurrentHashMap<String, Page>();
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>();
+
String spaceKey = "CXF";
String pageCacheFile = "pagesConfig.obj";
@@ -125,7 +133,9 @@ public class SiteExporter implements Run
File outputDir = rootOutputDir;
Template template;
+ Space space;
+
public SiteExporter(String fileName, boolean force) throws Exception {
forceAll = force;
@@ -161,18 +171,19 @@ public class SiteExporter implements Run
props.put("resource.loader", "url");
props.put("url.resource.loader.class", clzName);
props.put("url.resource.loader.root", "");
- synchronized (Velocity.class) {
- Velocity.init(props);
+
+ VelocityEngine engine = new VelocityEngine();
+ engine.init(props);
- URL url = ClassLoaderUtils.getResource(templateName, this.getClass());
- if (url == null) {
- File file = new File(templateName);
- if (file.exists()) {
- url = file.toURI().toURL();
- }
+ URL url = ClassLoaderUtils.getResource(templateName, this.getClass());
+ if (url == null) {
+ File file = new File(templateName);
+ if (file.exists()) {
+ url = file.toURI().toURL();
}
- template = Velocity.getTemplate(url.toURI().toString());
}
+ template = engine.getTemplate(url.toURI().toString());
+
outputDir.mkdirs();
}
@@ -207,7 +218,7 @@ public class SiteExporter implements Run
public void run() {
try {
- doExport();
+ render();
} catch (Exception e) {
e.printStackTrace();
}
@@ -221,9 +232,13 @@ public class SiteExporter implements Run
}
}
- public void doExport() throws Exception {
+ /**
+ * @return true if some pages have changed - rendering is needed
+ * @throws Exception
+ */
+ public boolean initialize() throws Exception {
if (!forceAll) {
- loadPagesCache();
+ loadCache();
}
// debug stuff, force regen of a page
@@ -234,12 +249,22 @@ public class SiteExporter implements Run
if (modifiedPages.isEmpty() && checkRSS()) {
System.out.println("(" + spaceKey + ") No changes detected from RSS");
- return;
+ return false;
}
-
+
doLogin();
+ getSpace();
+ if ("-space-".equals(breadCrumbRoot)) {
+ breadCrumbRoot = space.getName();
+ }
+
+ loadBlog();
loadPages();
+ return true;
+ }
+
+ protected void render() throws Exception {
for (Page p : modifiedPages) {
if (globalPages.contains(p.getTitle())) {
modifiedPages.clear();
@@ -247,18 +272,20 @@ public class SiteExporter implements Run
break;
}
}
+
if (forceAll) {
modifiedPages.clear();
modifiedPages.addAll(pages.values());
+
+ modifiedBlog.clear();
+ modifiedBlog.addAll(blog.values());
}
-
- if (!modifiedPages.isEmpty()) {
+ if (!modifiedPages.isEmpty() || !modifiedBlog.isEmpty()) {
+ renderBlog();
renderPages();
- savePages();
+ saveCache();
}
-
-
}
@@ -277,15 +304,15 @@ public class SiteExporter implements Run
List<Element> els = DOMUtils.getChildrenWithName(doc.getDocumentElement(),
"http://www.w3.org/2005/Atom",
"entry");
- //XMLUtils.printDOM(doc);
+ // XMLUtils.printDOM(doc);
for (Element el : els) {
Element e2 = DOMUtils.getFirstChildWithName(el, "http://www.w3.org/2005/Atom", "updated");
String val = DOMUtils.getContent(e2);
XMLGregorianCalendar cal = DatatypeFactory.newInstance().newXMLGregorianCalendar(val);
e2 = DOMUtils.getFirstChildWithName(el, "http://www.w3.org/2005/Atom", "title");
String title = DOMUtils.getContent(e2);
- Page p = findPage(title);
+ Page p = findPage(title);
if (p != null) {
//found a modified page - need to rebuild
if (cal.compare(p.getModifiedTime()) > 0) {
@@ -293,24 +320,36 @@ public class SiteExporter implements Run
return false;
}
} else {
- System.out.println("(" + spaceKey + ") Did not find page for: " + title);
- return false;
+ BlogEntrySummary entry = findBlogEntry(title);
+ if (entry != null) {
+ // we don't have modified date so just assume it's modified
+ // we'll use version number to actually figure out if page is modified or not
+ System.out.println("(" + spaceKey + ") Changed blog page found: " + title);
+ return false;
+ } else {
+ System.out.println("(" + spaceKey + ") Did not find page for: " + title);
+ return false;
+ }
}
}
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();
}
private void renderPages() throws Exception {
+ PageManager pageManager = new PageManager(this);
+ Renderer renderer = new Renderer(this);
+
int total = modifiedPages.size();
int count = 0;
for (Page p : modifiedPages) {
@@ -321,9 +360,13 @@ public class SiteExporter implements Run
loadPageContent(p, null, null);
VelocityContext ctx = new VelocityContext();
- ctx.put("exporter", this);
+ ctx.put("autoexport", this);
ctx.put("page", p);
+ ctx.put("body", p.getContent());
ctx.put("confluenceUri", ROOT);
+ ctx.put("pageManager", pageManager);
+ ctx.put("renderer", renderer);
+ ctx.put("exporter", this);
File file = new File(outputDir, p.createFileName());
boolean isNew = !file.exists();
@@ -339,8 +382,55 @@ public class SiteExporter implements Run
} else {
svnCommitMessage.append("Modified: " + file.getName() + "\n");
}
+
+ p.setContent(null);
+ }
+ }
+
+ private void renderBlog() throws Exception {
+ PageManager pageManager = new PageManager(this);
+ Renderer renderer = new Renderer(this);
+
+ 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);
+
+ pageManager.setDirectory(entry.getDirectory());
+
+ VelocityContext ctx = new VelocityContext();
+ ctx.put("autoexport", this);
+ ctx.put("page", entry);
+ ctx.put("body", body);
+ ctx.put("confluenceUri", ROOT);
+ ctx.put("pageManager", pageManager);
+ ctx.put("renderer", renderer);
+ ctx.put("exporter", this);
+ ctx.put("isBlogEntry", Boolean.TRUE);
+
+ 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);
}
@@ -408,13 +498,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) {
@@ -464,21 +554,13 @@ public class SiteExporter implements Run
}
}
public Page findPage(String title) throws Exception {
- for (Page p : pages.values()) {
- if (title.equals(p.getTitle())) {
- return p;
- }
- }
- return null;
+ return (Page) findByTitle(title, pages.values());
}
+
public Page findPageByURL(String url) throws Exception {
- for (Page p : pages.values()) {
- if (p.getURL().endsWith(url)) {
- return p;
- }
- }
- return null;
+ return (Page) findByURL(url, pages.values());
}
+
public Page findPageByID(String id) {
for (Page p : pages.values()) {
if (p.getId().equals(id)) {
@@ -487,14 +569,46 @@ public class SiteExporter implements Run
}
return null;
}
- public String breadcrumbs(Page page) {
- String separator = ">";
- String s = " " + separator + " ";
+ 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);
+ } else {
+ buffer.append("<a href=\"../../../index.html\">Index</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) {
StringBuffer buffer = new StringBuffer();
List<Page> p = new LinkedList<Page>();
String parentId = page.getParentId();
- Page parent = parentId == null ? null : pages.get(parentId);
+ Page parent = pages.get(parentId);
while (parent != null) {
p.add(0, parent);
parentId = parent.getParentId();
@@ -506,7 +620,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=\"");
@@ -514,7 +628,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());
@@ -549,7 +663,19 @@ public class SiteExporter implements Run
}
return p.getContent();
}
- private String loadPageContent(Page p, String divId, String divCls) throws Exception {
+ 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");
@@ -583,15 +709,7 @@ public class SiteExporter implements Run
doc.appendChild(el);
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;
+ return doc.getDocumentElement().getFirstChild().getTextContent().trim();
}
public String unwrap(String v) throws Exception {
@@ -625,27 +743,42 @@ 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()) {
+ p.setExporter(this);
+ }
}
}
- private Document getPagesDocument() throws Exception {
- return getElementsDocument("ns1:getPages");
- }
-
- private Document getBlogEntriesDocument() throws Exception {
- return getElementsDocument("ns1:getBlogEntries");
+ public int getBlogVersion(String pageId) throws Exception {
+ Document doc = XMLUtils.newDocument();
+ Element el = doc.createElementNS(SOAPNS, "ns1:getBlogEntry");
+ Element el2 = doc.createElement("in0");
+ el.appendChild(el2);
+ el2.setTextContent(loginToken);
+ el2 = doc.createElement("in1");
+ el.appendChild(el2);
+ el2.setTextContent(pageId);
+ doc.appendChild(el);
+ doc = getDispatch().invoke(doc);
+
+ Node nd = doc.getDocumentElement().getFirstChild();
+
+ String version = DOMUtils.getChildContent(nd, "version");
+ return Integer.parseInt(version);
}
- private Document getElementsDocument(String function) throws Exception {
+ public void loadBlog() throws Exception {
Document doc = XMLUtils.newDocument();
- Element el = doc.createElementNS(SOAPNS, function);
+ Element el = doc.createElementNS(SOAPNS, "ns1:getBlogEntries");
Element el2 = doc.createElement("in0");
el.appendChild(el2);
el2.setTextContent(loginToken);
@@ -654,58 +787,88 @@ public class SiteExporter implements Run
el2.setTextContent(spaceKey);
doc.appendChild(el);
doc = getDispatch().invoke(doc);
- return doc;
- }
-
- private void loadAndAddPages(List<Future<?>> futures, Set<String> allPages, Set<Page> newPages) throws Exception {
- Document doc = getPagesDocument();
- ElementLoader loader = new ElementLoader()
- {
- public Future<?> loadElement(Element element, Set<String> allPages, Set<Page> newPages) throws Exception
- {
- return loadPage(element, allPages, newPages);
- }
- };
- loadAndAddElements(futures, loader, doc, allPages, newPages);
- }
-
- private void loadAndAddBlogEntries(List<Future<?>> futures,
- Set<String> allPages,
- Set<Page> newPages) throws Exception {
- Document doc = getBlogEntriesDocument();
- ElementLoader loader = new ElementLoader()
- {
- public Future<?> loadElement(Element element, Set<String> allPages, Set<Page> newPages) throws Exception
- {
- return loadBlogEntry(element, allPages, newPages);
- }
- };
- loadAndAddElements(futures, loader, doc, allPages, newPages);
- }
-
- private void loadAndAddElements(List<Future<?>> futures, ElementLoader loader, Document doc,
- Set<String> allPages, Set<Page> newPages) throws Exception {
+
+ Map<String, BlogEntrySummary> oldBlog = new ConcurrentHashMap<String, BlogEntrySummary>(blog);
+
Node nd = doc.getDocumentElement().getFirstChild().getFirstChild();
while (nd != null) {
if (nd instanceof Element) {
- futures.add(loader.loadElement((Element)nd, allPages, newPages));
+ BlogEntrySummary entry = new BlogEntrySummary((Element)nd);
+ entry.setVersion(getBlogVersion(entry.id));
+ BlogEntrySummary oldEntry = blog.put(entry.getId(), entry);
+ if (oldEntry == null || oldEntry.getVersion() != entry.getVersion()) {
+ 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 findBlogEntry(String title) throws Exception {
+ return (BlogEntrySummary) findByTitle(title, blog.values());
}
- private interface ElementLoader {
- Future<?> loadElement(Element element, Set<String> allPages, Set<Page> newPages) throws Exception;
+ public BlogEntrySummary findBlogEntryByURL(String url) throws Exception {
+ return (BlogEntrySummary) findByURL(url, blog.values());
+ }
+
+ private static AbstractPage findByURL(String url, Collection<? extends AbstractPage> pages) throws Exception {
+ for (AbstractPage p : pages) {
+ if (p.getURL().endsWith(url)) {
+ return p;
+ }
+ }
+ return null;
+ }
+
+ private static AbstractPage findByTitle(String title, Collection<? extends AbstractPage> pages) throws Exception {
+ for (AbstractPage p : pages) {
+ if (title.equals(p.getTitle())) {
+ return p;
+ }
+ }
+ return null;
}
public void loadPages() throws Exception {
+ Document doc = XMLUtils.newDocument();
+ Element el = doc.createElementNS(SOAPNS, "ns1:getPages");
+ 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);
+
Set<String> allPages = new CopyOnWriteArraySet<String>(pages.keySet());
Set<Page> newPages = new CopyOnWriteArraySet<Page>();
List<Future<?>> futures = new ArrayList<Future<?>>(allPages.size());
-
- loadAndAddPages(futures, allPages, newPages);
- loadAndAddBlogEntries(futures, allPages, newPages);
+ // XMLUtils.printDOM(doc.getDocumentElement());
+
+ Node nd = doc.getDocumentElement().getFirstChild().getFirstChild();
+ while (nd != null) {
+ if (nd instanceof Element) {
+ futures.add(loadPage((Element)nd, allPages, newPages));
+ }
+ nd = nd.getNextSibling();
+ }
for (Future<?> f : futures) {
//wait for all the pages to be done
f.get();
@@ -731,6 +894,7 @@ public class SiteExporter implements Run
while (checkIncludes()) {
// nothing
}
+
}
public boolean checkIncludes() {
@@ -753,8 +917,7 @@ public class SiteExporter implements Run
return false;
}
public void checkForChildren(Page p) {
- String parentId = p.getParentId();
- Page parent = parentId == null ? null : pages.get(parentId);
+ Page parent = pages.get(p.getParentId());
int d = 1;
while (parent != null) {
for (Page p2 : pages.values()) {
@@ -768,6 +931,32 @@ public class SiteExporter implements Run
}
}
+ public static synchronized Space getSpace(String key) {
+ Space space = spaces.get(key);
+ if (space == null) {
+ try {
+ doLogin();
+
+ Document doc = XMLUtils.newDocument();
+ Element el = doc.createElementNS(SOAPNS, "ns1:getSpace");
+ Element el2 = doc.createElement("in0");
+ el.appendChild(el2);
+ el2.setTextContent(loginToken);
+ el2 = doc.createElement("in1");
+ el.appendChild(el2);
+ el2.setTextContent(key);
+ doc.appendChild(el);
+
+ Document out = getDispatch().invoke(doc);
+ space = new Space(out);
+ spaces.put(key, space);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+ return space;
+ }
+
public Future<?> loadPage(Element pageSumEl,
final Set<String> allPages,
final Set<Page> newPages) throws Exception {
@@ -781,36 +970,16 @@ public class SiteExporter implements Run
el2.setTextContent(DOMUtils.getChildContent(pageSumEl, "id"));
doc.appendChild(el);
- return getResponseHandler(doc, allPages, newPages);
- }
-
- public Future<?> loadBlogEntry(Element pageSumEl, final Set<String> allPages,
- final Set<Page> newPages) throws Exception {
- Document doc = XMLUtils.newDocument();
- Element el = doc.createElementNS(SOAPNS, "ns1:getBlogEntry");
- Element el2 = doc.createElement("in0");
- el.appendChild(el2);
- el2.setTextContent(loginToken);
- el2 = doc.createElement("in1");
- el.appendChild(el2);
- el2.setTextContent(DOMUtils.getChildContent(pageSumEl, "id"));
- doc.appendChild(el);
-
- return getResponseHandler(doc, allPages, newPages);
- }
-
- private Future<?> getResponseHandler(Document doc,
- final Set<String> allPages,
- final Set<Page> newPages) throws Exception {
- // make sure we only fire off about 15-20 or confluence may get a bit overloaded
+ //make sure we only fire off about 15-20 or confluence may get a bit overloaded
while (asyncCount.get() > 15) {
Thread.sleep(10);
}
asyncCount.incrementAndGet();
- return getDispatch().invokeAsync(doc, new AsyncHandler<Document>() {
+ Future<?> f = getDispatch().invokeAsync(doc, new AsyncHandler<Document>() {
public void handleResponse(Response<Document> doc) {
try {
Page page = new Page(doc.get());
+ page.setExporter(SiteExporter.this);
Page oldPage = pages.put(page.getId(), page);
if (oldPage == null || page.getModifiedTime().compare(oldPage.getModifiedTime()) > 0) {
modifiedPages.add(page);
@@ -829,9 +998,10 @@ 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();
@@ -855,7 +1025,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");
@@ -893,16 +1063,34 @@ public class SiteExporter implements Run
}
}
- List<Thread> threads = new ArrayList<Thread>(files.size());
+
+ List<SiteExporter> exporters = new ArrayList<SiteExporter>();
for (String file : files) {
- Thread t = new Thread(new SiteExporter(file, forceAll));
- threads.add(t);
- t.start();
+ exporters.add(new SiteExporter(file, forceAll));
}
- for (Thread t : threads) {
- t.join();
+
+ List<SiteExporter> modified = new ArrayList<SiteExporter>();
+ for (SiteExporter exporter : exporters) {
+ if (exporter.initialize()) {
+ modified.add(exporter);
+ }
}
+ // render stuff only if needed
+ if (!modified.isEmpty()) {
+ setSiteExporters(exporters);
+
+ List<Thread> threads = new ArrayList<Thread>(modified.size());
+ for (SiteExporter exporter : modified) {
+ Thread t = new Thread(exporter);
+ threads.add(t);
+ t.start();
+ }
+ for (Thread t : threads) {
+ t.join();
+ }
+ }
+
if (commit) {
File file = FileUtils.createTempFile("svncommit", "txt");
FileWriter writer = new FileWriter(file);
@@ -912,4 +1100,45 @@ public class SiteExporter implements Run
svnCommitMessage.setLength(0);
}
}
+
+ public boolean hasChildren(Page page) {
+ for (Page p : pages.values()) {
+ if (p == page) {
+ continue;
+ }
+ if (page.getId().equals(p.getParentId())) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ public List<Page> getChildren(Page page) {
+ List<Page> children = new ArrayList<Page>();
+ for (Page p : pages.values()) {
+ if (p == page) {
+ continue;
+ }
+ if (page.getId().equals(p.getParentId())) {
+ children.add(p);
+ }
+ }
+ return children;
+ }
+
+ public String link(Page page) {
+ return page.getLink();
+ }
+
+ public Space getSpace() {
+ if (space == null) {
+ space = getSpace(spaceKey);
+ }
+ return space;
+ }
+
+ private static void setSiteExporters(List<SiteExporter> exporters) {
+ siteExporters = exporters;
+ }
+
}
Added: cxf/web/src/main/java/org/apache/cxf/cwiki/Space.java
URL: http://svn.apache.org/viewvc/cxf/web/src/main/java/org/apache/cxf/cwiki/Space.java?rev=1441099&view=auto
==============================================================================
--- cxf/web/src/main/java/org/apache/cxf/cwiki/Space.java (added)
+++ cxf/web/src/main/java/org/apache/cxf/cwiki/Space.java Thu Jan 31 18:20:35 2013
@@ -0,0 +1,53 @@
+/**
+ * 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 org.w3c.dom.Document;
+
+import org.apache.cxf.helpers.DOMUtils;
+
+/**
+ *
+ */
+public class Space {
+
+ final String key;
+ final String name;
+ final String url;
+
+ public Space(Document doc) throws Exception {
+ // org.apache.cxf.helpers.XMLUtils.printDOM(doc.getDocumentElement());
+
+ key = DOMUtils.getChildContent(doc.getDocumentElement().getFirstChild(), "key");
+ name = DOMUtils.getChildContent(doc.getDocumentElement().getFirstChild(), "name");
+ url = DOMUtils.getChildContent(doc.getDocumentElement().getFirstChild(), "url");
+ }
+
+ public String getKey() {
+ return key;
+ }
+ public String getName() {
+ return name;
+ }
+ public String getURL() {
+ return url;
+ }
+
+}
Modified: cxf/web/template/template.vm
URL: http://svn.apache.org/viewvc/cxf/web/template/template.vm?rev=1441099&r1=1441098&r2=1441099&view=diff
==============================================================================
--- cxf/web/template/template.vm (original)
+++ cxf/web/template/template.vm Thu Jan 31 18:20:35 2013
@@ -98,8 +98,7 @@ $content
<td height="100%">
<!-- Content -->
<div class="wiki-content">
-#set($content = $page.getContent())
-$content
+$body
</div>
<!-- Content -->
</td>