cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dk...@apache.org
Subject svn commit: r1065906 - in /cxf/web/src/main: java/org/apache/cxf/cwiki/ConfluenceCleanupWriter.java java/org/apache/cxf/cwiki/SiteExporter.java resources/template.vm
Date Tue, 01 Feb 2011 03:38:36 GMT
Author: dkulp
Date: Tue Feb  1 03:38:36 2011
New Revision: 1065906

URL: http://svn.apache.org/viewvc?rev=1065906&view=rev
Log:
Update so the generated pages are HTML4 transitional compliant 

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

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=1065906&r1=1065905&r2=1065906&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 Tue Feb  1 03:38:36
2011
@@ -20,6 +20,9 @@
 package org.apache.cxf.cwiki;
 
 import java.io.Writer;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Stack;
 
 import org.xml.sax.Attributes;
 import org.xml.sax.SAXException;
@@ -30,18 +33,23 @@ import org.ccil.cowan.tagsoup.XMLWriter;
  * 
  */
 public class ConfluenceCleanupWriter extends XMLWriter {
+
     private final Page page;
     private final SiteExporter exporter;
+    private final String divId;
+    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, Page page, String id)
{
         super(writer);
         this.page = page;
         this.exporter = exp;
+        this.divId = id;
     }
 
     public void startElement(String uri, String localName, String qName, final Attributes
atts)
         throws SAXException {
-        Attributes newAtts = atts;
+        AttributesWrapper newAtts = new AttributesWrapper(atts);
         if ("a".equals(localName.toLowerCase())
             || "a".equals(qName.toLowerCase())) {
             String href = atts.getValue("href");
@@ -54,8 +62,7 @@ public class ConfluenceCleanupWriter ext
                 try {
                     final Page p = exporter.findPageByURL(href);
                     if (p != null) {
-                        newAtts = new AttributesWrapper("href", p.createFileName()
-                                                        + params, atts);
+                        newAtts.addMapping("href", p.createFileName() + params);
                     } else {
                         System.out.println("Could not find page for " + href 
                                            + " linked from " + page.getTitle());
@@ -68,20 +75,23 @@ public class ConfluenceCleanupWriter ext
                 String dirName = page.createFileName();
                 dirName = dirName.substring(0, dirName.lastIndexOf(".")) + ".data";
 
-                newAtts = new AttributesWrapper("href", dirName + href, atts);
+                newAtts.addMapping("href", dirName + href);
             }
         } else if ("img".equals(localName.toLowerCase())
             || "img".equals(qName.toLowerCase())) {
             String href = atts.getValue("src");
+            if ("absmiddle".equalsIgnoreCase(atts.getValue("align"))) {
+                newAtts.addMapping("align", "middle");
+            }
             if (href != null && href.startsWith("/confluence/images/")) {
-                newAtts = new AttributesWrapper("src", SiteExporter.HOST + href, atts);
+                newAtts.addMapping("src", SiteExporter.HOST + href);
             } else if (href != null && href.startsWith("/confluence/download/attachments"))
{
                 href = href.substring(0, href.lastIndexOf('?'));
                 href = href.substring(href.lastIndexOf('/'));
                 String dirName = page.createFileName();
                 dirName = dirName.substring(0, dirName.lastIndexOf(".")) + ".data";
 
-                newAtts = new AttributesWrapper("src", dirName + href, atts);
+                newAtts.addMapping("src", dirName + href);
             } else if (href != null && href.startsWith("/confluence/download/thumbnails"))
{
                 
                 try {
@@ -96,26 +106,57 @@ public class ConfluenceCleanupWriter ext
                 String dirName = page.createFileName();
                 dirName = dirName.substring(0, dirName.lastIndexOf(".")) + ".thumbs";
 
-                newAtts = new AttributesWrapper("src", dirName + href, atts);
+                newAtts.addMapping("src", dirName + href);
+            }
+        } else if ("th".equals(localName.toLowerCase())
+            || "th".equals(qName.toLowerCase())) {
+            curTrCount++;
+        } else if ("td".equals(localName.toLowerCase())
+            || "td".equals(qName.toLowerCase())) {
+            curTrCount++;
+            newAtts.addMapping("nowrap", "nowrap");            
+        } else if ("tr".equals(localName.toLowerCase())
+            || "tr".equals(qName.toLowerCase())) {
+            trStack.push(curTrCount);
+            curTrCount = 0;
+        } else if ("div".equals(localName.toLowerCase())
+            || "div".equals(qName.toLowerCase())) {
+            String id = atts.getValue("id");
+            if ("ConfluenceContent".equals(id) && divId != null) {
+                newAtts.addMapping("id", divId);
             }
         }
         super.startElement(uri, localName, qName, newAtts);
     }
-    
+    public void endElement(String uri, String localName, String qName) throws SAXException
{
+        if ("tr".equals(localName.toLowerCase())
+            || "tr".equals(qName.toLowerCase())) {
+            if (curTrCount == 0) {
+                super.startElement("td");
+                super.endElement("td");
+            }
+            curTrCount = trStack.pop();
+        }
+        super.endElement(uri, localName, qName);
+    }
+
+
+
+
     
 
 
-    private final class AttributesWrapper implements Attributes {
+    final class AttributesWrapper implements Attributes {
         private final Attributes atts;
-        private final String attr;
-        private final String newval;
+        private final Map<String, String> newAtts = new HashMap<String, String>();
 
-        private AttributesWrapper(String attr, String newval, Attributes atts) {
-            this.attr = attr;
-            this.newval = newval;
+        private AttributesWrapper(Attributes atts) {
             this.atts = atts;
         }
-
+        public void addMapping(String k, String v) {
+            newAtts.put(k, v);
+        }
+        
         public int getLength() {
             return atts.getLength();
         }
@@ -153,22 +194,23 @@ public class ConfluenceCleanupWriter ext
         }
 
         public String getValue(int index) {
-            if (index == getIndex(attr)) {
-                return getValue(attr);
+            String f = getLocalName(index);
+            if (newAtts.containsKey(f.toLowerCase())) {
+                return newAtts.get(f.toLowerCase());
             }
             return atts.getValue(index);
         }
 
         public String getValue(String uri, String localName) {
-            if (attr.equals(localName.toLowerCase())) {
-                return newval;
+            if (newAtts.containsKey(localName.toLowerCase())) {
+                return newAtts.get(localName.toLowerCase());
             }
             return atts.getValue(uri, localName);
         }
 
         public String getValue(String qName) {
-            if (attr.equals(qName.toLowerCase())) {
-                return newval;
+            if (newAtts.containsKey(qName.toLowerCase())) {
+                return newAtts.get(qName.toLowerCase());
             }
             return atts.getValue(qName);
         }

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=1065906&r1=1065905&r2=1065906&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 Feb  1 03:38:36 2011
@@ -158,6 +158,7 @@ public class SiteExporter {
         modifiedPages.add(findPage("FAQ"));
         modifiedPages.add(findPage("Apache CXF 2.1.3 Release Notes"));
         */
+        //modifiedPages.add(findPage("Index"));
         
         renderPages();
         savePages();
@@ -290,6 +291,10 @@ public class SiteExporter {
         return buffer.toString();
     }
     
+    public String getPageContent(String title, String id) throws Exception {
+        Page p = findPage(title);
+        return loadPageContent(p, id);
+    }
     public String getPageContent(String title) throws Exception {
         Page p = findPage(title);
         String s = p.getContent();
@@ -299,6 +304,9 @@ public class SiteExporter {
         return p.getContent();
     }
     private void loadPageContent(Page p) throws Exception {
+        loadPageContent(p, null);
+    }
+    private String loadPageContent(Page p, String id) throws Exception {
         Document doc = XMLUtils.newDocument();
         Element el = doc.createElementNS(SOAPNS, "ns1:renderContent");
         Element el2 = doc.createElement("in0");
@@ -333,8 +341,11 @@ public class SiteExporter {
         doc = dispatch.invoke(doc);
         
         String content = doc.getDocumentElement().getFirstChild().getTextContent().trim();
-        
-        p.setContent(updateContentLinks(p, content));
+        content = updateContentLinks(p, content, id);
+        if (id == null) {
+            p.setContent(content);
+        }
+        return content;
     }
 
     
@@ -412,10 +423,10 @@ public class SiteExporter {
         }
     }    
     
-    private String updateContentLinks(Page page, String content) throws Exception {
+    private String updateContentLinks(Page page, String content, String id) throws Exception
{
         XMLReader parser = createTagSoupParser();
         StringWriter w = new StringWriter();
-        parser.setContentHandler(createContentHandler(page, w));
+        parser.setContentHandler(createContentHandler(page, w, id));
         parser.parse(new InputSource(new StringReader(content)));
         content = w.toString();
         content = content.substring("<html><body>".length());
@@ -435,8 +446,8 @@ public class SiteExporter {
 
         return reader;
     }
-    protected ContentHandler createContentHandler(final Page page, Writer w) {
-        XMLWriter xmlWriter = new ConfluenceCleanupWriter(this, w, page);
+    protected ContentHandler createContentHandler(final Page page, Writer w, String id) {
+        XMLWriter xmlWriter = new ConfluenceCleanupWriter(this, w, page, id);
         xmlWriter.setOutputProperty(XMLWriter.OMIT_XML_DECLARATION, "yes");
         xmlWriter.setOutputProperty(XMLWriter.METHOD, "html");
         return xmlWriter;

Modified: cxf/web/src/main/resources/template.vm
URL: http://svn.apache.org/viewvc/cxf/web/src/main/resources/template.vm?rev=1065906&r1=1065905&r2=1065906&view=diff
==============================================================================
--- cxf/web/src/main/resources/template.vm (original)
+++ cxf/web/src/main/resources/template.vm Tue Feb  1 03:38:36 2011
@@ -19,11 +19,12 @@
 -->
 <html>
   <head>
-    <link type="text/css" rel="stylesheet" href="http://cxf.apache.org/resources/site.css"></link>
+    <link type="text/css" rel="stylesheet" href="http://cxf.apache.org/resources/site.css">
     <script src="http://cxf.apache.org/resources/space.js" type="text/javascript"></script>
-
-<meta name="keywords" content="business integration, EAI, SOA, Service Oriented Architecture,
web services, SOAP, JBI, JMS, WSDL, XML, EDI, Electronic Data Interchange, standards support,
integration standards, application integration, middleware, software, solutions, services,
CXF, open source"/>
-<meta name="description" content"Apache CXF, Services Framework - $page.title" />
+    
+<meta http-equiv="Content-type" content="text/html;charset=UTF-8">
+<meta name="keywords" content="business integration, EAI, SOA, Service Oriented Architecture,
web services, SOAP, JBI, JMS, WSDL, XML, EDI, Electronic Data Interchange, standards support,
integration standards, application integration, middleware, software, solutions, services,
CXF, open source">
+<meta name="description" content="Apache CXF, Services Framework - $page.title">
     <title>
 Apache CXF -- $page.title
     </title>
@@ -32,19 +33,19 @@ Apache CXF -- $page.title
 
 
 <table width="100%" cellpadding="0" cellspacing="0">
-  <tr width="100%">
+  <tr>
     <td id="cell-0-0" colspan="2">&nbsp;</td>
     <td id="cell-0-1">&nbsp;</td>
     <td id="cell-0-2" colspan="2">&nbsp;</td>
   </tr>
-  <tr width="100%">
+  <tr>
     <td id="cell-1-0">&nbsp;</td>
     <td id="cell-1-1">&nbsp;</td>
     <td id="cell-1-2">
       <div style="padding: 5px;">
         <div id="banner">
           <!-- Banner -->
-#set($content = $exporter.getPageContent("Banner"))
+#set($content = $exporter.getPageContent("Banner", "banner-content"))
 $content
           <!-- Banner -->
         </div>
@@ -63,7 +64,7 @@ $content
             <td>
               <div align="right">
                 <!-- Quicklinks -->
-#set($content = $exporter.getPageContent("QuickLinks"))
+#set($content = $exporter.getPageContent("QuickLinks", "quicklinks"))
 $content
                 <!-- Quicklinks -->
               </div>
@@ -75,18 +76,18 @@ $content
     <td id="cell-1-3">&nbsp;</td>
     <td id="cell-1-4">&nbsp;</td>
   </tr>
-  <tr width="100%">
+  <tr>
     <td id="cell-2-0" colspan="2">&nbsp;</td>
     <td id="cell-2-1">
       <table>
-        <tr height="100%" valign="top">
+        <tr valign="top">
           <td height="100%">
             <div id="wrapper-menu-page-right">
               <div id="wrapper-menu-page-top">
                 <div id="wrapper-menu-page-bottom">
                   <div id="menu-page">
                     <!-- NavigationBar -->
-#set($content = $exporter.getPageContent("Navigation"))
+#set($content = $exporter.getPageContent("Navigation", "navigation"))
 $content
                     <!-- NavigationBar -->
                   </div>
@@ -107,7 +108,7 @@ $content
    </td>
    <td id="cell-2-2" colspan="2">&nbsp;</td>
   </tr>
-  <tr width="100%">
+  <tr>
    <td id="cell-3-0">&nbsp;</td>
    <td id="cell-3-1">&nbsp;</td>
    <td id="cell-3-2">
@@ -116,7 +117,7 @@ $content
        <div id="site-footer">
          <a href="http://cxf.apache.org/privacy-policy.html">Privacy Policy</a>
- 
          (<a href="$confluenceUri/pages/editpage.action?pageId=$page.id">edit page</a>)

-	 (<a href="$page.getURL()?showComments=true&showCommentArea=true#addcomment">add
comment</a>)
+	 (<a href="$page.getURL()?showComments=true&amp;showCommentArea=true#addcomment">add
comment</a>)
        </div>
        <!-- Footer -->
      </div>
@@ -124,7 +125,7 @@ $content
    <td id="cell-3-3">&nbsp;</td>
    <td id="cell-3-4">&nbsp;</td>
   </tr>
-  <tr width="100%">
+  <tr>
     <td id="cell-4-0" colspan="2">&nbsp;</td>
     <td id="cell-4-1">&nbsp;</td>
     <td id="cell-4-2" colspan="2">&nbsp;</td>



Mime
View raw message