Created
October 1, 2011 10:45
-
-
Save vmassol/1255867 to your computer and use it in GitHub Desktop.
Docbook parsing with XWiki Rendering using the Doxia bridge
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Index: xwiki-rendering/xwiki-rendering-syntaxes/xwiki-rendering-syntax-doxia/pom.xml | |
=================================================================== | |
--- xwiki-rendering/xwiki-rendering-syntaxes/xwiki-rendering-syntax-doxia/pom.xml (revision 5c84b2cc2f38e6f22c74a4e2133dae1a43bc7ff0) | |
+++ xwiki-rendering/xwiki-rendering-syntaxes/xwiki-rendering-syntax-doxia/pom.xml (revision ) | |
@@ -45,6 +45,24 @@ | |
</exclusion> | |
</exclusions> | |
</dependency> | |
+ <dependency> | |
+ <groupId>org.apache.maven.doxia</groupId> | |
+ <artifactId>doxia-module-docbook-simple</artifactId> | |
+ <version>1.2</version> | |
+ <exclusions> | |
+ <!-- Plexus draws JUnit that we don't need/want to have at runtime --> | |
+ <exclusion> | |
+ <groupId>junit</groupId> | |
+ <artifactId>junit</artifactId> | |
+ </exclusion> | |
+ </exclusions> | |
+ </dependency> | |
+ <dependency> | |
+ <groupId>org.xwiki.rendering</groupId> | |
+ <artifactId>xwiki-rendering-syntax-xwiki2</artifactId> | |
+ <version>${project.version}</version> | |
+ <scope>test</scope> | |
+ </dependency> | |
</dependencies> | |
<build> | |
<plugins> | |
Index: xwiki-rendering/xwiki-rendering-syntaxes/xwiki-rendering-syntax-doxia/src/main/resources/META-INF/components.txt | |
=================================================================== | |
--- xwiki-rendering/xwiki-rendering-syntaxes/xwiki-rendering-syntax-doxia/src/main/resources/META-INF/components.txt (revision 5c84b2cc2f38e6f22c74a4e2133dae1a43bc7ff0) | |
+++ xwiki-rendering/xwiki-rendering-syntaxes/xwiki-rendering-syntax-doxia/src/main/resources/META-INF/components.txt (revision ) | |
@@ -1,1 +1,2 @@ | |
-org.xwiki.rendering.internal.parser.DoxiaTWikiParser | |
\ No newline at end of file | |
+org.xwiki.rendering.internal.parser.DoxiaTWikiParser | |
+org.xwiki.rendering.internal.parser.DoxiaDocbookParser | |
\ No newline at end of file | |
Index: xwiki-rendering/xwiki-rendering-syntaxes/xwiki-rendering-syntax-doxia/src/main/java/org/xwiki/rendering/internal/parser/DoxiaDocbookParser.java | |
=================================================================== | |
--- xwiki-rendering/xwiki-rendering-syntaxes/xwiki-rendering-syntax-doxia/src/main/java/org/xwiki/rendering/internal/parser/DoxiaDocbookParser.java (revision ) | |
+++ xwiki-rendering/xwiki-rendering-syntaxes/xwiki-rendering-syntax-doxia/src/main/java/org/xwiki/rendering/internal/parser/DoxiaDocbookParser.java (revision ) | |
@@ -0,0 +1,53 @@ | |
+/* | |
+ * See the NOTICE file distributed with this work for additional | |
+ * information regarding copyright ownership. | |
+ * | |
+ * This is free software; you can redistribute it and/or modify it | |
+ * under the terms of the GNU Lesser General Public License as | |
+ * published by the Free Software Foundation; either version 2.1 of | |
+ * the License, or (at your option) any later version. | |
+ * | |
+ * This software is distributed in the hope that it will be useful, | |
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
+ * Lesser General Public License for more details. | |
+ * | |
+ * You should have received a copy of the GNU Lesser General Public | |
+ * License along with this software; if not, write to the Free | |
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA | |
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org. | |
+ */ | |
+package org.xwiki.rendering.internal.parser; | |
+ | |
+import javax.inject.Named; | |
+import javax.inject.Singleton; | |
+ | |
+import org.apache.maven.doxia.module.docbook.DocBookParser; | |
+import org.xwiki.component.annotation.Component; | |
+import org.xwiki.rendering.internal.parser.doxia.AbstractDoxiaParser; | |
+import org.xwiki.rendering.syntax.Syntax; | |
+import org.xwiki.rendering.syntax.SyntaxType; | |
+ | |
+/** | |
+ * @version $Id$ | |
+ * @since 3.2RC1 | |
+ */ | |
+@Component | |
+@Named("docbook/1.0") | |
+@Singleton | |
+public class DoxiaDocbookParser extends AbstractDoxiaParser | |
+{ | |
+ private static final Syntax SYNTAX = new Syntax(new SyntaxType("docbook", "DocBook"), "1.0"); | |
+ | |
+ @Override | |
+ public Syntax getSyntax() | |
+ { | |
+ return SYNTAX; | |
+ } | |
+ | |
+ @Override | |
+ public org.apache.maven.doxia.parser.Parser createDoxiaParser() | |
+ { | |
+ return new DocBookParser(); | |
+ } | |
+} | |
Index: xwiki-rendering/xwiki-rendering-syntaxes/xwiki-rendering-syntax-doxia/src/test/java/org/xwiki/rendering/internal/parser/doxia/DoxiaDocbookParserTest.java | |
=================================================================== | |
--- xwiki-rendering/xwiki-rendering-syntaxes/xwiki-rendering-syntax-doxia/src/test/java/org/xwiki/rendering/internal/parser/doxia/DoxiaDocbookParserTest.java (revision ) | |
+++ xwiki-rendering/xwiki-rendering-syntaxes/xwiki-rendering-syntax-doxia/src/test/java/org/xwiki/rendering/internal/parser/doxia/DoxiaDocbookParserTest.java (revision ) | |
@@ -0,0 +1,105 @@ | |
+package org.xwiki.rendering.internal.parser.doxia; | |
+ | |
+import java.io.StringReader; | |
+ | |
+import org.junit.Assert; | |
+import org.junit.Test; | |
+import org.xwiki.rendering.block.XDOM; | |
+import org.xwiki.rendering.parser.Parser; | |
+import org.xwiki.rendering.renderer.BlockRenderer; | |
+import org.xwiki.rendering.renderer.printer.DefaultWikiPrinter; | |
+import org.xwiki.test.AbstractComponentTestCase; | |
+ | |
+public class DoxiaDocbookParserTest extends AbstractComponentTestCase | |
+{ | |
+ @Test | |
+ public void parseDocbookExample() throws Exception | |
+ { | |
+ String docbook = "<!DOCTYPE book\n" + | |
+ " PUBLIC \"-//OASIS//DTD DocBook XML V4.1.2//EN\"\n" + | |
+ " \"http://www.oasis-open.org/docbook/xml/4.1.2/docbookx.dtd\">\n" + | |
+ "<book>\n" + | |
+ "\n" + | |
+ " <bookinfo>\n" + | |
+ " <title>DocBook document example</title>\n" + | |
+ " <author>\n" + | |
+ " <firstname>Ovidiu</firstname>\n" + | |
+ " <surname>Predescu</surname>\n" + | |
+ " </author>\n" + | |
+ "\n" + | |
+ " <copyright>\n" + | |
+ " <year>2001</year>\n" + | |
+ " <holder>Ovidiu Predescu</holder>\n" + | |
+ " </copyright>\n" + | |
+ " </bookinfo>\n" + | |
+ "\n" + | |
+ " <preface>\n" + | |
+ " <title>Example document</title>\n" + | |
+ "\n" + | |
+ " <para>A simple DocBook example document.</para>\n" + | |
+ " </preface>\n" + | |
+ "\n" + | |
+ " <chapter>\n" + | |
+ " <title>DocBook and XSLT-process mode for GNU Emacs/XEmacs</title>\n" + | |
+ "\n" + | |
+ " <para>The <emphasis>XSLT-process</emphasis> mode, when used with the\n" + | |
+ " DocBook-XSL stylesheets makes GNU Emacs/XEmacs the ideal DocBook\n" + | |
+ " processor.</para>\n" + | |
+ "\n" + | |
+ " <para>To find out more on how to use the\n" + | |
+ " <emphasis>XSLT-process</emphasis> mode for DocBook processing, point\n" + | |
+ " your browser to <ulink\n" + | |
+ " url=\"http://xslt-process.sourceforge.net/docbook.php\">http://xslt-process.sourceforge.net/docbook.php</ulink>.</para>\n" + | |
+ "\n" + | |
+ " </chapter>\n" + | |
+ "\n" + | |
+ "</book>"; | |
+ | |
+ Parser parser = getComponentManager().lookup(Parser.class, "docbook/1.0"); | |
+ XDOM xdom = parser.parse(new StringReader(docbook)); | |
+ | |
+ BlockRenderer renderer = getComponentManager().lookup(BlockRenderer.class, "xwiki/2.0"); | |
+ DefaultWikiPrinter printer = new DefaultWikiPrinter(); | |
+ renderer.render(xdom, printer); | |
+ | |
+ String expected = "\n" + | |
+ "\n" + | |
+ " \n" + | |
+ " **DocBook document example**\n" + | |
+ " \n" + | |
+ " Ovidiu\n" + | |
+ " Predescu\n" + | |
+ " \n" + | |
+ "\n" + | |
+ " \n" + | |
+ " 2001\n" + | |
+ " Ovidiu Predescu\n" + | |
+ " \n" + | |
+ " \n" + | |
+ "\n" + | |
+ " \n" + | |
+ " **Example document**\n" + | |
+ "\n" + | |
+ " A simple DocBook example document.\n" + | |
+ " \n" + | |
+ "\n" + | |
+ " \n" + | |
+ " **DocBook and XSLT-process mode for GNU Emacs/XEmacs**\n" + | |
+ "\n" + | |
+ " \n" + | |
+ "\n" + | |
+ "The //XSLT-process// mode, when used with the\n" + | |
+ " DocBook-XSL stylesheets makes GNU Emacs/XEmacs the ideal DocBook\n" + | |
+ " processor.\n" + | |
+ "\n" + | |
+ " \n" + | |
+ "\n" + | |
+ "To find out more on how to use the\n" + | |
+ " //XSLT-process// mode for DocBook processing, point\n" + | |
+ " your browser to [[http:~~/~~/xslt-process.sourceforge.net/docbook.php>>http://xslt-process.sourceforge.net/docbook.php]].\n" + | |
+ "\n" + | |
+ " \n"; | |
+ | |
+ Assert.assertEquals(expected, printer.toString()); | |
+ } | |
+} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment