servicemix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ge...@apache.org
Subject svn commit: r948010 - in /servicemix/maven-plugins/docs-maven-plugin/trunk/src: main/java/org/apache/servicemix/docs/ main/java/org/apache/servicemix/docs/confluence/ test/java/org/apache/servicemix/docs/confluence/ test/resources/org/apache/servicemix...
Date Tue, 25 May 2010 11:53:23 GMT
Author: gertv
Date: Tue May 25 11:53:22 2010
New Revision: 948010

URL: http://svn.apache.org/viewvc?rev=948010&view=rev
Log:
Add support for lists, images and tables to the docs-maven-plugin

Added:
    servicemix/maven-plugins/docs-maven-plugin/trunk/src/test/resources/org/apache/servicemix/docs/confluence/images.wiki
      - copied, changed from r940388, servicemix/maven-plugins/docs-maven-plugin/trunk/src/test/resources/org/apache/servicemix/docs/confluence/code-blocks.wiki
    servicemix/maven-plugins/docs-maven-plugin/trunk/src/test/resources/org/apache/servicemix/docs/confluence/images.xml
      - copied, changed from r940388, servicemix/maven-plugins/docs-maven-plugin/trunk/src/test/resources/org/apache/servicemix/docs/confluence/document2.xml
    servicemix/maven-plugins/docs-maven-plugin/trunk/src/test/resources/org/apache/servicemix/docs/confluence/lists.wiki
    servicemix/maven-plugins/docs-maven-plugin/trunk/src/test/resources/org/apache/servicemix/docs/confluence/lists.xml
    servicemix/maven-plugins/docs-maven-plugin/trunk/src/test/resources/org/apache/servicemix/docs/confluence/tables.wiki
    servicemix/maven-plugins/docs-maven-plugin/trunk/src/test/resources/org/apache/servicemix/docs/confluence/tables.xml
Modified:
    servicemix/maven-plugins/docs-maven-plugin/trunk/src/main/java/org/apache/servicemix/docs/ConfluenceToDocbookMojo.java
    servicemix/maven-plugins/docs-maven-plugin/trunk/src/main/java/org/apache/servicemix/docs/confluence/ConfluenceConverter.java
    servicemix/maven-plugins/docs-maven-plugin/trunk/src/test/java/org/apache/servicemix/docs/confluence/ConfluenceDocumentTest.java
    servicemix/maven-plugins/docs-maven-plugin/trunk/src/test/resources/org/apache/servicemix/docs/confluence/code-blocks.wiki
    servicemix/maven-plugins/docs-maven-plugin/trunk/src/test/resources/org/apache/servicemix/docs/confluence/code-blocks.xml

Modified: servicemix/maven-plugins/docs-maven-plugin/trunk/src/main/java/org/apache/servicemix/docs/ConfluenceToDocbookMojo.java
URL: http://svn.apache.org/viewvc/servicemix/maven-plugins/docs-maven-plugin/trunk/src/main/java/org/apache/servicemix/docs/ConfluenceToDocbookMojo.java?rev=948010&r1=948009&r2=948010&view=diff
==============================================================================
--- servicemix/maven-plugins/docs-maven-plugin/trunk/src/main/java/org/apache/servicemix/docs/ConfluenceToDocbookMojo.java
(original)
+++ servicemix/maven-plugins/docs-maven-plugin/trunk/src/main/java/org/apache/servicemix/docs/ConfluenceToDocbookMojo.java
Tue May 25 11:53:22 2010
@@ -20,14 +20,10 @@ import java.io.FileFilter;
 import java.io.FileReader;
 import java.io.FileWriter;
 import java.io.IOException;
-import java.net.URL;
-import java.net.URLStreamHandler;
-import java.net.URLStreamHandlerFactory;
 
 import org.apache.maven.plugin.AbstractMojo;
 import org.apache.maven.plugin.MojoExecutionException;
 import org.apache.servicemix.docs.confluence.ConfluenceConverter;
