cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dk...@apache.org
Subject svn commit: r1441049 - in /cxf/web: pom.xml src/main/java/org/apache/cxf/cwiki/Page.java src/main/java/org/apache/cxf/cwiki/SiteExporter.java
Date Thu, 31 Jan 2013 16:31:42 GMT
Author: dkulp
Date: Thu Jan 31 16:31:41 2013
New Revision: 1441049

URL: http://svn.apache.org/viewvc?rev=1441049&view=rev
Log:
Patch from Uli to add blog entries to the exported content

Modified:
    cxf/web/pom.xml
    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/pom.xml
URL: http://svn.apache.org/viewvc/cxf/web/pom.xml?rev=1441049&r1=1441048&r2=1441049&view=diff
==============================================================================
--- cxf/web/pom.xml (original)
+++ cxf/web/pom.xml Thu Jan 31 16:31:41 2013
@@ -28,11 +28,11 @@
     <parent>
         <groupId>org.apache.cxf</groupId>
         <artifactId>cxf-parent</artifactId>
-        <version>2.5.2</version>
+        <version>2.6.5</version>
     </parent>
 
     <properties>
-        <cxf.version>2.5.2</cxf.version>
+        <cxf.version>2.6.5</cxf.version>
         <extra.arg></extra.arg>
         <svn.arg1></svn.arg1>
         <svn.arg2></svn.arg2>

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=1441049&r1=1441048&r2=1441049&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 16:31:41 2013
@@ -59,6 +59,9 @@ public class Page implements Serializabl
         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");
+        }
         modified = DatatypeFactory.newInstance().newXMLGregorianCalendar(mod);
         
         String c = DOMUtils.getChildContent(doc.getDocumentElement().getFirstChild(), "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=1441049&r1=1441048&r2=1441049&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 16:31:41 2013
@@ -494,7 +494,7 @@ public class SiteExporter implements Run
         StringBuffer buffer = new StringBuffer();
         List<Page> p = new LinkedList<Page>();
         String parentId = page.getParentId();
-        Page parent = pages.get(parentId);
+        Page parent = parentId == null ? null : pages.get(parentId);
         while (parent != null) {
             p.add(0, parent);
             parentId = parent.getParentId();
@@ -634,9 +634,18 @@ public class SiteExporter implements Run
             oin.close();
         }
     }
-    public void loadPages() throws Exception {
+    
+    private Document getPagesDocument() throws Exception {
+        return getElementsDocument("ns1:getPages");
+    }
+    
+    private Document getBlogEntriesDocument() throws Exception {
+        return getElementsDocument("ns1:getBlogEntries");
+    }
+    
+    private Document getElementsDocument(String function) throws Exception {
         Document doc = XMLUtils.newDocument();
-        Element el = doc.createElementNS(SOAPNS, "ns1:getPages");
+        Element el = doc.createElementNS(SOAPNS, function);
         Element el2 = doc.createElement("in0");
         el.appendChild(el2);
         el2.setTextContent(loginToken);
@@ -645,19 +654,58 @@ public class SiteExporter implements Run
         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());
-        
-        //XMLUtils.printDOM(doc.getDocumentElement());
+        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 {
         Node nd = doc.getDocumentElement().getFirstChild().getFirstChild();
         while (nd != null) {
             if (nd instanceof Element) {
-                futures.add(loadPage((Element)nd, allPages, newPages));
+                futures.add(loader.loadElement((Element)nd, allPages, newPages));
             }
             nd = nd.getNextSibling();
         }
+    }
+    
+    private interface ElementLoader {
+        Future<?> loadElement(Element element, Set<String> allPages, Set<Page>
newPages) throws Exception;
+    }
+    
+    public void loadPages() throws Exception {
+        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);
+        
         for (Future<?> f : futures) {
             //wait for all the pages to be done
             f.get();
@@ -683,7 +731,6 @@ public class SiteExporter implements Run
         while (checkIncludes()) {
             // nothing
         }
-        
     }
 
     public boolean checkIncludes() {
@@ -706,7 +753,8 @@ public class SiteExporter implements Run
         return false;
     }
     public void checkForChildren(Page p) {
-        Page parent = pages.get(p.getParentId());
+        String parentId = p.getParentId();
+        Page parent = parentId == null ? null : pages.get(parentId);
         int d = 1;
         while (parent != null) {
             for (Page p2 : pages.values()) {
@@ -733,12 +781,33 @@ public class SiteExporter implements Run
         el2.setTextContent(DOMUtils.getChildContent(pageSumEl, "id"));
         doc.appendChild(el);
         
-        //make sure we only fire off about 15-20 or confluence may get a bit overloaded
+        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
         while (asyncCount.get() > 15) {
             Thread.sleep(10);
         }
         asyncCount.incrementAndGet();
-        Future<?> f = getDispatch().invokeAsync(doc, new AsyncHandler<Document>()
{
+        return getDispatch().invokeAsync(doc, new AsyncHandler<Document>() {
             public void handleResponse(Response<Document> doc) {
                 try {
                     Page page = new Page(doc.get());
@@ -760,8 +829,7 @@ public class SiteExporter implements Run
                 }
             }
         });
-        return f;
-    }    
+    }
     
     private String updateContentLinks(Page page, String content,
                                       String id, String divCls) throws Exception {



Mime
View raw message