Author: dkulp
Date: Tue Jun 18 18:29:31 2013
New Revision: 1494238
URL: http://svn.apache.org/r1494238
Log:
Start the process of supporting the newer confluence version
Modified:
cxf/web/src/main/java/org/apache/cxf/cwiki/Page.java
cxf/web/src/main/java/org/apache/cxf/cwiki/SiteExporter.java
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=1494238&r1=1494237&r2=1494238&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 Tue Jun 18 18:29:31
2013
@@ -21,6 +21,7 @@ package org.apache.cxf.cwiki;
import java.io.Serializable;
+import java.io.StringReader;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -33,13 +34,23 @@ import javax.xml.datatype.XMLGregorianCa
import org.w3c.dom.Document;
import org.w3c.dom.Element;
+import org.xml.sax.Attributes;
+import org.xml.sax.ContentHandler;
+import org.xml.sax.InputSource;
+import org.xml.sax.Locator;
+import org.xml.sax.SAXException;
+import org.xml.sax.XMLReader;
+
+
import org.apache.cxf.helpers.DOMUtils;
+import org.ccil.cowan.tagsoup.Parser;
/**
*
*/
public class Page extends AbstractPage implements Serializable {
+
private static final long serialVersionUID = 1L;
final XMLGregorianCalendar modified;
@@ -56,12 +67,13 @@ public class Page extends AbstractPage i
transient SiteExporter exporter;
- public Page(Document doc) throws Exception {
- this(DOMUtils.getFirstElement(doc.getDocumentElement()));
+ public Page(Document doc, SiteExporter exp) throws Exception {
+ this(DOMUtils.getFirstElement(doc.getDocumentElement()), exp);
}
- public Page(Element root) throws Exception {
+ public Page(Element root, SiteExporter exp) throws Exception {
super(root);
+ exporter = exp;
//org.apache.cxf.helpers.XMLUtils.printDOM(doc.getDocumentElement());
parent = DOMUtils.getChildContent(root, "parentId");
@@ -72,53 +84,13 @@ public class Page extends AbstractPage i
String c = DOMUtils.getChildContent(root, "content");
if (c != null) {
- int idx = c.indexOf("{children");
- while (idx != -1) {
- if (childrenOf == null) {
- childrenOf = new HashMap<String, Integer>();
- }
- idx += 9;
- if (c.charAt(idx) != '}') {
- // {children:page=Foo|...}
- idx++;
- int idx2 = c.indexOf('}', idx);
- String paramString = c.substring(idx, idx2);
- String params[] = paramString.split("\\||=");
- String page = null;
- int depth = 1;
- for (int x = 0; x < params.length; x++) {
- if ("page".equals(params[x])) {
- page = params[x + 1];
- x++;
- } else if ("depth".equals(params[x])) {
- depth = Integer.parseInt(params[x + 1]);
- x++;
- }
- }
- childrenOf.put(page, depth);
- } else {
- childrenOf.put(title, 1);
- }
- idx = c.indexOf("{children", idx);
- }
-
- idx = c.indexOf("{include:");
- while (idx != -1) {
- int idx2 = c.indexOf("}", idx);
- String inc = c.substring(idx + 9, idx2);
- if (includes == null) {
- includes = new CopyOnWriteArraySet<String>();
- }
- includes.add(inc);
- idx = c.indexOf("{include:", idx2);
- }
- idx = c.indexOf("{blog-posts");
- if (idx != -1) {
- hasBlog = true;
+ if (exp.getAPIVersion() == 2) {
+ checkContentV2(c);
+ } else {
+ checkContentV1(c);
}
}
}
-
/*
* Makes a shallow copy without any content
*/
@@ -134,6 +106,76 @@ public class Page extends AbstractPage i
this.hasBlog = source.hasBlog;
}
+ private void checkContentV2(final String c) {
+ try {
+ //if ("Book In One Page".equals(title)) {
+ // System.out.println(c);
+ //}
+
+ XMLReader reader = new Parser();
+ reader.setFeature(Parser.namespacesFeature, true);
+ reader.setFeature(Parser.namespacePrefixesFeature, true);
+ reader.setProperty(Parser.schemaProperty, new
org.ccil.cowan.tagsoup.HTMLSchema() {
+ {
+ //problem with nested lists that the confluence {toc}
macro creates
+ elementType("ul", M_LI, M_BLOCK | M_LI, 0);
+ }
+ });
+ reader.setContentHandler(new V2ContentHandler(this));
+ reader.parse(new InputSource(new StringReader(c)));
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+ private void checkContentV1(String c) {
+ int idx = c.indexOf("{children");
+ while (idx != -1) {
+ if (childrenOf == null) {
+ childrenOf = new HashMap<String, Integer>();
+ }
+ idx += 9;
+ if (c.charAt(idx) != '}') {
+ // {children:page=Foo|...}
+ idx++;
+ int idx2 = c.indexOf('}', idx);
+ String paramString = c.substring(idx, idx2);
+ String params[] = paramString.split("\\||=");
+ String page = null;
+ int depth = 1;
+ for (int x = 0; x < params.length; x++) {
+ if ("page".equals(params[x])) {
+ page = params[x + 1];
+ x++;
+ } else if ("depth".equals(params[x])) {
+ depth = Integer.parseInt(params[x + 1]);
+ x++;
+ }
+ }
+ childrenOf.put(page, depth);
+ } else {
+ childrenOf.put(title, 1);
+ }
+ idx = c.indexOf("{children", idx);
+ }
+
+ idx = c.indexOf("{include:");
+ while (idx != -1) {
+ int idx2 = c.indexOf("}", idx);
+ String inc = c.substring(idx + 9, idx2);
+ if (includes == null) {
+ includes = new CopyOnWriteArraySet<String>();
+ }
+ includes.add(inc);
+ idx = c.indexOf("{include:", idx2);
+ }
+ idx = c.indexOf("{blog-posts");
+ if (idx != -1) {
+ hasBlog = true;
+ }
+ }
+
+
public boolean hasChildrenOf(String t, int d) {
if (childrenOf == null) {
return false;
@@ -236,5 +278,117 @@ public class Page extends AbstractPage i
public boolean hasBlog() {
return hasBlog;
}
+
+
+ static class V2ContentHandler implements ContentHandler {
+ private final Page page;
+
+ enum State {
+ NONE,
+ CHILDREN,
+ INCLUDE,
+ BLOG_POSTS,
+ };
+ private State state = State.NONE;
+ private Map<String, String> params = new HashMap<String, String>();
+ private String paramName;
+
+ V2ContentHandler(Page pg) {
+ page = pg;
+ }
+
+ public void setDocumentLocator(Locator locator) {
+ }
+
+ public void startDocument() throws SAXException {
+ }
+
+ public void endDocument() throws SAXException {
+ }
+
+ public void startPrefixMapping(String prefix, String uri) throws
SAXException {
+ }
+
+ public void endPrefixMapping(String prefix) throws SAXException {
+ }
+
+ public void startElement(String uri, String localName, String qName,
Attributes atts)
+ throws SAXException {
+ if ("macro".equals(localName)) {
+ String s = atts.getValue(uri, "name");
+ if ("children".equals(s)) {
+ state = State.CHILDREN;
+ } else if ("include".equals(s)) {
+ state = State.INCLUDE;
+ } else if ("blog-posts".equals(s)) {
+ state = State.BLOG_POSTS;
+ } else {
+ //System.out.println("Unknown macro: " + s);
+ }
+ params.clear();
+ paramName = null;
+ } else if ("parameter".equals(localName)) {
+ paramName = atts.getValue(uri, "name");
+ } else if ("default-parameter".equals(localName)) {
+ paramName = "default-parameter";
+ }
+ }
+
+ public void endElement(String uri, String localName, String qName)
throws SAXException {
+ if ("macro".equals(localName)) {
+ switch (state) {
+ case CHILDREN: {
+ String pageName = params.get("page");
+ String depth = params.get("depth");
+ if (depth == null || "".equals(depth.trim())) {
+ depth = "1";
+ }
+ if (page.childrenOf == null) {
+ page.childrenOf = new HashMap<String, Integer>();
+ }
+ if (pageName == null) {
+ page.childrenOf.put(page.title,
Integer.parseInt(depth));
+ } else {
+ page.childrenOf.put(pageName, Integer.parseInt(depth));
+ }
+ params.clear();
+ state = State.NONE;
+ break;
+ }
+ case INCLUDE:
+ if (page.includes == null) {
+ page.includes = new CopyOnWriteArraySet<String>();
+ }
+ page.includes.add(params.get("default-parameter"));
+ break;
+ case BLOG_POSTS:
+ page.hasBlog = true;
+ break;
+ default:
+ state = State.NONE;
+ break;
+ }
+ } else if ("parameter".equals(localName)) {
+ paramName = null;
+ } else if ("default-parameter".equals(localName)) {
+ paramName = null;
+ }
+ }
+
+ public void characters(char[] ch, int start, int length) throws
SAXException {
+ if (paramName != null) {
+ params.put(paramName, new String(ch, start, length));
+ }
+ }
+
+ public void ignorableWhitespace(char[] ch, int start, int length)
throws SAXException {
+ }
+
+ public void processingInstruction(String target, String data) throws
SAXException {
+ }
+
+ public void skippedEntity(String name) throws SAXException {
+ }
+ }
}
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=1494238&r1=1494237&r2=1494238&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 Tue Jun 18
18:29:31 2013
@@ -23,6 +23,7 @@ import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.FileWriter;
+import java.io.IOException;
import java.io.InputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
@@ -93,7 +94,7 @@ public class SiteExporter implements Run
static final String HOST = "https://cwiki.apache.org";
static final String ROOT = HOST + "/confluence";
- static final String RPC_ROOT = "/rpc/soap-axis/confluenceservice-v1";
+ static final String RPC_ROOT = "/rpc/soap-axis/confluenceservice-v";
static final String SOAPNS = "http://soap.rpc.confluence.atlassian.com";
static final String SEPARATOR = " > ";
@@ -104,6 +105,8 @@ public class SiteExporter implements Run
static String userName = "cxf-export-user";
static String password;
+ static int apiVersion = 1;
+
static boolean svn;
static boolean commit;
static StringBuilder svnCommitMessage = new StringBuilder();
@@ -192,7 +195,7 @@ public class SiteExporter implements Run
Service service = Service.create(new QName(SOAPNS, "Service"));
service.addPort(new QName(SOAPNS, "Port"),
SOAPBinding.SOAP11HTTP_BINDING,
- ROOT + RPC_ROOT);
+ ROOT + RPC_ROOT + apiVersion);
dispatch = service.createDispatch(new QName(SOAPNS, "Port"),
Document.class,
Service.Mode.PAYLOAD);
@@ -253,17 +256,41 @@ public class SiteExporter implements Run
}
doLogin();
+ checkVersion();
getSpace();
if ("-space-".equals(breadCrumbRoot)) {
breadCrumbRoot = space.getName();
}
-
loadBlog();
loadPages();
return true;
}
+ private void checkVersion() throws ParserConfigurationException,
IOException {
+ Document doc = XMLUtils.newDocument();
+ Element el = doc.createElementNS(SOAPNS, "ns1:getServerInfo");
+ Element el2 = doc.createElement("in0");
+ el.appendChild(el2);
+ el2.setTextContent(loginToken);
+ doc.appendChild(el);
+
+ doc = getDispatch().invoke(doc);
+ el =
DOMUtils.getFirstElement(DOMUtils.getFirstElement(doc.getDocumentElement()));
+ while (el != null) {
+ if ("majorVersion".equals(el.getLocalName())) {
+ String major = DOMUtils.getContent(el);
+ if (Integer.parseInt(major) >= 5) {
+ apiVersion = 2;
+ ((java.io.Closeable)dispatch).close();
+ dispatch = null;
+ }
+ }
+
+ el = DOMUtils.getNextElement(el);
+ }
+ }
+
protected void render() throws Exception {
for (Page p : modifiedPages) {
if (globalPages.contains(p.getTitle())) {
@@ -331,7 +358,7 @@ public class SiteExporter implements Run
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);
+ System.out.println("(" + spaceKey + ") Possible changed
blog page found: " + title);
return false;
} else {
System.out.println("(" + spaceKey + ") Did not find page
for: " + title);
@@ -754,14 +781,20 @@ public class SiteExporter implements Run
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);
+ try {
+ 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);
+ }
+ } catch (Throwable t) {
+ //invalid cache, punt
+ pages.clear();
+ blog.clear();
}
}
}
@@ -807,6 +840,9 @@ public class SiteExporter implements Run
if (oldEntry == null || oldEntry.getVersion() !=
entry.getVersion()) {
modifiedBlog.add(entry);
}
+ if (entry.getTitle().contains("2.9.7")) {
+ modifiedBlog.add(entry);
+ }
oldBlog.remove(entry.getId());
}
nd = nd.getNextSibling();
@@ -986,7 +1022,7 @@ public class SiteExporter implements Run
Future<?> f = getDispatch().invokeAsync(doc, new
AsyncHandler<Document>() {
public void handleResponse(Response<Document> doc) {
try {
- Page page = new Page(doc.get());
+ Page page = new Page(doc.get(), SiteExporter.this);
page.setExporter(SiteExporter.this);
Page oldPage = pages.put(page.getId(), page);
if (oldPage == null ||
page.getModifiedTime().compare(oldPage.getModifiedTime()) > 0) {
@@ -1076,7 +1112,6 @@ public class SiteExporter implements Run
for (String file : files) {
exporters.add(new SiteExporter(file, forceAll));
}
-
List<SiteExporter> modified = new ArrayList<SiteExporter>();
for (SiteExporter exporter : exporters) {
if (exporter.initialize()) {
@@ -1148,5 +1183,9 @@ public class SiteExporter implements Run
private static void setSiteExporters(List<SiteExporter> exporters) {
siteExporters = exporters;
}
+
+ public int getAPIVersion() {
+ return apiVersion;
+ }
}