-import org.apache.servicemix.docs.snippet.SnippetHandler;
 
 /**
  * Convert pages in Confluence wiki markup to Docbook syntax

Modified: servicemix/maven-plugins/docs-maven-plugin/trunk/src/main/java/org/apache/servicemix/docs/confluence/ConfluenceConverter.java
URL: http://svn.apache.org/viewvc/servicemix/maven-plugins/docs-maven-plugin/trunk/src/main/java/org/apache/servicemix/docs/confluence/ConfluenceConverter.java?rev=948010&r1=948009&r2=948010&view=diff
==============================================================================
--- servicemix/maven-plugins/docs-maven-plugin/trunk/src/main/java/org/apache/servicemix/docs/confluence/ConfluenceConverter.java
(original)
+++ servicemix/maven-plugins/docs-maven-plugin/trunk/src/main/java/org/apache/servicemix/docs/confluence/ConfluenceConverter.java
Tue May 25 11:53:22 2010
@@ -32,7 +32,7 @@ import java.util.regex.Pattern;
 public class ConfluenceConverter {
 
     private static Pattern CHAPTER = Pattern.compile("^h1\\. .*");
-    private static Pattern CHAPTER_OR_SECTION = Pattern.compile("^h[1-6]\\. .*"); 
+    private static Pattern CHAPTER_OR_SECTION = Pattern.compile("^h[1-6]\\. .*");
 
     private BufferedReader reader;
     private PrintWriter writer;
@@ -56,22 +56,98 @@ public class ConfluenceConverter {
 
     public void convert() throws IOException {
         String line = null;
-        
+
         while ((line = reader.readLine()) != null) {
             if (CHAPTER_OR_SECTION.matcher(line).matches()) {
                 writeChapterOrSection(line);
-            } else if ("{code}".equals(line.trim())) {
+            } else if (line.trim().startsWith("!") && line.trim().endsWith("!"))
{
+                writeImage(line);
+            } else if (line.trim().startsWith("||") && line.trim().endsWith("||"))
{
+                writeTableHeader(line);
+            } else if (line.trim().startsWith("|") && line.trim().endsWith("|"))
{
+                writeTableBody(line);
+            } else if (line.startsWith("*")) {
+                writeBulletList(line);
+            } else if (line.startsWith("#")) {
+                writeNumberedList(line);
+            } else if (line.startsWith("-")) {
+                writeGlossaryList(line);
+            } else if (line.trim().startsWith("{code")) {
                 writeProgramListing();
             } else {
                 writePara(line);
             }
         }
-        
+
         // let's close everying that was opened
         closeElements();
 
     }
 
+    private void writeGlossaryList(String line) {
+        ensureElementOpen("glosslist");
+
+        String[] keyvalue = line.substring(1).trim().split("::");
+        openElement("glossentry");
+        writeElement("glossterm", filter(keyvalue[0].trim()));
+        openElement("glossdef");
+        writeElement("para", filter(keyvalue[1].trim()));
+        closeElement("glossentry");
+    }
+
+    private void writeTableBody(String line) {
+        ensureElementOpen("tbody");
+
+        writeTableRow(line.substring(1, line.length() - 1).split("\\|"));
+    }
+
+    private void writeTableHeader(String line) {
+        ensureElementOpen("informaltable");
+        ensureElementOpen("thead");
+
+        writeTableRow(line.substring(2, line.length() - 2).split("\\|\\|"));
+
+        closeElement("thead");
+    }
+
+    private void writeTableRow(String[] cells) {
+        openElement("tr");
+        for (String cell : cells) {
+            writeElement("td", filter(cell.trim()));
+        }
+        closeElement("tr");
+    }
+
+    private void writeNumberedList(String line) {
+        ensureElementOpen("orderedlist");
+        writeListItem(line);
+    }
+
+    private void ensureElementOpen(String element) {
+        if (!isCurrentElement(element)) {
+            openElement(element);
+        }
+    }
+
+    private void writeBulletList(String line) {
+        ensureElementOpen("itemizedlist");
+        writeListItem(line);
+    }
+
+    private void writeListItem(String line) {
+        String data = line.substring(1).trim();
+        openElement("listitem");
+        writeElement("para", filter(data));
+        closeElement("listitem");
+    }
+
+    private void writeImage(String line) {
+        String file = line.trim().replaceAll("!", "");
+        openElement("imageobject");
+        writeText(String.format("<imagedate fileref=\"%s\"/>", file));
+        closeElement("imageobject");
+    }
+
     private void writeProgramListing() throws IOException {
         writeText("<programlisting><![CDATA[");
 
@@ -84,6 +160,10 @@ public class ConfluenceConverter {
     }
 
     private void writePara(String line) {
+        // a <para/> shouldn't
+        ensureClosed("informaltable");
+
+
         if (line.trim().length() == 0) {
             if (elements.contains("para")) {
                 closeElement("para");
@@ -96,8 +176,14 @@ public class ConfluenceConverter {
         }
     }
 
+    private void ensureClosed(String element) {
+        if (elements.contains(element)) {
+            closeElement(element);
+        }
+    }
+
     private String filter(String line) {
-        return line.replaceAll("[\\{]{2}", "<code>").replaceAll("[\\}]{2}", "</code>");
+        return line.replaceAll("[\\{]{2}", "<code>").replaceAll("[\\}]{2}", "</code>").replaceAll("&",
"&amp;");
     }
 
     private void writeText(String text) {
@@ -105,7 +191,9 @@ public class ConfluenceConverter {
     }
 
     private void writeText(String text, String indent) {
-        writer.printf("%s%s%n", indent, text);
+        writer.printf("%s%s%n", indent, filter(text));
+
+
     }
 
     private void writeChapterOrSection(String line) {
@@ -119,7 +207,7 @@ public class ConfluenceConverter {
         } else {
             openElement("section");
         }
-        writeElement("title", line.substring(3).trim());
+        writeElement("title", filter(line.substring(3).trim()));
         currentLevel = level;
     }
 
@@ -139,11 +227,13 @@ public class ConfluenceConverter {
     }
 
     private void closeElement(String element) {
-        String next = elements.pop();
-        writer.printf("%s</%s>%n", indent(), next);
-        if (!element.equals(next)) {
-            // recursive call to close everything down to the required element
-            closeElement(element);
+        if (!elements.isEmpty()) {
+            String next = elements.pop();
+            writer.printf("%s</%s>%n", indent(), next);
+            if (!element.equals(next)) {
+                // recursive call to close everything down to the required element
+                closeElement(element);
+            }
         }
     }
 
@@ -154,4 +244,8 @@ public class ConfluenceConverter {
         }
         return buffer.toString();
     }
+
+    private boolean isCurrentElement(String element) {
+        return elements.peek().equals(element);
+    }
 }

Modified: servicemix/maven-plugins/docs-maven-plugin/trunk/src/test/java/org/apache/servicemix/docs/confluence/ConfluenceDocumentTest.java
URL: http://svn.apache.org/viewvc/servicemix/maven-plugins/docs-maven-plugin/trunk/src/test/java/org/apache/servicemix/docs/confluence/ConfluenceDocumentTest.java?rev=948010&r1=948009&r2=948010&view=diff
==============================================================================
--- servicemix/maven-plugins/docs-maven-plugin/trunk/src/test/java/org/apache/servicemix/docs/confluence/ConfluenceDocumentTest.java
(original)
+++ servicemix/maven-plugins/docs-maven-plugin/trunk/src/test/java/org/apache/servicemix/docs/confluence/ConfluenceDocumentTest.java
Tue May 25 11:53:22 2010
@@ -20,6 +20,8 @@ import java.io.InputStreamReader;
 import java.io.StringWriter;
 import java.util.List;
 
+import javax.xml.stream.XMLStreamException;
+
 import org.apache.commons.io.IOUtils;
 import org.junit.Test;
 
@@ -45,7 +47,22 @@ public class ConfluenceDocumentTest {
         assertDocBook("code-blocks");
     }
 
-    private void assertDocBook(String name) throws IOException {
+    @org.junit.Test
+    public void generateImageObject() throws Exception {
+        assertDocBook("images");
+    }
+
+    @org.junit.Test
+    public void generateLists() throws Exception {
+        assertDocBook("lists");
+    }
+
+    @org.junit.Test
+    public void generateTables() throws Exception {
+        assertDocBook("tables");
+    }
+
+    private void assertDocBook(String name) throws IOException, XMLStreamException {
         StringWriter writer = new StringWriter();
 
         List<String> expected = IOUtils.readLines(getClass().getResourceAsStream(name
+ ".xml"));

Modified: servicemix/maven-plugins/docs-maven-plugin/trunk/src/test/resources/org/apache/servicemix/docs/confluence/code-blocks.wiki
URL: http://svn.apache.org/viewvc/servicemix/maven-plugins/docs-maven-plugin/trunk/src/test/resources/org/apache/servicemix/docs/confluence/code-blocks.wiki?rev=948010&r1=948009&r2=948010&view=diff
==============================================================================
--- servicemix/maven-plugins/docs-maven-plugin/trunk/src/test/resources/org/apache/servicemix/docs/confluence/code-blocks.wiki
(original)
+++ servicemix/maven-plugins/docs-maven-plugin/trunk/src/test/resources/org/apache/servicemix/docs/confluence/code-blocks.wiki
Tue May 25 11:53:22 2010
@@ -8,4 +8,16 @@ This section contains a piece of {{code 
 <hello>
   <world/>
 </hello>
-{code}
\ No newline at end of file
+{code}
+
+h2. Section 2
+The next one specifies the language for the code block.
+
+{code:lang=xml}
+<?xml version="1.0"?>
+<hello>
+  <world/>
+</hello>
+{code}
+
+h2. Section with {{code text}}
\ No newline at end of file

Modified: servicemix/maven-plugins/docs-maven-plugin/trunk/src/test/resources/org/apache/servicemix/docs/confluence/code-blocks.xml
URL: http://svn.apache.org/viewvc/servicemix/maven-plugins/docs-maven-plugin/trunk/src/test/resources/org/apache/servicemix/docs/confluence/code-blocks.xml?rev=948010&r1=948009&r2=948010&view=diff
==============================================================================
--- servicemix/maven-plugins/docs-maven-plugin/trunk/src/test/resources/org/apache/servicemix/docs/confluence/code-blocks.xml
(original)
+++ servicemix/maven-plugins/docs-maven-plugin/trunk/src/test/resources/org/apache/servicemix/docs/confluence/code-blocks.xml
Tue May 25 11:53:22 2010
@@ -12,4 +12,19 @@
     </hello>
     ]]></programlisting>
   </section>
+  <section>
+    <title>Section 2</title>
+    <para>
+      The next one specifies the language for the code block.
+    </para>
+    <programlisting><![CDATA[
+    <?xml version="1.0"?>
+    <hello>
+      <world/>
+    </hello>
+    ]]></programlisting>
+  </section>
+  <section>
+    <title>Section with <code>code text</code></title>
+  </section>
 </chapter>
\ No newline at end of file

Copied: servicemix/maven-plugins/docs-maven-plugin/trunk/src/test/resources/org/apache/servicemix/docs/confluence/images.wiki
(from r940388, servicemix/maven-plugins/docs-maven-plugin/trunk/src/test/resources/org/apache/servicemix/docs/confluence/code-blocks.wiki)
URL: http://svn.apache.org/viewvc/servicemix/maven-plugins/docs-maven-plugin/trunk/src/test/resources/org/apache/servicemix/docs/confluence/images.wiki?p2=servicemix/maven-plugins/docs-maven-plugin/trunk/src/test/resources/org/apache/servicemix/docs/confluence/images.wiki&p1=servicemix/maven-plugins/docs-maven-plugin/trunk/src/test/resources/org/apache/servicemix/docs/confluence/code-blocks.wiki&r1=940388&r2=948010&rev=948010&view=diff
==============================================================================
--- servicemix/maven-plugins/docs-maven-plugin/trunk/src/test/resources/org/apache/servicemix/docs/confluence/code-blocks.wiki
(original)
+++ servicemix/maven-plugins/docs-maven-plugin/trunk/src/test/resources/org/apache/servicemix/docs/confluence/images.wiki
Tue May 25 11:53:22 2010
@@ -1,11 +1,6 @@
 h1. Chapter
 
 h2. Section 1
-This section contains a piece of {{code text}}.
+This section contains an image
 
-{code}
-<?xml version="1.0"?>
-<hello>
-  <world/>
-</hello>
-{code}
\ No newline at end of file
+!image.png!
\ No newline at end of file

Copied: servicemix/maven-plugins/docs-maven-plugin/trunk/src/test/resources/org/apache/servicemix/docs/confluence/images.xml
(from r940388, servicemix/maven-plugins/docs-maven-plugin/trunk/src/test/resources/org/apache/servicemix/docs/confluence/document2.xml)
URL: http://svn.apache.org/viewvc/servicemix/maven-plugins/docs-maven-plugin/trunk/src/test/resources/org/apache/servicemix/docs/confluence/images.xml?p2=servicemix/maven-plugins/docs-maven-plugin/trunk/src/test/resources/org/apache/servicemix/docs/confluence/images.xml&p1=servicemix/maven-plugins/docs-maven-plugin/trunk/src/test/resources/org/apache/servicemix/docs/confluence/document2.xml&r1=940388&r2=948010&rev=948010&view=diff
==============================================================================
--- servicemix/maven-plugins/docs-maven-plugin/trunk/src/test/resources/org/apache/servicemix/docs/confluence/document2.xml
(original)
+++ servicemix/maven-plugins/docs-maven-plugin/trunk/src/test/resources/org/apache/servicemix/docs/confluence/images.xml
Tue May 25 11:53:22 2010
@@ -3,16 +3,10 @@
   <section>
     <title>Section 1</title>
     <para>
-      Paragraph 1 starts here...
+      This section contains an image
     </para>
-    <para>
-      Paragraph 2 starts here...
-    </para>
-    <section>
-      <title>Section 1.1</title>
-      <para>
-        And one more paragraph
-      </para>
-    </section>
+    <imageobject>
+      <imagedate fileref="image.png"/>
+    </imageobject>
   </section>
 </chapter>
\ No newline at end of file

Added: servicemix/maven-plugins/docs-maven-plugin/trunk/src/test/resources/org/apache/servicemix/docs/confluence/lists.wiki
URL: http://svn.apache.org/viewvc/servicemix/maven-plugins/docs-maven-plugin/trunk/src/test/resources/org/apache/servicemix/docs/confluence/lists.wiki?rev=948010&view=auto
==============================================================================
--- servicemix/maven-plugins/docs-maven-plugin/trunk/src/test/resources/org/apache/servicemix/docs/confluence/lists.wiki
(added)
+++ servicemix/maven-plugins/docs-maven-plugin/trunk/src/test/resources/org/apache/servicemix/docs/confluence/lists.wiki
Tue May 25 11:53:22 2010
@@ -0,0 +1,20 @@
+h1. Chapter
+
+h2. Section 1
+This section contains a bulleted list:
+* item 1
+* {{item 2}}
+* item 3
+
+h2. Section 2
+This section contains a numbered list:
+# item 1
+# {{item 2}}
+# item 3
+
+h2. Definition list
+This section contains a definition list:
+- term1 :: Definition for term1
+- {{term2}} :: Definition for term2 (including {{code text}})
+- term3 :: Definition for term3
+

Added: servicemix/maven-plugins/docs-maven-plugin/trunk/src/test/resources/org/apache/servicemix/docs/confluence/lists.xml
URL: http://svn.apache.org/viewvc/servicemix/maven-plugins/docs-maven-plugin/trunk/src/test/resources/org/apache/servicemix/docs/confluence/lists.xml?rev=948010&view=auto
==============================================================================
--- servicemix/maven-plugins/docs-maven-plugin/trunk/src/test/resources/org/apache/servicemix/docs/confluence/lists.xml
(added)
+++ servicemix/maven-plugins/docs-maven-plugin/trunk/src/test/resources/org/apache/servicemix/docs/confluence/lists.xml
Tue May 25 11:53:22 2010
@@ -0,0 +1,63 @@
+<chapter>
+  <title>Chapter</title>
+  <section>
+    <title>Section 1</title>
+    <para>
+      This section contains a bulleted list:
+      <itemizedlist>
+        <listitem>
+          <para>item 1</para>
+        </listitem>
+        <listitem>
+          <para><code>item 2</code></para>
+        </listitem>
+        <listitem>
+          <para>item 3</para>
+        </listitem>
+      </itemizedlist>
+    </para>
+  </section>
+  <section>
+    <title>Section 2</title>
+    <para>
+      This section contains a numbered list:
+      <orderedlist>
+        <listitem>
+          <para>item 1</para>
+        </listitem>
+        <listitem>
+          <para><code>item 2</code></para>
+        </listitem>
+        <listitem>
+          <para>item 3</para>
+        </listitem>
+      </orderedlist>
+    </para>
+  </section>
+  <section>
+    <title>Definition list</title>
+    <para>
+      This section contains a definition list:
+      <glosslist>
+        <glossentry>
+          <glossterm>term1</glossterm>
+          <glossdef>
+            <para>Definition for term1</para>
+          </glossdef>
+        </glossentry>
+        <glossentry>
+          <glossterm><code>term2</code></glossterm>
+          <glossdef>
+            <para>Definition for term2 (including <code>code text</code>)</para>
+          </glossdef>
+        </glossentry>
+        <glossentry>
+          <glossterm>term3</glossterm>
+          <glossdef>
+            <para>Definition for term3</para>
+          </glossdef>
+        </glossentry>
+      </glosslist>
+    </para>
+  </section>
+</chapter>
\ No newline at end of file

Added: servicemix/maven-plugins/docs-maven-plugin/trunk/src/test/resources/org/apache/servicemix/docs/confluence/tables.wiki
URL: http://svn.apache.org/viewvc/servicemix/maven-plugins/docs-maven-plugin/trunk/src/test/resources/org/apache/servicemix/docs/confluence/tables.wiki?rev=948010&view=auto
==============================================================================
--- servicemix/maven-plugins/docs-maven-plugin/trunk/src/test/resources/org/apache/servicemix/docs/confluence/tables.wiki
(added)
+++ servicemix/maven-plugins/docs-maven-plugin/trunk/src/test/resources/org/apache/servicemix/docs/confluence/tables.wiki
Tue May 25 11:53:22 2010
@@ -0,0 +1,7 @@
+h1. Chapter
+
+h2. An informal table
+This section contains an informal table:
+|| Header 1 || Header 2 || Header 3 ||
+| Val 1.1 | Val 1.2 | {{Val 1.3}} |
+| Val 2.1 | Val 2.2 | {{Val 2.3}} |

Added: servicemix/maven-plugins/docs-maven-plugin/trunk/src/test/resources/org/apache/servicemix/docs/confluence/tables.xml
URL: http://svn.apache.org/viewvc/servicemix/maven-plugins/docs-maven-plugin/trunk/src/test/resources/org/apache/servicemix/docs/confluence/tables.xml?rev=948010&view=auto
==============================================================================
--- servicemix/maven-plugins/docs-maven-plugin/trunk/src/test/resources/org/apache/servicemix/docs/confluence/tables.xml
(added)
+++ servicemix/maven-plugins/docs-maven-plugin/trunk/src/test/resources/org/apache/servicemix/docs/confluence/tables.xml
Tue May 25 11:53:22 2010
@@ -0,0 +1,30 @@
+<chapter>
+  <title>Chapter</title>
+  <section>
+    <title>An informal table</title>
+    <para>
+      This section contains an informal table:
+      <informaltable>
+        <thead>
+          <tr>
+            <td>Header 1</td>
+            <td>Header 2</td>
+            <td>Header 3</td>
+          </tr>
+        </thead>
+        <tbody>
+          <tr>
+            <td>Val 1.1</td>
+            <td>Val 1.2</td>
+            <td><code>Val 1.3</code></td>
+          </tr>
+          <tr>
+            <td>Val 2.1</td>
+            <td>Val 2.2</td>
+            <td><code>Val 2.3</code></td>
+          </tr>
+        </tbody>
+      </informaltable>
+    </para>
+  </section>
+</chapter>
\ No newline at end of file



Mime
View raw message