cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dk...@apache.org
Subject svn commit: r1420835 - in /cxf/web/src/main/java/org/apache/cxf/cwiki: ConfluenceCleanupWriter.java SiteExporter.java
Date Wed, 12 Dec 2012 17:05:54 GMT
Author: dkulp
Date: Wed Dec 12 17:05:53 2012
New Revision: 1420835

URL: http://svn.apache.org/viewvc?rev=1420835&view=rev
Log:
Pull user images into the static site.

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=1420835&r1=1420834&r2=1420835&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 Wed Dec 12 17:05:53
2012
@@ -137,29 +137,39 @@ public class ConfluenceCleanupWriter ext
             String cls = atts.getValue("class");
             if (href != null && href.startsWith("/confluence/images/")) {
                 newAtts.addMapping("src", SiteExporter.HOST + href);
-            } else if (href != null && href.startsWith("/confluence/download/attachments")
-                && (cls == null || !cls.contains("userLogo"))) {
-                href = href.substring(0, href.lastIndexOf('?'));
-                href = href.substring(href.lastIndexOf('/'));
-                String dirName = page.createFileName();
-                dirName = dirName.substring(0, dirName.lastIndexOf(".")) + ".data";
-
-                newAtts.addMapping("src", dirName + href);
+            } else if (href != null && href.startsWith("/confluence/download/attachments"))
{
+                if (cls == null) {
+                    href = href.substring(0, href.lastIndexOf('?'));
+                    href = href.substring(href.lastIndexOf('/'));
+                    String dirName = page.createFileName();
+                    dirName = dirName.substring(0, dirName.lastIndexOf(".")) + ".data";
+
+                    newAtts.addMapping("src", dirName + href);
+                } else if (cls.contains("userLogo")) {
+                    String name = href;
+                    try {
+                        name = exporter.loadUserImage(page, href);
+                    } catch (Exception ex) {
+                        throw new SAXException(ex);
+                    }
+                    String dirName = page.createFileName();
+                    dirName = dirName.substring(0, dirName.lastIndexOf(".")) + ".userimage/";
+
+                    newAtts.addMapping("src", dirName + name);                    
+                } else {
+                    newAtts.addMapping("src", SiteExporter.HOST + href);
+                }
             } else if (href != null && href.startsWith("/confluence/download/thumbnails"))
{
-                
+                String name = href;
                 try {
-                    exporter.loadThumbnail(page, href);
+                    name = exporter.loadThumbnail(page, href);
                 } catch (Exception ex) {
                     throw new SAXException(ex);
                 }
-                if (href.indexOf('?') != -1) {
-                    href = href.substring(0, href.lastIndexOf('?'));
-                }
-                href = href.substring(href.lastIndexOf('/'));
                 String dirName = page.createFileName();
-                dirName = dirName.substring(0, dirName.lastIndexOf(".")) + ".thumbs";
+                dirName = dirName.substring(0, dirName.lastIndexOf(".")) + ".thumbs/";
 
-                newAtts.addMapping("src", dirName + href);
+                newAtts.addMapping("src", dirName + name);
             } else if (href != null && href.startsWith("/confluence")) {
                 newAtts.addMapping("src", SiteExporter.HOST + href);
             }

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=1420835&r1=1420834&r2=1420835&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 Wed Dec 12 17:05:53 2012
@@ -31,6 +31,7 @@ import java.io.StringReader;
 import java.io.StringWriter;
 import java.io.Writer;
 import java.net.URL;
+import java.net.URLConnection;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collection;
@@ -64,6 +65,7 @@ import org.xml.sax.InputSource;
 import org.xml.sax.XMLReader;
 
 import org.apache.cxf.common.classloader.ClassLoaderUtils;
+import org.apache.cxf.common.util.Base64Utility;
 import org.apache.cxf.helpers.CastUtils;
 import org.apache.cxf.helpers.DOMUtils;
 import org.apache.cxf.helpers.FileUtils;
@@ -401,11 +403,21 @@ public class SiteExporter implements Run
             el = DOMUtils.getNextElement(el);
         }
     }
-    void loadThumbnail(Page p, String href) throws Exception {
+    String loadUserImage(Page p, String href) throws Exception {
+        return loadPageBinaryData(p, href, "userimage");
+    }
+    String loadThumbnail(Page p, String href) throws Exception {
+        return loadPageBinaryData(p, href, "thumbs");
+    }
+    String loadPageBinaryData(Page p, String href, String type) throws Exception {
         String filename = href.substring(href.lastIndexOf('/') + 1);
+        filename = filename.replace(' ', '_');
+        if (filename.indexOf('?') != -1) {
+            filename = filename.substring(0, filename.indexOf('?'));
+        }
         
         String dirName = p.createFileName();
-        dirName = dirName.substring(0, dirName.lastIndexOf(".")) + ".thumbs";
+        dirName = dirName.substring(0, dirName.lastIndexOf(".")) + "." + type;
         File file = new File(outputDir, dirName);
         if (!file.exists()) {
             callSvn("mkdir", file.getAbsolutePath());
@@ -414,8 +426,15 @@ public class SiteExporter implements Run
         file = new File(file, filename);
         boolean exists = file.exists();
         FileOutputStream out = new FileOutputStream(file);
+        if (href.indexOf('?') != -1) {
+            href += "&os_authType=basic";
+        } else {
+            href += "?os_authType=basic";
+        }
         URL url = new URL(HOST + href);
-        InputStream ins = url.openStream();
+        URLConnection con = url.openConnection();
+        con.addRequestProperty("Authorization", getBasicAuthHeader());
+        InputStream ins = con.getInputStream();
         IOUtils.copy(ins, out);
         out.close();
         ins.close();
@@ -425,6 +444,11 @@ public class SiteExporter implements Run
         } else {
             svnCommitMessage.append("Modified: " + dirName + "/" + file.getName() + "\n");
         }
+        return file.getName();
+    }
+    public String getBasicAuthHeader() {
+        String userAndPass = userName + ":" + password;
+        return "Basic " + Base64Utility.encode(userAndPass.getBytes());
     }
     public Page findPage(String title) throws Exception {
         for (Page p : pages.values()) {



Mime
View raw message