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 2011/02/07 19:45:45 UTC

svn commit: r1068047 - in /cxf/web/src/main/java/org/apache/cxf/cwiki: ConfluenceCleanupWriter.java SiteExporter.java

Author: dkulp
Date: Mon Feb  7 18:45:45 2011
New Revision: 1068047

URL: http://svn.apache.org/viewvc?rev=1068047&view=rev
Log:
Use RSS feed as preliminary check for changes.  A bit faster than 200 soap calls.
Fix issues with links to pages with special characters.

Modified:
    cxf/web/src/main/java/org/apache/cxf/cwiki/ConfluenceCleanupWriter.java
    cxf/web/src/main/java/org/apache/cxf/cwiki/SiteExporter.java

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=1068047&r1=1068046&r2=1068047&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 Mon Feb  7 18:45:45 2011
@@ -70,6 +70,16 @@ public class ConfluenceCleanupWriter ext
                 } catch (Exception e) {
                     throw new SAXException(e);
                 }
+            } else if (href != null && href.contains("/confluence/pages/viewpage.action")) {
+                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());
+                }
             } else if (href != null && href.contains("/confluence/download/attachments")) {
                 href = href.substring(href.lastIndexOf("/"));
                 String dirName = page.createFileName();
@@ -140,12 +150,6 @@ public class ConfluenceCleanupWriter ext
         super.endElement(uri, localName, qName);
     }
 
-
-
-
-    
-
-
     final class AttributesWrapper implements Attributes {
         private final Attributes atts;
         private final Map<String, String> newAtts = new HashMap<String, String>();

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=1068047&r1=1068046&r2=1068047&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 Mon Feb  7 18:45:45 2011
@@ -41,6 +41,8 @@ import java.util.Map;
 import java.util.Properties;
 import java.util.Set;
 
+import javax.xml.datatype.DatatypeFactory;
+import javax.xml.datatype.XMLGregorianCalendar;
 import javax.xml.namespace.QName;
 import javax.xml.ws.Dispatch;
 import javax.xml.ws.Service;
@@ -59,6 +61,7 @@ import org.apache.cxf.helpers.IOUtils;
 import org.apache.cxf.helpers.XMLUtils;
 import org.apache.cxf.interceptor.LoggingInInterceptor;
 import org.apache.cxf.interceptor.LoggingOutInterceptor;
+import org.apache.cxf.staxutils.StaxUtils;
 import org.apache.velocity.Template;
 import org.apache.velocity.VelocityContext;
 import org.apache.velocity.app.Velocity;
@@ -94,6 +97,7 @@ public class SiteExporter {
     String password = "autoexport-cxf";
     String spaceKey = "CXF";
     String pageCacheFile = "pagesConfig.obj";
+    boolean forceAll;
     
     File outputDir = new File(".");
 
@@ -128,6 +132,8 @@ public class SiteExporter {
                 spaceKey = it.next(); 
             } else if ("-cache".equals(s)) {
                 pageCacheFile = it.next();
+            } else if ("-force".equals(s)) {
+                forceAll = true;
             }
         }
         
@@ -142,6 +148,11 @@ public class SiteExporter {
     }
     
     public void run() throws Exception {
+        loadPagesCache();
+        if (checkRSS()) {
+            return;
+        }
+        
         doLogin();
         loadPages();
         
@@ -151,6 +162,9 @@ public class SiteExporter {
                 break;
             }
         }
+        if (forceAll) {
+            modifiedPages = new LinkedList<Page>(pages.values());
+        }
         /*
         // debug stuff, force regen of a page
         modifiedPages.add(findPage("Setting up Eclipse for Running and Debugging Distributed OSGi"));
@@ -158,12 +172,49 @@ public class SiteExporter {
         modifiedPages.add(findPage("FAQ"));
         modifiedPages.add(findPage("Apache CXF 2.1.3 Release Notes"));
         */
-        //modifiedPages.add(findPage("Index"));
         
         renderPages();
         savePages();
     }
 
+    public boolean checkRSS() throws Exception {
+        if (forceAll || pages == null) {
+            return false;
+        }
+        URL url = new URL(ROOT + "/createrssfeed.action?types=page&types=blogpost&types=mail&"
+                          //+ "types=comment&"  //cannot handle comment updates yet
+                          + "types=attachment&statuses=created&statuses=modified"
+                          + "&spaces=" + spaceKey + "&rssType=atom&maxResults=20&timeSpan=5"
+                          + "&publicFeed=true");
+        InputStream ins = url.openStream();
+        Document doc = StaxUtils.read(ins);
+        ins.close();
+        List<Element> els = DOMUtils.getChildrenWithName(doc.getDocumentElement(),
+                                                        "http://www.w3.org/2005/Atom", 
+                                                        "entry");
+        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);
+            
+            if (p != null) {
+                //found a modified page - need to rebuild
+                if (cal.compare(p.getModifiedTime()) > 0) {
+                    System.out.println("Changed page found: " + title);
+                    return false;
+                }
+            } else {
+                System.out.println("Did not find page for: " + title);
+                return false;
+            }
+        }
+        
+        return true;
+    }
+
     private void savePages() throws Exception {
         File file = new File(pageCacheFile);
         file.getParentFile().mkdirs();
@@ -260,7 +311,14 @@ public class SiteExporter {
         }
         return null;
     }
-    
+    public Page findPageByID(String id) {
+        for (Page p : pages.values()) {
+            if (p.getId().equals(id)) {
+                return p;
+            }
+        }
+        return null;
+    }
     public String breadcrumbs(Page page) {
         String separator = "&gt;";
         String s = "&nbsp;" + separator + "&nbsp;";
@@ -375,7 +433,7 @@ public class SiteExporter {
     }
 
     @SuppressWarnings("unchecked")
-    public void loadPages() throws Exception {
+    public void loadPagesCache() throws Exception {
         File file = new File(pageCacheFile);
         if (file.exists()) {
             FileInputStream fin = new FileInputStream(pageCacheFile);
@@ -383,7 +441,8 @@ public class SiteExporter {
             pages = (Map)oin.readObject();
             oin.close();
         }
-        
+    }
+    public void loadPages() throws Exception {
         Document doc = XMLUtils.newDocument();
         Element el = doc.createElementNS(SOAPNS, "ns1:getPages");
         Element el2 = doc.createElement("in0");
@@ -457,4 +516,5 @@ public class SiteExporter {
         new SiteExporter(Arrays.asList(args)).run();
     }
 
+
 }