Jrst-commits
Threads by month
- ----- 2026 -----
- June
- May
- April
- March
- February
- January
- ----- 2025 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2024 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2023 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2022 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2021 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2020 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2019 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2018 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2017 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2016 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2015 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2014 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2013 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2012 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2011 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2010 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2009 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2008 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2007 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2006 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2005 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2004 -----
- December
- November
- October
- September
- August
May 2011
- 5 participants
- 18 discussions
r586 - in trunk/jrst/src/test: java/org/nuiton/jrst resources resources/FilesTest
by kcardineaud@users.nuiton.org 19 May '11
by kcardineaud@users.nuiton.org 19 May '11
19 May '11
Author: kcardineaud
Date: 2011-05-19 11:51:39 +0200 (Thu, 19 May 2011)
New Revision: 586
Url: http://nuiton.org/repositories/revision/jrst/586
Log:
Ajout d'une fonction permettant de comparer les resultats de l'execution de jrst et docutils
Added:
trunk/jrst/src/test/java/org/nuiton/jrst/JRSTCompareDocutils.java
trunk/jrst/src/test/resources/FilesTest/
trunk/jrst/src/test/resources/FilesTest/index.txt
trunk/jrst/src/test/resources/FilesTest/roles.txt
trunk/jrst/src/test/resources/FilesTest/rstTest.rst
Added: trunk/jrst/src/test/java/org/nuiton/jrst/JRSTCompareDocutils.java
===================================================================
--- trunk/jrst/src/test/java/org/nuiton/jrst/JRSTCompareDocutils.java (rev 0)
+++ trunk/jrst/src/test/java/org/nuiton/jrst/JRSTCompareDocutils.java 2011-05-19 09:51:39 UTC (rev 586)
@@ -0,0 +1,325 @@
+package org.nuiton.jrst;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.io.Reader;
+import java.io.StringReader;
+import java.io.StringWriter;
+import java.net.URL;
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Locale;
+
+import javax.xml.transform.TransformerException;
+
+import junit.framework.Assert;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.custommonkey.xmlunit.DetailedDiff;
+import org.custommonkey.xmlunit.Diff;
+import org.custommonkey.xmlunit.DifferenceListener;
+
+import org.custommonkey.xmlunit.IgnoreTextAndAttributeValuesDifferenceListener;
+import org.dom4j.Document;
+import org.dom4j.DocumentException;
+import org.dom4j.io.SAXReader;
+import org.dom4j.io.XMLWriter;
+import org.junit.Ignore;
+import org.junit.Test;
+import org.nuiton.i18n.I18n;
+import org.nuiton.i18n.init.ClassPathI18nInitializer;
+import org.nuiton.util.FileUtil;
+
+
+
+
+
+public class JRSTCompareDocutils {
+
+ /** to use log facility, just put in your code: log.info(\"...\"); */
+ private static Log log = LogFactory.getLog(JRSTCompareDocutils.class);
+
+ /** Commande utilisee pour transformer le rst en xml */
+ private static String rst2xml = "rst2xml";
+
+ /** Commande utilisee pour transformer le rst en html */
+ private static String rst2html = "rst2html";
+
+
+ public static void main(String[] args) throws Exception {
+
+ I18n.init(new ClassPathI18nInitializer(), Locale.UK);
+
+ JRSTCompareDocutils jT = new JRSTCompareDocutils();
+
+ File rep = null;
+ if (args.length > 0) {
+ rep = new File(args[0]);
+ jT.runCompare(rep);
+ }
+ else {
+ jT.runCompare(new File("src/test/resources/FilesTest/"));
+ }
+
+ }
+
+
+ /**
+ *
+ * @param rep
+ * @throws Exception
+ */
+ public void runCompare(File rep) throws Exception {
+
+ if(testIfDocutils()) {
+ //File rep = new File("src/test/resources/FilesTest/");
+
+ LinkedList<File> rstFilesTests = new LinkedList<File>();
+
+ //1. recuperation des fichiers de test directement dans le repertoire des fichiers rst
+ rstFilesTests.addAll(FileUtil.getFiles(rep));
+
+ //2. boucle sur les fichiers de test
+ Iterator<File> iteFiles = rstFilesTests.iterator();
+
+ File testFile;
+
+
+ String res="";
+
+ while(iteFiles.hasNext()) {
+ testFile = iteFiles.next();
+ log.debug("fichier test : "+testFile.getName());
+ res+="\nFichier test: "+testFile.getName();
+
+ //Compare XML
+ if (compareXML(getXMLJrst(testFile),getDocPython(testFile,rst2xml))) {
+ res+="\tXML->OK\n";
+ }
+ else {
+ res+="\n\tXML->KO\n";
+ }
+
+ //Compare HTML
+ if (compareHTML(testFile)) {
+ res+="\tHTML->OK\n";
+ }
+ else {
+ res+="\tHTML->KO\n";
+ }
+
+ //Compare RST
+ if (compareRST(testFile)) {
+ res+="\tRST->OK\n";
+ }
+ else {
+ res+="\tRST->KO\n";
+ }
+ log.debug("==========================================================");
+ }
+
+ log.info(res);
+ }
+ Assert.assertTrue(true);
+ }
+
+
+ /**
+ *
+ * @param compare
+ * @param base
+ * @return
+ * @throws Exception
+ */
+ private boolean compareXML(Document compare, Document base) throws Exception {
+
+ Document docRst = compare; // JRST
+
+ Document docPython = base; // docutils
+
+
+ XMLCaseTest test = new XMLCaseTest("testXML");
+ DetailedDiff myDiff = test.testAllDifferences(docPython.asXML(), docRst.asXML());
+ List<?> allDifferences = myDiff.getAllDifferences();
+
+
+ log.debug("Nombre de difference XML: "+allDifferences.size());
+
+
+
+ return myDiff.similar();
+
+ }
+
+
+ /**
+ *
+ * @param testFile
+ * @return
+ * @throws Exception
+ */
+ private boolean compareHTML(File testFile) throws Exception {
+
+ String htmlJRST = getHTMLJrst(testFile);
+
+ Document htmlPython = getDocPython(testFile,rst2html);
+
+ String BadlyFormedJRST2HTML = htmlJRST;
+
+ String BadlyFormedPython2HTML = toWriter(htmlPython).toString();
+
+ DifferenceListener myDifferenceListener = new IgnoreTextAndAttributeValuesDifferenceListener();
+
+ Diff myDiff = new Diff(BadlyFormedJRST2HTML, BadlyFormedPython2HTML);
+
+ myDiff.overrideDifferenceListener(myDifferenceListener);
+
+ return myDiff.similar();
+ }
+
+
+ /**
+ *
+ * @param testFile
+ * @return
+ * @throws Exception
+ */
+ private boolean compareRST(File testFile) throws Exception {
+
+ //recuperation du XML cree depuis le RST avec JRST
+ Document rst2xml = getXMLJrst(testFile);
+
+ //recuperation du rst genere depuis le xml
+ String rst2rst = getRSTJrst(testFile);
+
+ JRSTReader jrst = new JRSTReader();
+
+ Document rst2rst2xml = jrst.read(new StringReader(rst2rst)); // JRST
+
+ return compareXML(rst2xml, rst2rst2xml);
+ //return true;
+
+ }
+
+
+ /**
+ * Permet de recuperer le fichier XML genere par JRST
+ * @param source
+ * @return Document le xml genere
+ * @throws Exception
+ */
+ private Document getXMLJrst(File source) throws Exception {
+ URL url = source.toURI().toURL();
+ Reader in = new InputStreamReader(url.openStream());
+
+ JRSTReader jrst = new JRSTReader();
+
+ return jrst.read(in); // JRST
+
+ }
+
+ /**
+ *
+ * @param source
+ * @return
+ * @throws Exception
+ */
+ private String getHTMLJrst(File source) throws Exception {
+
+ URL url = source.toURI().toURL();
+ Reader reader = new InputStreamReader(url.openStream(), JRST.UTF_8);
+
+
+ return JRST.generate(JRST.TYPE_HTML,reader);
+ }
+
+ /**
+ *
+ * @param source
+ * @return
+ * @throws Exception
+ */
+ private String getRSTJrst(File source) throws Exception {
+
+ URL url = source.toURI().toURL();
+ Reader reader = new InputStreamReader(url.openStream(), JRST.UTF_8);
+
+ return JRST.generate(JRST.TYPE_RST,reader);
+ }
+
+
+ /**
+ * Permet de recuperer le fichier genere par docutils en specifiant son type
+ * @param source
+ * @return Document le xml genere
+ * @throws IOException
+ * @throws TransformerException
+ * @throws Exception
+ */
+ private Document getDocPython(File source, String action) throws DocumentException, InterruptedException, TransformerException, IOException {
+
+ ProcessBuilder processBuilder = new ProcessBuilder(action, source.getPath());
+ processBuilder.redirectErrorStream(true);
+ Process p = processBuilder.start();
+
+ ThreadRedirection t = new ThreadRedirection(p);
+ t.start();
+ p.waitFor();
+ t.join();
+ //On attend que le processus ce termine
+ //t.stop();
+ p.destroy();
+
+
+ SAXReader sr = new SAXReader(false);
+
+ return sr.read(new StringReader(t.getOutput()));
+
+ }
+
+
+ private static boolean testIfDocutils() {
+
+ File file = new File("src/test/resources/docutilsFilesTest/rstTest.rst");
+
+ ProcessBuilder processBuilder = new ProcessBuilder(rst2xml, file.getPath());
+ processBuilder.redirectErrorStream(true);
+ @SuppressWarnings("unused")
+ Process p =null;
+
+ try {
+ p = processBuilder.start();
+ }
+ catch(IOException ioe) {
+ rst2xml="rst2xml.py";
+ rst2html="rst2html.py";
+ processBuilder = new ProcessBuilder(rst2xml, file.getPath());
+ try {
+ p = processBuilder.start();
+ } catch (IOException e) {
+ log.warn("You must install python-docutils to compare rst files");
+ return false;
+ }
+ }
+ p.destroy();
+ return true;
+
+ }
+
+
+
+ private static StringWriter toWriter(org.dom4j.Document dom4jdoc) throws TransformerException, IOException {
+
+ StringWriter writer = new StringWriter();
+ XMLWriter xmlWriter = new XMLWriter(writer);
+
+ xmlWriter.write(dom4jdoc);
+ return writer;
+ }
+
+
+
+}
Added: trunk/jrst/src/test/resources/FilesTest/index.txt
===================================================================
--- trunk/jrst/src/test/resources/FilesTest/index.txt (rev 0)
+++ trunk/jrst/src/test/resources/FilesTest/index.txt 2011-05-19 09:51:39 UTC (rev 586)
@@ -0,0 +1,238 @@
+==========================================
+ Docutils_ Project Documentation Overview
+==========================================
+
+:Author: David Goodger
+:Contact: goodger(a)python.org
+:Date: $Date: 2008-12-26 17:36:46 -0500 (Fri, 26 Dec 2008) $
+:Revision: $Revision: 5834 $
+:Copyright: This document has been placed in the public domain.
+
+The latest working documents may be accessed individually below, or
+from the ``docs`` directory of the `Docutils distribution`_.
+
+.. _Docutils: http://docutils.sourceforge.net/
+.. _Docutils distribution: http://docutils.sourceforge.net/#download
+
+.. contents::
+
+
+Docutils Stakeholders
+=====================
+
+Docutils stakeholders can be categorized in several groups:
+
+1. End-users: users of reStructuredText and the Docutils tools.
+ Although some are developers (e.g. Python developers utilizing
+ reStructuredText for docstrings in their source), many are not.
+
+2. Client-developers: developers using Docutils as a library,
+ programmers developing *with* Docutils.
+
+3. Component-developers: those who implement application-specific
+ components, directives, and/or roles, separately from Docutils.
+
+4. Core-developers: developers of the Docutils codebase and
+ participants in the Docutils project community.
+
+5. Re-implementers: developers of alternate implementations of
+ Docutils.
+
+There's a lot of overlap between these groups. Most (perhaps all)
+core-developers, component-developers, client-developers, and
+re-implementers are also end-users. Core-developers are also
+client-developers, and may also be component-developers in other
+projects. Component-developers are also client-developers.
+
+
+Project Fundamentals
+====================
+
+These files are for all Docutils stakeholders. They are kept at the
+top level of the Docutils project directory.
+
+:README.txt_: Project overview: quick-start, requirements,
+ installation, and usage.
+:COPYING.txt_: Conditions for Docutils redistribution, with links to
+ licenses.
+:FAQ.txt_: Docutils Frequently Asked Questions. If you have a
+ question or issue, there's a good chance it's already
+ answered here.
+:BUGS.txt_: A list of known bugs, and how to report a bug.
+:RELEASE-NOTES.txt_: Summary of the major changes in recent releases.
+:HISTORY.txt_: Detailed change history log.
+:THANKS.txt_: Acknowledgements.
+
+.. _README.txt: ../README.html
+.. _BUGS.txt: ../BUGS.html
+.. _COPYING.txt: ../COPYING.html
+.. _Docutils FAQ:
+.. _FAQ.txt: ../FAQ.html
+.. _RELEASE-NOTES.txt: ../RELEASE-NOTES.html
+.. _HISTORY.txt: ../HISTORY.html
+.. _THANKS.txt: ../THANKS.html
+
+
+.. _user:
+
+``user/``: Introductory & Tutorial Material for End-Users
+=========================================================
+
+Docutils-general:
+
+* `Docutils Front-End Tools <user/tools.html>`__
+* `Docutils Configuration <user/config.html>`__
+* `Docutils Mailing Lists <user/mailing-lists.html>`__
+* `Docutils Link List <user/links.html>`__
+
+Writer-specific:
+
+* `Easy Slide Shows With reStructuredText & S5 <user/slide-shows.html>`__
+* `Docutils LaTeX Writer <user/latex.html>`__
+* `Docutils ODF/OpenOffice/odt Writer <user/odt.html>`__
+
+`reStructuredText <http://docutils.sourceforge.net/rst.html>`_:
+
+* `A ReStructuredText Primer (HTML) <user/rst/quickstart.html>`__ (or
+ `text source <user/rst/quickstart.txt>`__)
+* `Quick reStructuredText <user/rst/quickref.html>`__ (user reference)
+* `reStructuredText Cheat Sheet <user/rst/cheatsheet.txt>`__ (text
+ only; 1 page for syntax, 1 page directive & role reference)
+* `reStructuredText Demonstration <user/rst/demo.html>`_ (a
+ demonstration of most reStructuredText features; you can also have a
+ look at the `text source <user/rst/demo.txt>`__)
+
+Editor support:
+
+* `Emacs support for reStructuredText <user/emacs.html>`_
+
+
+.. _ref:
+
+``ref/``: Reference Material for All Groups
+===========================================
+
+Many of these files began as developer specifications, but now that
+they're mature and used by end-users and client-developers, they have
+become reference material. Successful specs evolve into refs.
+
+Docutils-general:
+
+* `The Docutils Document Tree <ref/doctree.html>`__ (incomplete)
+* `Docutils Transforms <ref/transforms.html>`__
+* `Docutils Generic DTD <ref/docutils.dtd>`__
+* `OASIS XML Exchange Table Model Declaration Module
+ <ref/soextblx.dtd>`__ (CALS tables DTD module)
+
+Although not in the "ref" directory, `PEP 258`_ is a must-read
+reference for any Docutils developer.
+
+reStructuredText_:
+
+* `An Introduction to reStructuredText <ref/rst/introduction.html>`__
+ (includes the `Goals <ref/rst/introduction.html#goals>`__ and
+ `History <ref/rst/introduction.html#history>`__ of reStructuredText)
+* `reStructuredText Markup Specification <ref/rst/restructuredtext.html>`__
+* `reStructuredText Directives <ref/rst/directives.html>`__
+* `reStructuredText Interpreted Text Roles <ref/rst/roles.html>`__
+* `reStructuredText Standard Definition Files
+ <ref/rst/definitions.html>`_
+
+Prehistoric:
+
+* `Setext Documents Mirror
+ <http://docutils.sourceforge.net/mirror/setext.html>`__
+
+
+.. _peps:
+
+``peps/``: Python Enhancement Proposals
+=======================================
+
+* `PEP 256: Docstring Processing System Framework`__ is a high-level
+ generic proposal. [`PEP 256`__ in the `master repository`_]
+* `PEP 257: Docstring Conventions`__ addresses docstring style and
+ touches on content. [`PEP 257`__ in the `master repository`_]
+* `PEP 258: Docutils Design Specification`__ is an overview of the
+ architecture of Docutils. It documents design issues and
+ implementation details. [`PEP 258`__ in the `master repository`_]
+* `PEP 287: reStructuredText Docstring Format`__ proposes a standard
+ markup syntax. [`PEP 287`__ in the `master repository`_]
+
+Please note that PEPs in the `master repository`_ may not be current,
+whereas the local versions are.
+
+__ peps/pep-0256.html
+__ http://www.python.org/peps/pep-0256.html
+__ peps/pep-0257.html
+__ http://www.python.org/peps/pep-0257.html
+.. _PEP 258:
+__ peps/pep-0258.html
+__ http://www.python.org/peps/pep-0258.html
+__ peps/pep-0287.html
+__ http://www.python.org/peps/pep-0287.html
+.. _master repository: http://www.python.org/peps/
+
+
+.. _api:
+
+``api/``: API Reference Material for Client-Developers
+======================================================
+
+* `The Docutils Publisher <api/publisher.html>`__
+* `Inside A Docutils Command-Line Front-End Tool <api/cmdline-tool.html>`__
+* `Docutils Runtime Settings <api/runtime-settings.html>`__
+* (`Docutils Transforms <ref/transforms.html>`__ should be moved here)
+
+`PEP 258`_ is an overview of the architecture of Docutils.
+
+
+.. _howto:
+
+``howto/``: Instructions for Developers
+=======================================
+
+* **Security:** `Deploying Docutils Securely <howto/security.html>`__
+* `Writing HTML (CSS) Stylesheets for Docutils
+ <howto/html-stylesheets.html>`__
+* `Docutils Internationalization <howto/i18n.html>`__
+* `Creating reStructuredText Directives <howto/rst-directives.html>`__
+* `Creating reStructuredText Interpreted Text Roles
+ <howto/rst-roles.html>`__
+
+
+.. _dev:
+
+``dev/``: Development Notes and Plans for Core-Developers
+=========================================================
+
+Docutils-general:
+
+* `Docutils Hacker's Guide <dev/hacking.html>`__
+* `Docutils Distributor's Guide <dev/distributing.html>`__
+* `Docutils To Do List <dev/todo.html>`__
+* `Docutils Project Policies <dev/policies.html>`__
+* `Docutils Web Site <dev/website.html>`__
+* `Docutils Release Procedure <dev/release.html>`__
+* `The Docutils Subversion Repository <dev/repository.html>`__
+* `Docutils Testing <dev/testing.html>`__
+* `Docstring Semantics <dev/semantics.html>`__ (incomplete)
+* `Python Source Reader <dev/pysource.html>`_ (incomplete)
+* `Docutils Python DTD <dev/pysource.dtd>`_ (experimental)
+* `Plan for Enthought API Documentation Tool <dev/enthought-plan.html>`_
+* `Enthought API Documentation Tool RFP <dev/enthought-rfp.html>`_
+
+reStructuredText_:
+
+* `A Record of reStructuredText Syntax Alternatives
+ <dev/rst/alternatives.html>`__
+* `Problems With StructuredText <dev/rst/problems.html>`__
+
+
+..
+ Local Variables:
+ mode: indented-text
+ indent-tabs-mode: nil
+ sentence-end-double-space: t
+ fill-column: 70
+ End:
Added: trunk/jrst/src/test/resources/FilesTest/roles.txt
===================================================================
--- trunk/jrst/src/test/resources/FilesTest/roles.txt (rev 0)
+++ trunk/jrst/src/test/resources/FilesTest/roles.txt 2011-05-19 09:51:39 UTC (rev 586)
@@ -0,0 +1,318 @@
+=========================================
+ reStructuredText Interpreted Text Roles
+=========================================
+
+:Author: David Goodger
+:Contact: goodger(a)python.org
+:Revision: $Revision: 4564 $
+:Date: $Date: 2006-05-21 16:44:42 -0400 (Sun, 21 May 2006) $
+:Copyright: This document has been placed in the public domain.
+
+This document describes the interpreted text roles implemented in the
+reference reStructuredText parser.
+
+Interpreted text uses backquotes (`) around the text. An explicit
+role marker may optionally appear before or after the text, delimited
+with colons. For example::
+
+ This is `interpreted text` using the default role.
+
+ This is :title:`interpreted text` using an explicit role.
+
+A default role may be defined by applications of reStructuredText; it
+is used if no explicit ``:role:`` prefix or suffix is given. The
+"default default role" is `:title-reference:`_. It can be changed
+using the default-role_ directive.
+
+See the `Interpreted Text`_ section in the `reStructuredText Markup
+Specification`_ for syntax details. For details on the hierarchy of
+elements, please see `The Docutils Document Tree`_ and the `Docutils
+Generic DTD`_ XML document type definition. For interpreted text role
+implementation details, see `Creating reStructuredText Interpreted
+Text Roles`_.
+
+.. _"role" directive: directives.html#role
+.. _default-role: directives.html#default-role
+.. _Interpreted Text: restructuredtext.html#interpreted-text
+.. _reStructuredText Markup Specification: restructuredtext.html
+.. _The Docutils Document Tree: ../doctree.html
+.. _Docutils Generic DTD: ../docutils.dtd
+.. _Creating reStructuredText Interpreted Text Roles:
+ ../../howto/rst-roles.html
+
+
+.. contents::
+
+
+---------------
+ Customization
+---------------
+
+Custom interpreted text roles may be defined in a document with the
+`"role" directive`_. Customization details are listed with each role.
+
+.. _class:
+
+A ``class`` option is recognized by the "role" directive for most
+interpreted text roles. A description__ is provided in the `"role"
+directive`_ documentation.
+
+__ directives.html#role-class
+
+
+----------------
+ Standard Roles
+----------------
+
+``:emphasis:``
+==============
+
+:Aliases: None
+:DTD Element: emphasis
+:Customization:
+ :Options: class_.
+ :Content: None.
+
+Implements emphasis. These are equivalent::
+
+ *text*
+ :emphasis:`text`
+
+
+``:literal:``
+==============
+
+:Aliases: None
+:DTD Element: literal
+:Customization:
+ :Options: class_.
+ :Content: None.
+
+Implements inline literal text. These are equivalent::
+
+ ``text``
+ :literal:`text`
+
+Care must be taken with backslash-escapes though. These are *not*
+equivalent::
+
+ ``text \ and \ backslashes``
+ :literal:`text \ and \ backslashes`
+
+The backslashes in the first line are preserved (and do nothing),
+whereas the backslashes in the second line escape the following
+spaces.
+
+
+``:pep-reference:``
+===================
+
+:Aliases: ``:PEP:``
+:DTD Element: reference
+:Customization:
+ :Options: class_.
+ :Content: None.
+
+The ``:pep-reference:`` role is used to create an HTTP reference to a
+PEP (Python Enhancement Proposal). The ``:PEP:`` alias is usually
+used. For example::
+
+ See :PEP:`287` for more information about reStructuredText.
+
+This is equivalent to::
+
+ See `PEP 287`__ for more information about reStructuredText.
+
+ __ http://www.python.org/peps/pep-0287.html
+
+
+``:rfc-reference:``
+===================
+
+:Aliases: ``:RFC:``
+:DTD Element: reference
+:Customization:
+ :Options: class_.
+ :Content: None.
+
+The ``:rfc-reference:`` role is used to create an HTTP reference to an
+RFC (Internet Request for Comments). The ``:RFC:`` alias is usually
+used. For example::
+
+ See :RFC:`2822` for information about email headers.
+
+This is equivalent to::
+
+ See `RFC 2822`__ for information about email headers.
+
+ __ http://www.faqs.org/rfcs/rfc2822.html
+
+
+``:strong:``
+============
+
+:Aliases: None
+:DTD Element: strong
+:Customization:
+ :Options: class_.
+ :Content: None.
+
+Implements strong emphasis. These are equivalent::
+
+ **text**
+ :strong:`text`
+
+
+``:subscript:``
+===============
+
+:Aliases: ``:sub:``
+:DTD Element: subscript
+:Customization:
+ :Options: class_.
+ :Content: None.
+
+Implements subscripts.
+
+.. Tip::
+
+ Whitespace or punctuation is required around interpreted text, but
+ often not desired with subscripts & superscripts.
+ Backslash-escaped whitespace can be used; the whitespace will be
+ removed from the processed document::
+
+ H\ :sub:`2`\ O
+ E = mc\ :sup:`2`
+
+ In such cases, readability of the plain text can be greatly
+ improved with substitutions::
+
+ The chemical formula for pure water is |H2O|.
+
+ .. |H2O| replace:: H\ :sub:`2`\ O
+
+ See `the reStructuredText spec`__ for further information on
+ `character-level markup`__ and `the substitution mechanism`__.
+
+ __ restructuredtext.html
+ __ restructuredtext.html#character-level-inline-markup
+ __ restructuredtext.html#substitution-references
+
+
+``:superscript:``
+=================
+
+:Aliases: ``:sup:``
+:DTD Element: superscript
+:Customization:
+ :Options: class_.
+ :Content: None.
+
+Implements superscripts. See the tip in `:subscript:`_ above.
+
+
+``:title-reference:``
+=====================
+
+:Aliases: ``:title:``, ``:t:``.
+:DTD Element: title_reference
+:Customization:
+ :Options: class_.
+ :Content: None.
+
+The ``:title-reference:`` role is used to describe the titles of
+books, periodicals, and other materials. It is the equivalent of the
+HTML "cite" element, and it is expected that HTML writers will
+typically render "title_reference" elements using "cite".
+
+Since title references are typically rendered with italics, they are
+often marked up using ``*emphasis*``, which is misleading and vague.
+The "title_reference" element provides accurate and unambiguous
+descriptive markup.
+
+Let's assume ``:title-reference:`` is the default interpreted text
+role (see below) for this example::
+
+ `Design Patterns` [GoF95]_ is an excellent read.
+
+The following document fragment (pseudo-XML_) will result from
+processing::
+
+ <paragraph>
+ <title_reference>
+ Design Patterns
+
+ <citation_reference refname="gof95">
+ GoF95
+ is an excellent read.
+
+``:title-reference:`` is the default interpreted text role in the
+standard reStructuredText parser. This means that no explicit role is
+required. Applications of reStructuredText may designate a different
+default role, in which case the explicit ``:title-reference:`` role
+must be used to obtain a ``title_reference`` element.
+
+
+.. _pseudo-XML: ../doctree.html#pseudo-xml
+
+
+-------------------
+ Specialized Roles
+-------------------
+
+``raw``
+=======
+
+:Aliases: None
+:DTD Element: raw
+:Customization:
+ :Options: class_, format
+ :Content: None
+
+.. WARNING::
+
+ The "raw" role is a stop-gap measure allowing the author to bypass
+ reStructuredText's markup. It is a "power-user" feature that
+ should not be overused or abused. The use of "raw" ties documents
+ to specific output formats and makes them less portable.
+
+ If you often need to use "raw"-derived interpreted text roles or
+ the "raw" directive, that is a sign either of overuse/abuse or that
+ functionality may be missing from reStructuredText. Please
+ describe your situation in a message to the Docutils-users_ mailing
+ list.
+
+ .. _Docutils-users: ../../user/mailing-lists.html#docutils-user
+
+The "raw" role indicates non-reStructuredText data that is to be
+passed untouched to the Writer. It is the inline equivalent of the
+`"raw" directive`_; see its documentation for details on the
+semantics.
+
+.. _"raw" directive: directives.html#raw
+
+The "raw" role cannot be used directly. The `"role" directive`_ must
+first be used to build custom roles based on the "raw" role. One or
+more formats (Writer names) must be provided in a "format" option.
+
+For example, the following creates an HTML-specific "raw-html" role::
+
+ .. role:: raw-html(raw)
+ :format: html
+
+This role can now be used directly to pass data untouched to the HTML
+Writer. For example::
+
+ If there just *has* to be a line break here,
+ :raw-html:`<br />`
+ it can be accomplished with a "raw"-derived role.
+ But the line block syntax should be considered first.
+
+.. Tip:: Roles based on "raw" should clearly indicate their origin, so
+ they are not mistaken for reStructuredText markup. Using a "raw-"
+ prefix for role names is recommended.
+
+In addition to "class_", the following option is recognized:
+
+``format`` : text
+ One or more space-separated output format names (Writer names).
Added: trunk/jrst/src/test/resources/FilesTest/rstTest.rst
===================================================================
--- trunk/jrst/src/test/resources/FilesTest/rstTest.rst (rev 0)
+++ trunk/jrst/src/test/resources/FilesTest/rstTest.rst 2011-05-19 09:51:39 UTC (rev 586)
@@ -0,0 +1,5 @@
+=====
+tests
+=====
+
+le paragraphe de test
1
0
r585 - in trunk/jrst/src: main/java/org/nuiton/jrst test/java/org/nuiton/jrst test/resources
by kcardineaud@users.nuiton.org 18 May '11
by kcardineaud@users.nuiton.org 18 May '11
18 May '11
Author: kcardineaud
Date: 2011-05-18 16:37:58 +0200 (Wed, 18 May 2011)
New Revision: 585
Url: http://nuiton.org/repositories/revision/jrst/585
Log:
#1538 Probl?\195?\168me avec les anonymous hyperlinks
Added:
trunk/jrst/src/test/resources/testAnonymous.rst
Modified:
trunk/jrst/src/main/java/org/nuiton/jrst/JRSTLexer.java
trunk/jrst/src/test/java/org/nuiton/jrst/JRSTReaderTest.java
Modified: trunk/jrst/src/main/java/org/nuiton/jrst/JRSTLexer.java
===================================================================
--- trunk/jrst/src/main/java/org/nuiton/jrst/JRSTLexer.java 2011-05-18 13:55:12 UTC (rev 584)
+++ trunk/jrst/src/main/java/org/nuiton/jrst/JRSTLexer.java 2011-05-18 14:37:58 UTC (rev 585)
@@ -480,7 +480,7 @@
Element resultTmp = DocumentHelper
.createElement(TARGETANONYMOUS);
resultTmp.addAttribute(LEVEL, "" + level(l));
- Matcher matcher = Pattern.compile("__ ").matcher(l);
+ Matcher matcher = Pattern.compile("__ |.. __: ").matcher(l);
if (matcher.find()) {
resultTmp.addAttribute(REFURI, l.substring(matcher
Modified: trunk/jrst/src/test/java/org/nuiton/jrst/JRSTReaderTest.java
===================================================================
--- trunk/jrst/src/test/java/org/nuiton/jrst/JRSTReaderTest.java 2011-05-18 13:55:12 UTC (rev 584)
+++ trunk/jrst/src/test/java/org/nuiton/jrst/JRSTReaderTest.java 2011-05-18 14:37:58 UTC (rev 585)
@@ -136,5 +136,28 @@
Assert.assertEquals(xmlexpected, actualXml);
}
+
+
+ @Test
+ public void testAnonymous() throws Exception {
+ URL url = JRSTReaderTest.class.getResource("/testAnonymous.rst");
+ Reader in = new InputStreamReader(url.openStream());
+ I18n.init(new ClassPathI18nInitializer(), Locale.UK);
+
+ JRSTReader jrst = new JRSTReader();
+ Document doc = jrst.read(in);
+
+
+ String xmlexpected ="<target anonymous=\"1\" ids=\"id1\" refuri=\"http://www.python.org\"/>"
+ +"<target anonymous=\"1\" ids=\"id2\" refuri=\"http://www.python.org\"/>";
+
+ String actualXml = doc.asXML();
+ log.info("Result :\n" + actualXml);
+ log.info("Expected :\n" + xmlexpected);
+
+ Assert.assertTrue(actualXml.contains(xmlexpected));
+ }
+
+
}
Added: trunk/jrst/src/test/resources/testAnonymous.rst
===================================================================
--- trunk/jrst/src/test/resources/testAnonymous.rst (rev 0)
+++ trunk/jrst/src/test/resources/testAnonymous.rst 2011-05-18 14:37:58 UTC (rev 585)
@@ -0,0 +1,5 @@
+There are three types of hyperlink targets: internal, external, and
+indirect.
+
+ .. __: http://www.python.org
+ __ http://www.python.org
1
0
r584 - in trunk/jrst/src: main/java/org/nuiton/jrst test/java/org/nuiton/jrst
by kcardineaud@users.nuiton.org 18 May '11
by kcardineaud@users.nuiton.org 18 May '11
18 May '11
Author: kcardineaud
Date: 2011-05-18 15:55:12 +0200 (Wed, 18 May 2011)
New Revision: 584
Url: http://nuiton.org/repositories/revision/jrst/584
Log:
#1537 Remplacer les attributs id et name par ids et names dans le XML
Modified:
trunk/jrst/src/main/java/org/nuiton/jrst/JRSTReader.java
trunk/jrst/src/test/java/org/nuiton/jrst/JRSTReaderTest.java
Modified: trunk/jrst/src/main/java/org/nuiton/jrst/JRSTReader.java
===================================================================
--- trunk/jrst/src/main/java/org/nuiton/jrst/JRSTReader.java 2011-05-18 13:35:06 UTC (rev 583)
+++ trunk/jrst/src/main/java/org/nuiton/jrst/JRSTReader.java 2011-05-18 13:55:12 UTC (rev 584)
@@ -380,7 +380,7 @@
protected static final String ATTR_INLINE = "inline";
- protected static final String ATTR_IDS = "id";
+ protected static final String ATTR_IDS = "ids";
protected static final String BACKREFS = "backrefs";
@@ -406,7 +406,7 @@
protected static final String NAME = "name";
- protected static final String NAMES = "name";
+ protected static final String NAMES = "names";
protected static final String NUM = "num";
Modified: trunk/jrst/src/test/java/org/nuiton/jrst/JRSTReaderTest.java
===================================================================
--- trunk/jrst/src/test/java/org/nuiton/jrst/JRSTReaderTest.java 2011-05-18 13:35:06 UTC (rev 583)
+++ trunk/jrst/src/test/java/org/nuiton/jrst/JRSTReaderTest.java 2011-05-18 13:55:12 UTC (rev 584)
@@ -28,15 +28,20 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.dom4j.Document;
+import org.dom4j.io.XMLWriter;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.Reader;
+import java.io.StringWriter;
import java.net.URL;
+import java.util.Locale;
import junit.framework.Assert;
import org.junit.Test;
+import org.nuiton.i18n.I18n;
+import org.nuiton.i18n.init.ClassPathI18nInitializer;
/**
* JRSTReaderTest.
@@ -72,7 +77,7 @@
Reader in = new InputStreamReader(url.openStream());
JRSTReader jrst = new JRSTReader();
Document doc = jrst.read(in);
- String xmlexpected = "<topic class=\"contents\" id=\"table des matières\" name=\"table des matières\">" +
+ String xmlexpected = "<topic class=\"contents\" ids=\"table des matières\" names=\"table des matières\">" +
"<title>Table des matières</title>" +
"</topic>" +
"<paragraph>Texte</paragraph>" +
@@ -131,4 +136,5 @@
Assert.assertEquals(xmlexpected, actualXml);
}
+
}
1
0
18 May '11
Author: kcardineaud
Date: 2011-05-18 15:35:06 +0200 (Wed, 18 May 2011)
New Revision: 583
Url: http://nuiton.org/repositories/revision/jrst/583
Log:
#1393 Replace String constant usage by real constant variable
Modified:
trunk/jrst/src/main/java/org/nuiton/jrst/JRSTLexer.java
trunk/jrst/src/main/java/org/nuiton/jrst/JRSTReader.java
Modified: trunk/jrst/src/main/java/org/nuiton/jrst/JRSTLexer.java
===================================================================
--- trunk/jrst/src/main/java/org/nuiton/jrst/JRSTLexer.java 2011-05-17 14:34:48 UTC (rev 582)
+++ trunk/jrst/src/main/java/org/nuiton/jrst/JRSTLexer.java 2011-05-18 13:35:06 UTC (rev 583)
@@ -120,6 +120,8 @@
static final public String PARAGRAPH = "paragraph";
static final public String BLANK_LINE = "blankLine";
+
+ static final public String COMMENT = "comment";
static final public String SUBSTITUTION_DEFINITION = "substitution_definition";
@@ -146,6 +148,13 @@
public static final String TARGET = "target";
public static final String FOOTNOTE = "footnote";
+
+ public static final String FOOTNOTES = "footnotes";
+
+ public static final String LEVEL = "level";
+
+ public static final String TARGETANONYMOUS = "targetAnonymous";
+
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Table Elements
@@ -170,7 +179,11 @@
static final public String CELL_BEGIN = "begin";
static final public String CELL_END = "end";
+
+ static final public String REMOVE = "remove";
+ static final public String INCLUDE = "include";
+
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Directive Elements
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -180,7 +193,72 @@
static final public String DIRECTIVE_TYPE = "type";
static final public String DIRECTIVE_VALUE = "value";
+
+
+ // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ // Attributs
+ // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+ static final public String AUTONUM = "autoNum";
+
+ static final public String AUTONUMLABEL = "autoNumLabel";
+
+ static final public String AUTOSYMBOL = "autoSymbol";
+
+ static final public String BULLET = "bullet";
+
+ static final public String CHAR = "char";
+
+ static final public String ID = "id";
+
+ static final public String CLASSIFIERS = "classifiers";
+
+ static final public String DELIMITER = "delimiter";
+
+ static final public String DELIMITEREXISTE ="delimiterExiste";
+
+ static final public String ENUMTYPE = "enumtype";
+
+ static final public String REFURI = "refuri";
+
+ static final public String OPTION = "option";
+
+ static final public String LITERAL = "literal";
+
+ static final public String NAME = "name";
+
+ static final public String NUM ="num";
+
+ static final public String OPTIONARGUMENT = "option_argument";
+
+ static final public String OPTIONSTRING = "option_string";
+
+ static final public String PREFIX = "prefix";
+
+ static final public String START = "start";
+
+ static final public String SUBEXISTE = "subExiste";
+
+ static final public String SUFFIX = "suffix";
+
+ static final public String SUBTITLE = "subtitle";
+
+ static final public String TERM = "term";
+
+ static final public String TITLEATTR = "title";
+
+ static final public String XMLSPACE = "xml:space";
+
+ static final public String TYPE = "type";
+
+ // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+ protected static final String TRUE = "true";
+
+ protected static final String FALSE = "false";
+
+
/**
* retient le niveau du titre, pour un titre de type double, on met deux
* fois le caratere dans la chaine, sinon on le met une seul fois.
@@ -334,8 +412,8 @@
int level = level(l);
l = l.replaceAll("^\\s*.. " + HEADER + ":: ", "");
result = DocumentHelper.createElement(HEADER).addAttribute(
- "level", String.valueOf(level));
- result.addAttribute("line", "" + i);
+ LEVEL, String.valueOf(level));
+ result.addAttribute(LINE, "" + i);
result.setText(l);
}
@@ -369,8 +447,8 @@
int level = level(l);
l = l.replaceAll("^\\s*.. " + FOOTER + ":: ", "");
result = DocumentHelper.createElement(FOOTER).addAttribute(
- "level", String.valueOf(level));
- result.addAttribute("line", "" + i);
+ LEVEL, String.valueOf(level));
+ result.addAttribute(LINE, "" + i);
result.setText(l);
}
}
@@ -398,14 +476,17 @@
i++;
if (l.matches("^\\s*__ .+$|^\\s*\\.\\. __\\:.+$")) {
+ log.debug(l);
Element resultTmp = DocumentHelper
- .createElement("targetAnonymous");
- resultTmp.addAttribute("level", "" + level(l));
+ .createElement(TARGETANONYMOUS);
+ resultTmp.addAttribute(LEVEL, "" + level(l));
Matcher matcher = Pattern.compile("__ ").matcher(l);
+
if (matcher.find()) {
- resultTmp.addAttribute("refuri", l.substring(matcher
+ resultTmp.addAttribute(REFURI, l.substring(matcher
.end(), l.length()));
}
+
result.add(resultTmp);
}
}
@@ -556,13 +637,13 @@
if (line != null) {
// Le header est parse des le debut
if (line.matches("^\\s*.. " + HEADER + ":: .*")) {
- result = DocumentHelper.createElement("remove").addAttribute(
- "level", "" + level(line));
+ result = DocumentHelper.createElement(REMOVE).addAttribute(
+ LEVEL, "" + level(line));
}
// Le footer
if (line.matches("^\\s*.. " + FOOTER + ":: .*")) {
- result = DocumentHelper.createElement("remove").addAttribute(
- "level", "" + level(line));
+ result = DocumentHelper.createElement(REMOVE).addAttribute(
+ LEVEL, "" + level(line));
}
}
@@ -590,12 +671,12 @@
String line = in.readLine();
if (line != null) {
if (line.matches("^\\s*\\.\\.\\sinclude\\:\\:.+$")) {
- result = DocumentHelper.createElement("include");
- result.addAttribute("level", "" + level(line));
+ result = DocumentHelper.createElement(INCLUDE);
+ result.addAttribute(LEVEL, "" + level(line));
String option = line.substring(line.indexOf("::") + 2).trim();
- result.addAttribute("option", "");
- if (option.trim().equalsIgnoreCase("literal")) {
- result.addAttribute("option", "literal");
+ result.addAttribute(OPTION, "");
+ if (option.trim().equalsIgnoreCase(LITERAL)) {
+ result.addAttribute(OPTION, LITERAL);
line = in.readLine();
result.setText(line.trim());
} else {
@@ -640,17 +721,17 @@
if (line != null) {
if (line.matches("^(\\s*((--?)|(//?))\\w+([ =][<a-zA-Z][\\w-><]*)?)\\s*.*$")) {
result = DocumentHelper.createElement(OPTION_LIST)
- .addAttribute("level", "" + level(line));
+ .addAttribute(LEVEL, "" + level(line));
char delimiter;
do {
Matcher matcher = Pattern.compile("[-/][-/]?.+").matcher(line);
matcher.find();
- Element option = result.addElement("option");
+ Element option = result.addElement(OPTION);
String option_stringTmp = matcher.group();
matcher = Pattern.compile("^[-/][-/]?\\w+").matcher(option_stringTmp);
matcher.find();
String option_string = matcher.group();
- option.addAttribute("option_string", option_string);
+ option.addAttribute(OPTIONSTRING, option_string);
boolean done = false;
// Delimiteur bidon
@@ -662,7 +743,7 @@
} else {
done = true;
}
- option.addAttribute("delimiterExiste", "false");
+ option.addAttribute(DELIMITEREXISTE, FALSE);
if (delimiter == ' ') { // S'il y a 2 espaces a suivre,
// l'option est finie
@@ -672,14 +753,14 @@
}
String option_argument = null;
if ((delimiter == '=' || delimiter == ' ') && !done) {
- option.addAttribute("delimiterExiste", "true");
- option.addAttribute("delimiter", "" + delimiter);
+ option.addAttribute(DELIMITEREXISTE, TRUE);
+ option.addAttribute(DELIMITER, "" + delimiter);
matcher = Pattern.compile(delimiter + "(([a-zA-Z][\\w-]+)|(<[a-zA-Z][^>]*>))").matcher(
option_stringTmp);
if (matcher.find()) {
option_argument = matcher.group().substring(1,
matcher.group().length());
- option.addAttribute("option_argument", option_argument);
+ option.addAttribute(OPTIONARGUMENT, option_argument);
if (option_stringTmp.charAt(option_argument.length() + 1) == ',') {
delimiter = ',';
} else {
@@ -688,7 +769,7 @@
} else { // Si la description n'est pas sur la meme
// ligne
option_argument = option_stringTmp;
- option.addAttribute("option_argument",
+ option.addAttribute(OPTIONARGUMENT,
option_argument);
line = in.readLine();
if (line != null) {
@@ -731,7 +812,7 @@
Matcher matcher = Pattern.compile(TOPIC + "::").matcher(line);
matcher.find();
result = DocumentHelper.createElement(TOPIC).addAttribute(
- "level", "" + level(line));
+ LEVEL, "" + level(line));
String title = line.substring(matcher.end(), line.length());
result.addAttribute(TITLE, title);
line = in.readLine();
@@ -777,7 +858,7 @@
Matcher matcher = Pattern.compile(SIDEBAR + "::").matcher(line);
matcher.find();
result = DocumentHelper.createElement(SIDEBAR).addAttribute(
- "level", "" + level(line));
+ LEVEL, "" + level(line));
String title = line.substring(matcher.end(), line.length());
result.addAttribute(TITLE, title);
line = in.readLine();
@@ -786,11 +867,11 @@
matcher.find();
String subTitle = line.substring(matcher.end(), line
.length());
- result.addAttribute("subExiste", "true");
- result.addAttribute("subtitle", subTitle);
+ result.addAttribute(SUBEXISTE, TRUE);
+ result.addAttribute(SUBTITLE, subTitle);
line = in.readLine();
} else {
- result.addAttribute("subExiste", "false");
+ result.addAttribute(SUBEXISTE, FALSE);
}
String txt = joinBlock(readBlock(level(line)));
result.setText(txt);
@@ -832,7 +913,7 @@
int[] levelsTmp = new int[lines.length];
int levelmin = 999;
result = DocumentHelper.createElement(LINE_BLOCK).addAttribute(
- "level", 0 + "");
+ LEVEL, 0 + "");
for (int i = 0; i < levelsTmp.length; i++) {
// on enleve |
lines[i] = lines[i].replaceAll("\\|\\s?", "");
@@ -893,7 +974,7 @@
}
for (int i = 0; i < levels.length; i++) {
Element eLine = result.addElement(LINE);
- eLine.addAttribute("level", "" + levels[i]);
+ eLine.addAttribute(LEVEL, "" + levels[i]);
eLine.setText(lines[i].trim());
}
}
@@ -921,8 +1002,8 @@
if (line.matches("^\\s*>>>\\s.*")) {
int level = level(line);
result = DocumentHelper.createElement(DOCTEST_BLOCK)
- .addAttribute("level", String.valueOf(level));
- result.addAttribute("xml:space", "preserve");
+ .addAttribute(LEVEL, String.valueOf(level));
+ result.addAttribute(XMLSPACE, "preserve");
line += "\n" + joinBlock(readBlock(level));
result.setText(line);
}
@@ -972,7 +1053,7 @@
}
}
result = DocumentHelper.createElement(BLOCK_QUOTE)
- .addAttribute("level", String.valueOf(level));
+ .addAttribute(LEVEL, String.valueOf(level));
if (blockQuote != null) {
result.addAttribute(ATTRIBUTION, blockQuote);
}
@@ -1016,20 +1097,20 @@
matcher.find();
int level = level(line);
result = DocumentHelper.createElement(ADMONITION).addAttribute(
- "level", "" + level);
+ LEVEL, "" + level);
if (matcher.group().equals(ADMONITION)) { // Il y a un titre
// pour un
// admonition
// general
admonition = true;
- result.addAttribute("type", ADMONITION);
+ result.addAttribute(TYPE, ADMONITION);
String title = line.substring(matcher.end() + 2, line
.length());
- result.addAttribute("title", title);
+ result.addAttribute(TITLEATTR, title);
} else {
- result.addAttribute("type", matcher.group());
+ result.addAttribute(TYPE, matcher.group());
}
String firstLine = "";
@@ -1074,7 +1155,7 @@
if (line != null && line.matches("\\s*")) {
int level = level(line);
result = DocumentHelper.createElement(BLANK_LINE).addAttribute(
- "level", String.valueOf(level));
+ LEVEL, String.valueOf(level));
}
endPeek();
@@ -1103,13 +1184,13 @@
if (ref != null && !"".equals(ref)) {
result = DocumentHelper
.createElement(SUBSTITUTION_DEFINITION);
- result.addAttribute("name", ref);
+ result.addAttribute(NAME, ref);
directive = result.addElement(DIRECTIVE);
} else {
result = DocumentHelper.createElement(DIRECTIVE);
directive = result;
}
- result.addAttribute("level", "0");
+ result.addAttribute(LEVEL, "0");
directive.addAttribute(DIRECTIVE_TYPE, directiveType);
directive.addAttribute(DIRECTIVE_VALUE, directiveValue);
@@ -1146,7 +1227,7 @@
// must have one blank line after
if (line != null && line.matches("\\s*")) {
result = DocumentHelper.createElement(TRANSITION)
- .addAttribute("level", String.valueOf(0));
+ .addAttribute(LEVEL, String.valueOf(0));
}
}
}
@@ -1195,7 +1276,7 @@
// if para is empty, there are error and possible
// infiny loop on para, force read next line
result = DocumentHelper.createElement(PARAGRAPH)
- .addAttribute("level", String.valueOf(level))
+ .addAttribute(LEVEL, String.valueOf(level))
.addText(para);
}
}
@@ -1247,7 +1328,7 @@
}
result = DocumentHelper.createElement(LITERAL_BLOCK)
- .addAttribute("level", String.valueOf(level)).addText(
+ .addAttribute(LEVEL, String.valueOf(level)).addText(
para);
}
}
@@ -1279,7 +1360,7 @@
if (line != null && line.matches("^:((?i)" + DOCINFO_ITEM + "):.*$")) {
result = DocumentHelper.createElement(DOCINFO);
- result.addAttribute("level", "0");
+ result.addAttribute(LEVEL, "0");
String infotype = line.substring(1, line.indexOf(":", 1));
/*
@@ -1299,7 +1380,7 @@
// CVS, RCS support
text = text.replaceAll("\\$\\w+: (.+?)\\$", "$1");
- result.addAttribute("type", infotype).addText(text);
+ result.addAttribute(TYPE, infotype).addText(text);
}
endPeek();
return result;
@@ -1337,9 +1418,9 @@
matcher = pTableBegin.matcher(line);
if (matcher.matches()) { // complexe table
result = DocumentHelper.createElement(TABLE);
- result.addAttribute(TABLE_HEADER, "false");
+ result.addAttribute(TABLE_HEADER, FALSE);
int level = level(line);
- result.addAttribute("level", String.valueOf(level));
+ result.addAttribute(LEVEL, String.valueOf(level));
line = line.trim();
int tableWidth = line.length();
result.addAttribute(TABLE_WIDTH, String.valueOf(tableWidth));
@@ -1378,9 +1459,9 @@
// fin normale de ligne, on peut directement l'assigner
lastSeparationLine = l;
for (Element cell : (List<Element>) row.elements()) {
- cell.addAttribute(CELL_END, "true");
+ cell.addAttribute(CELL_END, TRUE);
}
- row.addAttribute(ROW_END_HEADER, "false");
+ row.addAttribute(ROW_END_HEADER, FALSE);
result.add(row);
row = DocumentHelper.createElement(ROW);
done = true;
@@ -1390,11 +1471,11 @@
// fin de du header, on peut directement l'assigner
lastSeparationLine = l;
for (Element cell : (List<Element>) row.elements()) {
- cell.addAttribute(CELL_END, "true");
+ cell.addAttribute(CELL_END, TRUE);
}
- row.addAttribute(ROW_END_HEADER, "true");
+ row.addAttribute(ROW_END_HEADER, TRUE);
result.add(row);
- result.addAttribute(TABLE_HEADER, "true");
+ result.addAttribute(TABLE_HEADER, TRUE);
row = DocumentHelper.createElement(ROW);
done = true;
}
@@ -1429,7 +1510,7 @@
Element cell = null;
if (row.nodeCount() <= cellNumber) {
cell = row.addElement(CELL);
- cell.addAttribute(CELL_END, "false");
+ cell.addAttribute(CELL_END, FALSE);
} else {
cell = (Element) row.node(cellNumber);
}
@@ -1464,7 +1545,7 @@
// mais on commence tout de meme par fermer tout les
// cells
for (Element cell : (List<Element>) row.elements()) {
- cell.addAttribute(CELL_END, "true");
+ cell.addAttribute(CELL_END, TRUE);
}
StringBuffer tmp = new StringBuffer(l);
@@ -1505,7 +1586,7 @@
// on a ajouter des choses dans la cell,
// donc
// ce n'est pas la fin
- cell.addAttribute(CELL_END, "false");
+ cell.addAttribute(CELL_END, FALSE);
cell.addAttribute(CELL_INDEX_START, String
.valueOf(start));
cell.addAttribute(CELL_INDEX_END, String
@@ -1520,7 +1601,7 @@
}
}
lastSeparationLine = tmp.toString();
- row.addAttribute(ROW_END_HEADER, "false");
+ row.addAttribute(ROW_END_HEADER, FALSE);
result.add(row);
row = DocumentHelper.createElement(ROW);
done = true;
@@ -1576,7 +1657,7 @@
// Header if the table contains 3 equals separations
result.addAttribute(TABLE_HEADER, "" + (nbSeparations == 2));
int level = level(line);
- result.addAttribute("level", String.valueOf(level));
+ result.addAttribute(LEVEL, String.valueOf(level));
result
.addAttribute(TABLE_WIDTH, String
.valueOf(tableWidth + 1));
@@ -1672,10 +1753,10 @@
if (lastLines.size() == 0) {
row.addAttribute("debug", "pCell");
- cell.addAttribute(CELL_END, "true");
+ cell.addAttribute(CELL_END, TRUE);
} else {
row.addAttribute("debug", "pCellEnd");
- cell.addAttribute(CELL_END, "false");
+ cell.addAttribute(CELL_END, FALSE);
}
cell.addAttribute(CELL_INDEX_START, String
.valueOf(matcher.start() + 1));
@@ -1692,7 +1773,7 @@
row.addAttribute(ROW_END_HEADER, ""
+ (separation == 2));
} else {
- row.addAttribute(ROW_END_HEADER, "false");
+ row.addAttribute(ROW_END_HEADER, FALSE);
}
result.add(row);
@@ -1745,7 +1826,7 @@
String bullet = line.substring(level, level + 1);
result = DocumentHelper.createElement(BULLET_LIST).addAttribute(
- "level", String.valueOf(level)).addAttribute("bullet",
+ LEVEL, String.valueOf(level)).addAttribute(BULLET,
bullet);
if (!in.eof()) {
@@ -1791,7 +1872,7 @@
int begin = matcher.end(1) + 1;
result = DocumentHelper.createElement(FIELD_LIST).addAttribute(
- "level", String.valueOf(level)).addAttribute("name",
+ LEVEL, String.valueOf(level)).addAttribute(NAME,
name);
if (!in.eof()) {
@@ -1842,9 +1923,9 @@
String classifiers = matcher.group(2);
result = DocumentHelper.createElement(DEFINITION_LIST)
- .addAttribute("level", String.valueOf(level))
- .addAttribute("term", term).addAttribute(
- "classifiers", classifiers);
+ .addAttribute(LEVEL, String.valueOf(level))
+ .addAttribute(TERM, term).addAttribute(
+ CLASSIFIERS, classifiers);
// poussin 20070207 don't read block here because can't
// interpret it correctly in JRSTReader
@@ -1917,10 +1998,10 @@
}
result = DocumentHelper.createElement(ENUMERATED_LIST)
- .addAttribute("level", String.valueOf(level))
- .addAttribute("start", start).addAttribute("prefix",
- prefix).addAttribute("suffix", suffix)
- .addAttribute("enumtype", enumtype);
+ .addAttribute(LEVEL, String.valueOf(level))
+ .addAttribute(START, start).addAttribute(PREFIX,
+ prefix).addAttribute(SUFFIX, suffix)
+ .addAttribute(ENUMTYPE, enumtype);
if (!in.eof()) {
String[] content = readBlock(level + 1);
@@ -1974,7 +2055,7 @@
&& line.length() == titles[1].length()
&& line.equals(titles[1])) {
result = DocumentHelper.createElement(TITLE).addAttribute(
- "type", "double").addAttribute("char",
+ TYPE, "double").addAttribute(CHAR,
titles[1].substring(0, 1)).addText(titles[0]);
}
} else {
@@ -1985,7 +2066,7 @@
.length()) {
result = DocumentHelper.createElement(TITLE).addAttribute(
- "type", "simple").addAttribute("char",
+ TYPE, "simple").addAttribute(CHAR,
title.substring(0, 1)).addText(
line.replaceFirst("\\s*$", ""));
}
@@ -1994,9 +2075,9 @@
if (result != null) {
// add level information
- String titleLevel = result.attributeValue("char");
+ String titleLevel = result.attributeValue(CHAR);
- if ("double".equals(result.attributeValue("type"))) {
+ if ("double".equals(result.attributeValue(TYPE))) {
titleLevel += titleLevel;
}
int level = titleLevels.indexOf(titleLevel);
@@ -2004,7 +2085,7 @@
level = titleLevels.size();
titleLevels.add(titleLevel);
}
- result.addAttribute("level", String
+ result.addAttribute(LEVEL, String
.valueOf(JRSTReader.MAX_SECTION_DEPTH + level));
}
@@ -2023,9 +2104,9 @@
Matcher matcher = Pattern.compile("\\.\\.\\s_").matcher(line);
if (matcher.find()) {
int i = line.indexOf(':');
- result.addAttribute("id", URLEncoder.encode(line.substring(matcher.end(), i)
+ result.addAttribute(ID, URLEncoder.encode(line.substring(matcher.end(), i)
.toLowerCase().replaceAll(" ", "-"), "UTF-8"));
- result.addAttribute("level", "" + level(line));
+ result.addAttribute(LEVEL, "" + level(line));
}
}
}
@@ -2052,14 +2133,14 @@
boolean done = false;
for (int i = matcher.end(); i < line.length() && !done; i++) {
if (line.charAt(i) == ':') {
- result.getLast().addAttribute("level",
+ result.getLast().addAttribute(LEVEL,
"" + level(line));
result.getLast().addAttribute(
- "id",
+ ID,
URLEncoder.encode(line.substring(matcher.end(), i)
.replaceAll(" ", "-").toLowerCase(), "UTF-8"));
result.getLast().addAttribute(
- "name",
+ NAME,
line.substring(matcher.end(), i)
.toLowerCase());
if (i + 2 > line.length()) {
@@ -2071,10 +2152,10 @@
if (line == null) {
line = "";
}
- result.getLast().addAttribute("refuri",
+ result.getLast().addAttribute(REFURI,
line.trim());
} else {
- result.getLast().addAttribute("refuri", line.substring(i + 2, line.length()));
+ result.getLast().addAttribute(REFURI, line.substring(i + 2, line.length()));
}
done = true;
@@ -2099,8 +2180,8 @@
String line = in.readLine();
if (line != null) {
if (line.matches("^\\s*__ .+$|^\\s*\\.\\. __\\:.+$")) {
- result = DocumentHelper.createElement("targetAnonymous");
- result.addAttribute("level", "" + level(line));
+ result = DocumentHelper.createElement(TARGETANONYMOUS);
+ result.addAttribute(LEVEL, "" + level(line));
}
}
@@ -2121,9 +2202,9 @@
String line = in.readLine();
if (line != null) {
if (line.matches("^\\.\\.\\s+.*$")) {
- result = DocumentHelper.createElement("comment");
- result.addAttribute("level", "0");
- result.addAttribute("xml:space", "preserve");
+ result = DocumentHelper.createElement(COMMENT);
+ result.addAttribute(LEVEL, "0");
+ result.addAttribute(XMLSPACE, "preserve");
// first line is part of comment
result.setText(line.substring(2).trim());
@@ -2159,9 +2240,9 @@
if (lines != null) {
// int levelRef = level(line);
for (String line : lines) {
- Element comment = DocumentHelper.createElement("comment");
- comment.addAttribute("level", "0");
- comment.addAttribute("xml:space", "preserve");
+ Element comment = DocumentHelper.createElement(COMMENT);
+ comment.addAttribute(LEVEL, "0");
+ comment.addAttribute(XMLSPACE, "preserve");
// first line is part of comment
comment.setText(line.substring(2).trim());
@@ -2196,7 +2277,7 @@
String line = in.readLine();
if (line != null) {
if (line.matches("^\\s*\\.\\.\\s\\[(#|[0-9]|\\*).*\\]\\s.+$")) {
- result = DocumentHelper.createElement("footnotes");
+ result = DocumentHelper.createElement(FOOTNOTES);
boolean bLine = false;
do {
@@ -2211,19 +2292,19 @@
for (int i = matcher.end(); i < line.length() && !done; i++) {
if (line.charAt(i) == ']') {
- result.addAttribute("level", "" + level(line));
+ result.addAttribute(LEVEL, "" + level(line));
String id = line.substring(matcher.end(), i);
if (id.matches("\\*")) {
- footnote.addAttribute("type", "autoSymbol");
+ footnote.addAttribute(TYPE, AUTOSYMBOL);
} else if (id.matches("[0-9]")) {
- footnote.addAttribute("type", "num");
- footnote.addAttribute("name", id);
+ footnote.addAttribute(TYPE, NUM);
+ footnote.addAttribute(NAME, id);
} else if (id.equals("#")) {
- footnote.addAttribute("type", "autoNum");
+ footnote.addAttribute(TYPE, AUTONUM);
} else {
- footnote.addAttribute("type",
- "autoNumLabel");
- footnote.addAttribute("name", id
+ footnote.addAttribute(TYPE,
+ AUTONUMLABEL);
+ footnote.addAttribute(NAME, id
.substring(1));
}
String text = line.substring(i + 2, line
Modified: trunk/jrst/src/main/java/org/nuiton/jrst/JRSTReader.java
===================================================================
--- trunk/jrst/src/main/java/org/nuiton/jrst/JRSTReader.java 2011-05-17 14:34:48 UTC (rev 582)
+++ trunk/jrst/src/main/java/org/nuiton/jrst/JRSTReader.java 2011-05-18 13:35:06 UTC (rev 583)
@@ -69,8 +69,10 @@
import static org.nuiton.jrst.ReStructuredText.FOOTNOTE;
import static org.nuiton.jrst.ReStructuredText.FOOTNOTE_REFERENCE;
import static org.nuiton.jrst.ReStructuredText.FOOTNOTE_SYMBOL;
+import static org.nuiton.jrst.ReStructuredText.GENERATED;
import static org.nuiton.jrst.ReStructuredText.HEADER;
import static org.nuiton.jrst.ReStructuredText.IMAGE;
+import static org.nuiton.jrst.ReStructuredText.LABEL;
import static org.nuiton.jrst.ReStructuredText.LINE;
import static org.nuiton.jrst.ReStructuredText.LINE_BLOCK;
import static org.nuiton.jrst.ReStructuredText.LIST_ITEM;
@@ -114,6 +116,7 @@
import static org.nuiton.jrst.ReStructuredText.TRANSITION;
import static org.nuiton.jrst.ReStructuredText.VERSION;
+
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
@@ -363,6 +366,72 @@
/** to use log facility, just put in your code: log.info(\"...\"); */
private static Log log = LogFactory.getLog(JRSTReader.class);
+ protected static final String ANONYMOUS = "anonymous";
+
+ protected static final String AUTO = "auto";
+
+ protected static final String AUTONUM = "autoNum";
+
+ protected static final String AUTONUMLABEL = "autoNumLabel";
+
+ protected static final String AUTOSYMBOL = "autoSymbol";
+
+ protected static final String ATTR_REFID = "refid";
+
+ protected static final String ATTR_INLINE = "inline";
+
+ protected static final String ATTR_IDS = "id";
+
+ protected static final String BACKREFS = "backrefs";
+
+ protected static final String BULLET = "bullet";
+
+ protected static final String CLASS = "class";
+
+ protected static final String CONTENTS = "contents";
+
+ protected static final String DELIMITER = "delimiter";
+
+ protected static final String DELIMITEREXISTE ="delimiterExiste";
+
+ protected static final String ENUMTYPE = "enumtype";
+
+ protected static final String FOOTNOTES = "footnotes";
+
+ protected static final String ID = "id";
+
+ protected static final String INCLUDE = "include";
+
+ protected static final String LEVEL = "level";
+
+ protected static final String NAME = "name";
+
+ protected static final String NAMES = "name";
+
+ protected static final String NUM = "num";
+
+ protected static final String REFURI = "refuri";
+
+ protected static final String PREFIX = "prefix";
+
+ protected static final String REMOVE = "remove";
+
+ protected static final String START = "start";
+
+ protected static final String SECTNUM = "sectnum";
+
+ protected static final String SUBEXISTE = "subExiste";
+
+ protected static final String SUFFIX = "suffix";
+
+ protected static final String TRUE = "true";
+
+ protected static final String TYPE = "type";
+
+ protected static final String TARGETANONYMOUS = "targetAnonymous";
+
+ protected static final String VALUE = "value";
+
protected boolean ERROR_MISSING_ITEM;
protected static int MAX_SECTION_DEPTH = -1000;
@@ -400,9 +469,9 @@
defaultDirectives.put(IMAGE, new ImageDirective());
defaultDirectives.put(DATE, new DateDirective());
defaultDirectives.put("time", new DateDirective());
- defaultDirectives.put("contents", new ContentDirective());
+ defaultDirectives.put(CONTENTS, new ContentDirective());
// defaultDirectives.put("calc", new CalcDirective());
- defaultDirectives.put("sectnum", new SectnumDirective());
+ defaultDirectives.put(SECTNUM, new SectnumDirective());
// TODO put here all other directive
}
@@ -464,18 +533,18 @@
@Override
public void visit(Element e) {
// remove all level attribute
- e.addAttribute("level", null);
+ e.addAttribute(LEVEL, null);
// Constrution du sommaire
- String type = e.attributeValue("type");
+ String type = e.attributeValue(TYPE);
if (type != null) {
- if (type.equals("contents")) {
+ if (type.equals(CONTENTS)) {
composeContents(e);
- e.addAttribute("type", null);
+ e.addAttribute(TYPE, null);
}
}
- if ("true".equalsIgnoreCase(e.attributeValue("inline"))) {
- e.addAttribute("inline", null);
+ if (TRUE.equalsIgnoreCase(e.attributeValue(ATTR_INLINE))) {
+ e.addAttribute(ATTR_INLINE, null);
try {
inline(e);
} catch (DocumentException eee) {
@@ -536,7 +605,7 @@
try {
levelInit = Integer.parseInt(eTitle.getFirst().attributeValue(
- "level"));
+ LEVEL));
} catch (NumberFormatException eee) {
log.error("Can't parse level in: "
+ eTitle.getFirst().asXML(), eee);
@@ -549,13 +618,13 @@
// on rajoute les refid
for (int i = 0; i < eTitle.size(); i++) {
idMax++;
- eTitle.get(i).addAttribute("refid", "id" + idMax);
+ eTitle.get(i).addAttribute(ATTR_REFID, ID + idMax);
}
// on enleve les titres limites par depth
for (Element el : eTitle) {
- int level = Integer.parseInt(el.attributeValue("level"));
+ int level = Integer.parseInt(el.attributeValue(LEVEL));
level = level - levelInit;
- el.addAttribute("level", "" + level);
+ el.addAttribute(LEVEL, "" + level);
if (depth == -1) {
title.add(el);
}
@@ -565,18 +634,18 @@
}
}
}
- e.addAttribute("class", "contents");
- String titleValue = e.attributeValue("value");
- e.addAttribute("value", null);
+ e.addAttribute(CLASS, CONTENTS);
+ String titleValue = e.attributeValue(VALUE);
+ e.addAttribute(VALUE, null);
String value = titleValue.trim().toLowerCase();
// sans titre c "contents" par default
if (value.matches("\\s*")) {
- value = "contents";
+ value = CONTENTS;
titleValue = "Contents";
}
- e.addAttribute("id", value);
- e.addAttribute("name", value);
- result.addElement("title").setText(titleValue);
+ e.addAttribute(ATTR_IDS, value);
+ e.addAttribute(NAMES, value);
+ result.addElement(TITLE).setText(titleValue);
// on compose les lignes
if (!noTitle) { //Si il y a des titres à lier à la table des matières
result.add(composeLineContent(title, ""));
@@ -593,14 +662,14 @@
private Element composeLineContent(LinkedList<Element> title, String num) {
Element result = DocumentHelper.createElement(BULLET_LIST);
if (sectnum) {
- result.addAttribute("class", "auto-toc");
+ result.addAttribute(CLASS, "auto-toc");
}
Element item = null;
int cnt = 0;
while (!title.isEmpty()) {
Element e = title.getFirst();
- int level = Integer.parseInt(e.attributeValue("level"));
+ int level = Integer.parseInt(e.attributeValue(LEVEL));
LinkedList<Element> child = new LinkedList<Element>();
if (level <= 0) {
@@ -610,20 +679,20 @@
Element para = item.addElement(PARAGRAPH);
Element reference = para.addElement(REFERENCE);
String text = e.getText();
- String id = e.attributeValue("refid");
- reference.addAttribute("id", id);
- reference.addAttribute("refid", text.replaceAll("\\W+", " ")
+ String id = e.attributeValue(ATTR_REFID);
+ reference.addAttribute(ATTR_IDS, id);
+ reference.addAttribute(ATTR_REFID, text.replaceAll("\\W+", " ")
.trim().toLowerCase().replaceAll("\\W+", "-"));
// si l'on doit les numeroter
if (sectnum) {
- Element generated = reference.addElement("generated")
- .addAttribute("class", "sectnum");
+ Element generated = reference.addElement(GENERATED)
+ .addAttribute(CLASS, SECTNUM);
generated.setText(num + cnt + " ");
for (int i = 0; i < eTitle.size(); i++) {
- if (eTitle.get(i).attributeValue("refid").equals(id)) {
+ if (eTitle.get(i).attributeValue(ATTR_REFID).equals(id)) {
Element generatedTitle = eTitle.get(i).addElement(
- "generated");
- generatedTitle.addAttribute("class", "sectnum");
+ GENERATED);
+ generatedTitle.addAttribute(CLASS, SECTNUM);
generatedTitle.setText(num + cnt + " ");
}
@@ -633,12 +702,12 @@
} else {
do {
- e.addAttribute("level", "" + (level - 1));
+ e.addAttribute(LEVEL, "" + (level - 1));
child.add(e);
title.removeFirst();
if (!title.isEmpty()) {
e = title.getFirst();
- level = Integer.parseInt(e.attributeValue("level"));
+ level = Integer.parseInt(e.attributeValue(LEVEL));
}
} while (!title.isEmpty() && level > 0);
String numTmp = "";
@@ -665,7 +734,7 @@
*/
private Element composeDocument(JRSTLexer lexer) throws Exception {
Element result = DocumentHelper.createElement(DOCUMENT);
- result.addAttribute("level", String.valueOf(MAX_SECTION_DEPTH - 1));
+ result.addAttribute(LEVEL, String.valueOf(MAX_SECTION_DEPTH - 1));
Element item = null;
@@ -684,7 +753,7 @@
if (itemEquals(HEADER, item)) {
Element decoration = result.addElement(DECORATION);
Element header = decoration.addElement(HEADER);
- header.addAttribute("inline", "true").setText(item.getText());
+ header.addAttribute(ATTR_INLINE, TRUE).setText(item.getText());
}
// le footer
@@ -692,7 +761,7 @@
if (itemEquals(FOOTER, item)) {
footer = DocumentHelper.createElement(DECORATION);
Element header = footer.addElement(FOOTER);
- header.addAttribute("inline", "true").setText(item.getText());
+ header.addAttribute(ATTR_INLINE, TRUE).setText(item.getText());
}
// les hyperlinks
@@ -700,11 +769,12 @@
if (listItem != null) {
for (Element e : listItem) {
Element anonym = DocumentHelper.createElement(TARGET);
- anonym.addAttribute("anonymous", "1");
+ anonym.addAttribute(ANONYMOUS, "1");
idMax++;
- anonym.addAttribute("id", "id" + idMax);
- anonym.addAttribute("refuri", e.attributeValue("refuri")
- .trim());
+ anonym.addAttribute(ATTR_IDS, ID + idMax);
+
+ anonym.addAttribute(REFURI, e.attributeValue(REFURI).trim());
+
eTargetAnonymous.add(anonym);
eTargetAnonymousCopy.add(anonym);
}
@@ -712,7 +782,7 @@
// les eléments a enlever (deja parser : header, footer...)
item = lexer.peekRemove();
- if (itemEquals("remove", item)) {
+ if (itemEquals(REMOVE, item)) {
lexer.remove();
}
@@ -728,12 +798,12 @@
lexer.remove();
Element title = result.addElement(TITLE);
String txt = item.getText();
- result.addAttribute("id", txt.replaceAll("[(\\W+)_]", " ")
+ result.addAttribute(ATTR_IDS, txt.replaceAll("[(\\W+)_]", " ")
.toLowerCase().trim().replaceAll("\\s+", "-"));
- result.addAttribute("name", txt.toLowerCase().replaceAll(
+ result.addAttribute(NAMES, txt.toLowerCase().replaceAll(
"[(\\W+)_&&[^\\:]]+", " ").trim());
copyLevel(item, title);
- title.addAttribute("inline", "true").setText(txt.trim());
+ title.addAttribute(ATTR_INLINE, TRUE).setText(txt.trim());
}
// skip blank line
@@ -745,13 +815,13 @@
lexer.remove();
Element subtitle = result.addElement(SUBTITLE);
String txt = item.getText();
- subtitle.addAttribute("id", txt.replaceAll("[(\\W+)_]", " ")
+ subtitle.addAttribute(ATTR_IDS, txt.replaceAll("[(\\W+)_]", " ")
.toLowerCase().trim().replaceAll("\\s+", "-"));
- subtitle.addAttribute("name", txt.toLowerCase().replaceAll(
+ subtitle.addAttribute(NAMES, txt.toLowerCase().replaceAll(
"[(\\W+)_]", " ").trim());
copyLevel(item, subtitle);
- DocumentHelper.createElement("footnotes");
- subtitle.addAttribute("inline", "true").setText(txt.trim());
+ DocumentHelper.createElement(FOOTNOTES);
+ subtitle.addAttribute(ATTR_INLINE, TRUE).setText(txt.trim());
}
// skip blank line
@@ -770,56 +840,56 @@
Element field = composeFieldItemList(lexer);
documentinfo.add(field);
} else {
- if ("author".equalsIgnoreCase(item.attributeValue("type"))) {
- documentinfo.addElement(AUTHOR).addAttribute("inline",
- "true").setText(item.getText());
- } else if ("date".equalsIgnoreCase(item.attributeValue("type"))) {
+ if ("author".equalsIgnoreCase(item.attributeValue(TYPE))) {
+ documentinfo.addElement(AUTHOR).addAttribute(ATTR_INLINE,
+ TRUE).setText(item.getText());
+ } else if ("date".equalsIgnoreCase(item.attributeValue(TYPE))) {
documentinfo.addElement(DATE)
- .addAttribute("inline", "true").setText(
+ .addAttribute(ATTR_INLINE, TRUE).setText(
item.getText().trim());
} else if ("organization".equalsIgnoreCase(item
- .attributeValue("type"))) {
+ .attributeValue(TYPE))) {
documentinfo.addElement(ORGANIZATION).addAttribute(
- "inline", "true").setText(item.getText().trim());
+ ATTR_INLINE, TRUE).setText(item.getText().trim());
} else if ("contact".equalsIgnoreCase(item
- .attributeValue("type"))) {
- documentinfo.addElement(CONTACT).addAttribute("inline",
- "true").setText(item.getText().trim());
+ .attributeValue(TYPE))) {
+ documentinfo.addElement(CONTACT).addAttribute(ATTR_INLINE,
+ TRUE).setText(item.getText().trim());
} else if ("address".equalsIgnoreCase(item
- .attributeValue("type"))) {
- documentinfo.addElement(ADDRESS).addAttribute("inline",
- "true").setText(item.getText().trim());
+ .attributeValue(TYPE))) {
+ documentinfo.addElement(ADDRESS).addAttribute(ATTR_INLINE,
+ TRUE).setText(item.getText().trim());
} else if ("version".equalsIgnoreCase(item
- .attributeValue("type"))) {
- documentinfo.addElement(VERSION).addAttribute("inline",
- "true").setText(item.getText().trim());
+ .attributeValue(TYPE))) {
+ documentinfo.addElement(VERSION).addAttribute(ATTR_INLINE,
+ TRUE).setText(item.getText().trim());
} else if ("revision".equalsIgnoreCase(item
- .attributeValue("type"))) {
- documentinfo.addElement(REVISION).addAttribute("inline",
- "true").setText(item.getText().trim());
+ .attributeValue(TYPE))) {
+ documentinfo.addElement(REVISION).addAttribute(ATTR_INLINE,
+ TRUE).setText(item.getText().trim());
} else if ("status".equalsIgnoreCase(item
- .attributeValue("type"))) {
- documentinfo.addElement(STATUS).addAttribute("inline",
- "true").setText(item.getText().trim());
+ .attributeValue(TYPE))) {
+ documentinfo.addElement(STATUS).addAttribute(ATTR_INLINE,
+ TRUE).setText(item.getText().trim());
} else if ("copyright".equalsIgnoreCase(item
- .attributeValue("type"))) {
- documentinfo.addElement(COPYRIGHT).addAttribute("inline",
- "true").setText(item.getText().trim());
+ .attributeValue(TYPE))) {
+ documentinfo.addElement(COPYRIGHT).addAttribute(ATTR_INLINE,
+ TRUE).setText(item.getText().trim());
} else if ("authors".equalsIgnoreCase(item
- .attributeValue("type"))) {
+ .attributeValue(TYPE))) {
Element authors = documentinfo.addElement(AUTHORS);
int t = 0;
String line = item.getText();
for (int i = 0; i < line.length(); i++) {
if (line.charAt(i) == ';' || line.charAt(i) == ',') {
- authors.addElement(AUTHOR).addAttribute("inline",
- "true")
+ authors.addElement(AUTHOR).addAttribute(ATTR_INLINE,
+ TRUE)
.setText(line.substring(t, i).trim());
t = i + 1;
}
}
- authors.addElement(AUTHOR).addAttribute("inline", "true")
+ authors.addElement(AUTHOR).addAttribute(ATTR_INLINE, TRUE)
.setText(line.substring(t, line.length()).trim());
}
lexer.remove();
@@ -903,9 +973,9 @@
if (itemEquals(JRSTLexer.BLANK_LINE, item)) {
// go to the next element
lexer.remove();
- } else if (itemEquals("remove", item)) {
+ } else if (itemEquals(REMOVE, item)) {
lexer.remove();
- } else if (itemEquals("include", item)) {
+ } else if (itemEquals(INCLUDE, item)) {
lexer.remove();
Element list = composeInclude(item);
parent.add(list);
@@ -933,7 +1003,7 @@
lexer.remove();
Element para = parent.addElement(PARAGRAPH);
copyLevel(item, para);
- para.addAttribute("inline", "true").setText(item.getText());
+ para.addAttribute(ATTR_INLINE, TRUE).setText(item.getText());
} else if (itemEquals(JRSTLexer.DIRECTIVE, item)) {
lexer.remove();
Node directive = composeDirective(item);
@@ -985,12 +1055,12 @@
parent.add(list);
} catch (IllegalAddException e) {}
} else
- System.err.println("Unknown target name : \"" + item.attributeValue("id") + "\"");
- } else if (itemEquals("targetAnonymous", item)) {
+ System.err.println("Unknown target name : \"" + item.attributeValue(ATTR_IDS) + "\"");
+ } else if (itemEquals(TARGETANONYMOUS, item)) {
lexer.remove();
Element list = composeTargetAnonymous(item);
parent.add(list);
- } else if (itemEquals("footnotes", item)) {
+ } else if (itemEquals(FOOTNOTES, item)) {
lexer.remove();
Element[] list = composeFootnote(item);
for (Element l : list) {
@@ -1043,10 +1113,10 @@
* @throws Exception
*/
private Element composeInclude(Element item) throws Exception {
- String option = item.attributeValue("option");
+ String option = item.attributeValue(OPTION);
String path = item.getText();
Element result = null;
- if (option.equals("literal")) {
+ if (option.equals(LITERAL)) {
result = DocumentHelper.createElement(LITERAL_BLOCK);
FileReader reader = new FileReader(path);
BufferedReader bf = new BufferedReader(reader);
@@ -1108,7 +1178,7 @@
private Element composeTarget(Element item) {
Element result = null;
for (Element e : eTarget) {
- if (e.attributeValue("id").equals(item.attributeValue("id"))) {
+ if (e.attributeValue(ID).equals(item.attributeValue(ID))) {
result = e;
}
}
@@ -1126,7 +1196,7 @@
*/
private Element[] composeFootnote(Element item) throws Exception {
Element[] result = null;
- if (itemEquals("footnotes", item)) {
+ if (itemEquals(FOOTNOTES, item)) {
List<Element> footnotes = (List<Element>) item
.selectNodes(FOOTNOTE);
result = new Element[footnotes.size()];
@@ -1152,25 +1222,25 @@
String name = null;
String id = "";
String label = null;
- String type = footnote.attributeValue("type");
- if (type.equals("autoNum") || type.equals("autoNumLabel")) {
- result[cnt].addAttribute("auto", "1");
+ String type = footnote.attributeValue(TYPE);
+ if (type.equals(AUTONUM) || type.equals(AUTONUMLABEL)) {
+ result[cnt].addAttribute(AUTO, "1");
}
- if (type.equals("autoSymbol")) {
- result[cnt].addAttribute("auto", "*");
+ if (type.equals(AUTOSYMBOL)) {
+ result[cnt].addAttribute(AUTO, "*");
}
- result[cnt].addAttribute("backrefs", "id" + idMax);
- efootnote.addAttribute("backrefs", "id" + idMax);
- if (type.equals("num") || type.equals("autoNumLabel")) {
- name = footnote.attributeValue("name");
- if (type.equals("autoNumLabel")) {
+ result[cnt].addAttribute(BACKREFS, ID + idMax);
+ efootnote.addAttribute(BACKREFS, ID + idMax);
+ if (type.equals(NUM) || type.equals(AUTONUMLABEL)) {
+ name = footnote.attributeValue(NAME);
+ if (type.equals(AUTONUMLABEL)) {
id = name;
}
else {
label = name;
}
}
- if (type.equals("autoNum") || type.equals("autoNumLabel")) {
+ if (type.equals(AUTONUM) || type.equals(AUTONUMLABEL)) {
boolean done = false;
for (int i = 0; i < labels.length && !done; i++) {
@@ -1182,11 +1252,11 @@
if (!done) {
label = "" + (labels.length + 1);
}
- if (type.equals("autoNum")) {
+ if (type.equals(AUTONUM)) {
name = label;
}
}
- if (type.equals("autoSymbol")) {
+ if (type.equals(AUTOSYMBOL)) {
int nb = Math.abs(symbolMax / 10) + 1;
char symbol = FOOTNOTE_SYMBOL.charAt(symbolMax % 10);
@@ -1197,18 +1267,18 @@
symbolMax++;
}
- result[cnt].addAttribute("id", "" + id);
- efootnote.addAttribute("id", "" + id);
- if (!type.equals("autoSymbol")) {
- result[cnt].addAttribute("name", "" + name);
- efootnote.addAttribute("name", "" + name);
+ result[cnt].addAttribute(ATTR_IDS, "" + id);
+ efootnote.addAttribute(ATTR_IDS, "" + id);
+ if (!type.equals(AUTOSYMBOL)) {
+ result[cnt].addAttribute(NAME, "" + name);
+ efootnote.addAttribute(NAME, "" + name);
}
- result[cnt].addElement("label").setText("" + label);
- efootnote.addAttribute("label", "" + label);
- if (!type.equals("autoSymbol")) {
+ result[cnt].addElement(LABEL).setText("" + label);
+ efootnote.addAttribute(LABEL, "" + label);
+ if (!type.equals(AUTOSYMBOL)) {
lblFootnotes.add(Integer.parseInt(label));
}
- efootnote.addAttribute("type", type);
+ efootnote.addAttribute(TYPE, type);
eFootnotes.add(efootnote);
String text = footnote.getText();
Document doc = newJRSTReader(new StringReader(text));
@@ -1218,10 +1288,10 @@
}
}
for (int i = 0; i < result.length; i++) {
- if (result[i].attributeValue("id").equals("")) {
+ if (result[i].attributeValue(ATTR_IDS).equals("")) {
idMax++;
- result[i].addAttribute("id", "id" + idMax);
- (eFootnotes.get(i)).addAttribute("id", "id" + idMax);
+ result[i].addAttribute(ATTR_IDS, ID + idMax);
+ (eFootnotes.get(i)).addAttribute(ATTR_IDS, ID + idMax);
}
}
@@ -1248,14 +1318,14 @@
lexer.remove();
Element optionListItem = result.addElement(OPTION_LIST_ITEM);
Element optionGroup = optionListItem.addElement(OPTION_GROUP);
- List<Element> option = (List<Element>) item.selectNodes("option");
+ List<Element> option = (List<Element>) item.selectNodes(OPTION);
for (Element e : option) {
Element eOption = optionGroup.addElement(OPTION);
eOption.addElement(OPTION_STRING).setText(
e.attributeValue(OPTION_STRING));
- if (e.attributeValue("delimiterExiste").equals("true")) {
+ if (e.attributeValue(DELIMITEREXISTE).equals(TRUE)) {
eOption.addElement(OPTION_ARGUMENT).addAttribute(
- "delimiter", e.attributeValue("delimiter"))
+ DELIMITER, e.attributeValue(DELIMITER))
.setText(e.attributeValue(OPTION_ARGUMENT));
}
}
@@ -1286,7 +1356,7 @@
private Element composeTopic(Element item) throws Exception {
Element result = null;
result = DocumentHelper.createElement(TOPIC);
- result.addElement(TITLE).addAttribute("inline", "true").setText(
+ result.addElement(TITLE).addAttribute(ATTR_INLINE, TRUE).setText(
item.attributeValue(TITLE));
String text = item.getText();
Document doc = newJRSTReader(new StringReader(text));
@@ -1311,10 +1381,10 @@
private Element composeSidebar(Element item) throws Exception {
Element result = null;
result = DocumentHelper.createElement(SIDEBAR);
- result.addElement(TITLE).addAttribute("inline", "true").setText(
+ result.addElement(TITLE).addAttribute(ATTR_INLINE, TRUE).setText(
item.attributeValue(TITLE));
- if (item.attributeValue("subExiste").equals("true")) {
- result.addElement(SUBTITLE).addAttribute("inline", "true").setText(
+ if (item.attributeValue(SUBEXISTE).equals(TRUE)) {
+ result.addElement(SUBTITLE).addAttribute(ATTR_INLINE, TRUE).setText(
item.attributeValue(SUBTITLE));
}
@@ -1345,7 +1415,7 @@
int[] levels = new int[lines.size()];
int cnt = 0;
for (Element l : lines) {
- levels[cnt] = Integer.parseInt(l.attributeValue("level"));
+ levels[cnt] = Integer.parseInt(l.attributeValue(LEVEL));
cnt++;
}
cnt = 0;
@@ -1355,7 +1425,7 @@
}
for (Element l : lines) {
if (levels[cnt] == 0) {
- result.addElement(LINE).addAttribute("inline", "true").setText(
+ result.addElement(LINE).addAttribute(ATTR_INLINE, TRUE).setText(
l.getText());
}
else {
@@ -1364,8 +1434,8 @@
Boolean done = false;
for (int i = cnt; i < lines.size() && !done; i++) {
if (levels[i] > 0) {
- Element eLine = newItem.addElement("line");
- eLine.addAttribute("level", "" + (levels[i] - 1));
+ Element eLine = newItem.addElement(LINE);
+ eLine.addAttribute(LEVEL, "" + (levels[i] - 1));
eLine.setText(lines.get(i).getText());
lineDone[i] = true;
} else {
@@ -1422,7 +1492,7 @@
if (sAttribution != null) {
Element attribution = result.addElement(ATTRIBUTION);
attribution.setText(sAttribution);
- attribution.addAttribute("inline", "true");
+ attribution.addAttribute(ATTR_INLINE, TRUE);
}
return result;
}
@@ -1441,7 +1511,7 @@
*/
private Element composeAdmonition(Element item) throws Exception {
Element result = null;
- if (item.attributeValue("type").equalsIgnoreCase(ADMONITION)) {
+ if (item.attributeValue(TYPE).equalsIgnoreCase(ADMONITION)) {
result = DocumentHelper.createElement(ADMONITION);
String title = item.attributeValue(TITLE);
String admonitionClass = "admonition_" + title;
@@ -1449,11 +1519,11 @@
"\\p{Punct}", "");
admonitionClass = admonitionClass.replace(' ', '-');
admonitionClass = admonitionClass.replace('\n', '-');
- result.addAttribute("class", admonitionClass);
- result.addElement(TITLE).addAttribute("inline", "true").setText(
+ result.addAttribute(CLASS, admonitionClass);
+ result.addElement(TITLE).addAttribute(ATTR_INLINE, TRUE).setText(
title.trim());
} else {
- result = DocumentHelper.createElement(item.attributeValue("type")
+ result = DocumentHelper.createElement(item.attributeValue(TYPE)
.toLowerCase());
}
@@ -1472,7 +1542,7 @@
private Node composeDirective(Element item) {
Node result = item;
String type = item.attributeValue(JRSTLexer.DIRECTIVE_TYPE);
- if (type.equals("sectnum")) {
+ if (type.equals(SECTNUM)) {
sectnum = true;
}
JRSTDirective directive = getDirective(type);
@@ -1579,7 +1649,7 @@
}
Element rowList = null;
- if ("true".equals(item.attributeValue(JRSTLexer.TABLE_HEADER))) {
+ if (TRUE.equals(item.attributeValue(JRSTLexer.TABLE_HEADER))) {
rowList = tgroup.addElement(THEAD);
} else {
rowList = tgroup.addElement(TBODY);
@@ -1593,7 +1663,7 @@
Element cell = cells.get(c);
// si la cellule a ete utilise pour un regroupement vertical on
// la passe
- if (!"true".equals(cell.attributeValue("used"))) {
+ if (!TRUE.equals(cell.attributeValue("used"))) {
Element entry = row.addElement(ENTRY);
String text = "";
@@ -1611,8 +1681,8 @@
+ "=" + cellStart + "]");
text += tmpCell.getText();
// on marque la cellule comme utilise
- tmpCell.addAttribute("used", "true");
- } while (!"true".equals(tmpCell
+ tmpCell.addAttribute("used", TRUE);
+ } while (!TRUE.equals(tmpCell
.attributeValue(JRSTLexer.CELL_END)));
if (morerows > 0) {
@@ -1644,7 +1714,7 @@
entry.appendContent(doc.getRootElement());
}
}
- if ("true".equals(rows.get(r).attributeValue(
+ if (TRUE.equals(rows.get(r).attributeValue(
JRSTLexer.ROW_END_HEADER))) {
rowList = tgroup.addElement(TBODY);
}
@@ -1674,13 +1744,13 @@
Element item = lexer.peekBulletList();
Element result = DocumentHelper.createElement(BULLET_LIST);
copyLevel(item, result);
- result.addAttribute("bullet", item.attributeValue("bullet"));
+ result.addAttribute(BULLET, item.attributeValue(BULLET));
while (itemEquals(BULLET_LIST, item) && isSameLevel(item, result)
- && hasSameAttribute(item, result, "bullet")) {
+ && hasSameAttribute(item, result, BULLET)) {
lexer.remove();
Element bullet = result.addElement(LIST_ITEM);
copyLevel(item, bullet);
- bullet.addElement(PARAGRAPH).addAttribute("inline", "true")
+ bullet.addElement(PARAGRAPH).addAttribute(ATTR_INLINE, TRUE)
.setText(item.getText());
composeBody(lexer, bullet);
@@ -1706,22 +1776,22 @@
Element item = lexer.peekEnumeratedList();
Element result = DocumentHelper.createElement(ENUMERATED_LIST);
copyLevel(item, result);
- String enumType = item.attributeValue("enumtype");
+ String enumType = item.attributeValue(ENUMTYPE);
if (!enumType.equals("arabic")) {
- result.addAttribute("start", item.attributeValue("start"));
+ result.addAttribute(START, item.attributeValue(START));
}
- result.addAttribute("prefix", item.attributeValue("prefix"));
- result.addAttribute("suffix", item.attributeValue("suffix"));
- result.addAttribute("enumtype", enumType);
+ result.addAttribute(PREFIX, item.attributeValue(PREFIX));
+ result.addAttribute(SUFFIX, item.attributeValue(SUFFIX));
+ result.addAttribute(ENUMTYPE, enumType);
while (itemEquals(ENUMERATED_LIST, item)
&& isSameLevel(item, result)
- && hasSameAttribute(item, result, "prefix", "suffix")
- && ("auto".equals(item.attributeValue("enumtype")) || hasSameAttribute(
- item, result, "enumtype"))) {
+ && hasSameAttribute(item, result, PREFIX, SUFFIX)
+ && (AUTO.equals(item.attributeValue(ENUMTYPE)) || hasSameAttribute(
+ item, result, ENUMTYPE))) {
lexer.remove();
Element e = result.addElement(LIST_ITEM);
copyLevel(item, e);
- e.addElement(PARAGRAPH).addAttribute("inline", "true").setText(
+ e.addElement(PARAGRAPH).addAttribute(ATTR_INLINE, TRUE).setText(
item.getText());
composeBody(lexer, e);
@@ -1751,7 +1821,7 @@
Element term = def.addElement(TERM);
copyLevel(item, term);
- term.addAttribute("inline", "true").setText(
+ term.addAttribute(ATTR_INLINE, TRUE).setText(
item.attributeValue("term"));
String[] classifiers = StringUtil.split(item
@@ -1759,12 +1829,12 @@
for (String classifierText : classifiers) {
Element classifier = def.addElement("classifier");
copyLevel(item, classifier);
- classifier.addAttribute("inline", "true").setText(
+ classifier.addAttribute(ATTR_INLINE, TRUE).setText(
classifierText);
}
Element definition = def.addElement(DEFINITION);
- definition.addElement(PARAGRAPH).addAttribute("inline", "true")
+ definition.addElement(PARAGRAPH).addAttribute(ATTR_INLINE, TRUE)
.setText(item.getText());
copyLevel(item, definition);
@@ -1819,10 +1889,10 @@
copyLevel(item, field);
Element fieldName = field.addElement(FIELD_NAME);
copyLevel(item, fieldName);
- fieldName.addAttribute("inline", "true").setText(
- item.attributeValue("name"));
+ fieldName.addAttribute(ATTR_INLINE, TRUE).setText(
+ item.attributeValue(NAME));
Element fieldBody = field.addElement(FIELD_BODY);
- fieldBody.addElement(PARAGRAPH).addAttribute("inline", "true")
+ fieldBody.addElement(PARAGRAPH).addAttribute(ATTR_INLINE, TRUE)
.setText(item.getText());
copyLevel(item, fieldBody);
composeBody(lexer, fieldBody);
@@ -1858,10 +1928,10 @@
Element title = result.addElement(TITLE);
copyLevel(item, result);
copyLevel(item, title);
- title.addAttribute("inline", "true").setText(item.getText().trim());
- result.addAttribute("id", item.getText().replaceAll("\\W+", " ")
+ title.addAttribute(ATTR_INLINE, TRUE).setText(item.getText().trim());
+ result.addAttribute(ID, item.getText().replaceAll("\\W+", " ")
.trim().toLowerCase().replaceAll("\\W+", "-"));
- result.addAttribute("name", item.getText().toLowerCase().trim());
+ result.addAttribute(NAME, item.getText().toLowerCase().trim());
eTitle.add(title);
}
@@ -1901,8 +1971,8 @@
// return true;
// }
int subSectionLevel = Integer.parseInt(subSection
- .attributeValue("level"));
- int sectionLevel = Integer.parseInt(section.attributeValue("level"));
+ .attributeValue(LEVEL));
+ int sectionLevel = Integer.parseInt(section.attributeValue(LEVEL));
boolean result = subSectionLevel > sectionLevel;
return result;
}
@@ -1922,8 +1992,8 @@
// return false;
// }
int subSectionLevel = Integer.parseInt(subSection
- .attributeValue("level"));
- int sectionLevel = Integer.parseInt(section.attributeValue("level"));
+ .attributeValue(LEVEL));
+ int sectionLevel = Integer.parseInt(section.attributeValue(LEVEL));
boolean result = subSectionLevel == sectionLevel;
return result;
}
@@ -1958,11 +2028,11 @@
* @throws DocumentException
*/
private void copyLevel(Element from, Element to) throws DocumentException {
- String level = from.attributeValue("level");
+ String level = from.attributeValue(LEVEL);
if (level == null) {
throw new DocumentException("Element without level: " + from);
}
- to.addAttribute("level", level);
+ to.addAttribute(LEVEL, level);
}
/**
@@ -2077,7 +2147,7 @@
int end = matcher.end();
String literal = "<" + LITERAL + ">" + matcher.group(1) + "</"
+ LITERAL + ">";
- String key = "literal" + index++;
+ String key = LITERAL + index++;
temporaries.put(key, literal);
text = text.substring(0, start) + "<tmp>" + key + "</tmp>"
+ text.substring(end);
@@ -2092,7 +2162,7 @@
int start = matcher.start();
int end = matcher.end();
Element ref = DocumentHelper.createElement(REFERENCE);
- ref.addAttribute("refuri", StringEscapeUtils.unescapeXml(matcher.group(2)));
+ ref.addAttribute(REFURI, StringEscapeUtils.unescapeXml(matcher.group(2)));
ref.setText(StringEscapeUtils.unescapeXml(matcher.group(1)));
String key = "inlineReference" + index++;
temporaries.put(key, ref.asXML());
@@ -2130,15 +2200,15 @@
label += symbol;
}
symbolMaxRef++;
- footnote.addAttribute("auto", "*");
+ footnote.addAttribute(AUTO, "*");
for (int j = 0; j < eFootnotes.size(); j++) {
Element eFootnote = eFootnotes.get(j);
- if (eFootnote.attributeValue("label").equals(label)) {
+ if (eFootnote.attributeValue(LABEL).equals(label)) {
- footnote.addAttribute("id", eFootnote
- .attributeValue("backrefs"));
- footnote.addAttribute("refid", eFootnote
- .attributeValue("id"));
+ footnote.addAttribute(ATTR_IDS, eFootnote
+ .attributeValue(BACKREFS));
+ footnote.addAttribute(ATTR_REFID, eFootnote
+ .attributeValue(ATTR_IDS));
}
}
@@ -2148,11 +2218,11 @@
for (int j = 0; j < eFootnotes.size(); j++) {
Element eFootnote = eFootnotes.get(j);
- if (eFootnote.attributeValue("label").equals(id)) {
- footnote.addAttribute("id", eFootnote
- .attributeValue("backrefs"));
- footnote.addAttribute("refid", eFootnote
- .attributeValue("id"));
+ if (eFootnote.attributeValue(LABEL).equals(id)) {
+ footnote.addAttribute(ATTR_IDS, eFootnote
+ .attributeValue(BACKREFS));
+ footnote.addAttribute(ATTR_REFID, eFootnote
+ .attributeValue(ATTR_IDS));
}
}
footnote.setText(id);
@@ -2185,17 +2255,17 @@
if (!trouve) {
label = "" + (lbls.length + 1);
}
- footnote.addAttribute("auto", "1");
+ footnote.addAttribute(AUTO, "1");
for (int j = 0; j < eFootnotes.size(); j++) {
Element eFootnote = eFootnotes.get(j);
- if (eFootnote.attributeValue("label").equals(
+ if (eFootnote.attributeValue(LABEL).equals(
label)) {
- if (!(eFootnote.attributeValue("type")
- .equals("autoNumLabel"))) {
- footnote.addAttribute("id", eFootnote
- .attributeValue("backrefs"));
- footnote.addAttribute("refid",
- eFootnote.attributeValue("id"));
+ if (!(eFootnote.attributeValue(TYPE)
+ .equals(AUTONUMLABEL))) {
+ footnote.addAttribute(ATTR_IDS, eFootnote
+ .attributeValue(BACKREFS));
+ footnote.addAttribute(ATTR_REFID,
+ eFootnote.attributeValue(ATTR_IDS));
footnote.setText(label);
lblFootnotesRef.add(Integer
.parseInt(label));
@@ -2211,26 +2281,26 @@
}
else {
- footnote.addAttribute("auto", "1");
+ footnote.addAttribute(AUTO, "1");
String name = id.substring(1);
boolean trouve = false;
for (int j = 0; j < eFootnotes.size() && !trouve; j++) {
Element eFootnote = eFootnotes.get(j);
- if (eFootnote.attributeValue("name").equals(name)) {
- footnote.addAttribute("id", eFootnote
- .attributeValue("backrefs"));
- footnote.addAttribute("refid", eFootnote
- .attributeValue("id"));
+ if (eFootnote.attributeValue(NAMES).equals(name)) {
+ footnote.addAttribute(ATTR_IDS, eFootnote
+ .attributeValue(BACKREFS));
+ footnote.addAttribute(ATTR_REFID, eFootnote
+ .attributeValue(ATTR_IDS));
String label = eFootnote
- .attributeValue("label");
+ .attributeValue(LABEL);
footnote.setText(label);
lblFootnotesRef.add(Integer.parseInt(label));
trouve = true;
}
}
- footnote.addAttribute("name", name);
+ footnote.addAttribute(NAMES, name);
}
done = true;
}
@@ -2245,13 +2315,13 @@
String txtFin = text.substring(matcher.end(), text.length());
String ref = text.substring(matcher.start(), matcher.end() - 2);
ref = ref.replaceAll("`", "");
- Element anonym = DocumentHelper.createElement("reference");
- anonym.addAttribute("anonymous", "1");
- anonym.addAttribute("name", ref.trim());
+ Element anonym = DocumentHelper.createElement(REFERENCE);
+ anonym.addAttribute(ANONYMOUS, "1");
+ anonym.addAttribute(NAME, ref.trim());
if (!eTargetAnonymous.isEmpty()) {
Element target = eTargetAnonymous.getFirst();
eTargetAnonymous.removeFirst();
- anonym.addAttribute("refuri", target.attributeValue("refuri"));
+ anonym.addAttribute(REFURI, target.attributeValue(REFURI));
}
anonym.setText(ref);
text = txtDebut + anonym.asXML() + txtFin;
@@ -2266,19 +2336,19 @@
ref = StringEscapeUtils.unescapeXml(ref);
ref = ref.replaceAll("('|_)", "");
ref = ref.replaceAll("`", "");
- Element hyper = DocumentHelper.createElement("reference");
- hyper.addAttribute("name", ref);
+ Element hyper = DocumentHelper.createElement(REFERENCE);
+ hyper.addAttribute(NAME, ref);
boolean trouve = false;
for (int i = 0; i < eTarget.size() && !trouve; i++) {
Element el = eTarget.get(i);
String refTmp = URLEncoder.encode(ref.replaceAll("\\s", "-").toLowerCase(), "UTF-8");
- if (el.attributeValue("id").equalsIgnoreCase((refTmp))) {
- hyper.addAttribute("refuri", el.attributeValue("refuri"));
+ if (el.attributeValue(ID).equalsIgnoreCase((refTmp))) {
+ hyper.addAttribute(REFURI, el.attributeValue(REFURI));
trouve = true;
}
}
if (!trouve) {
- hyper.addAttribute("refid", ref);
+ hyper.addAttribute(ATTR_REFID, ref);
}
hyper.setText(ref);
text = txtDebut + hyper.asXML() + " " + txtFin;
1
0
17 May '11
Author: kcardineaud
Date: 2011-05-17 16:34:48 +0200 (Tue, 17 May 2011)
New Revision: 582
Url: http://nuiton.org/repositories/revision/jrst/582
Log:
Modification de ThreadRedirection.java pour l'utiliser avec des sorties de type HTML
Modified:
trunk/jrst/src/test/java/org/nuiton/jrst/ThreadRedirection.java
Modified: trunk/jrst/src/test/java/org/nuiton/jrst/ThreadRedirection.java
===================================================================
--- trunk/jrst/src/test/java/org/nuiton/jrst/ThreadRedirection.java 2011-05-17 14:17:34 UTC (rev 581)
+++ trunk/jrst/src/test/java/org/nuiton/jrst/ThreadRedirection.java 2011-05-17 14:34:48 UTC (rev 582)
@@ -29,10 +29,15 @@
import java.io.IOException;
import java.io.InputStreamReader;
+import org.apache.commons.io.IOUtils;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
/**
* Class qui redirige la sortie standard pour la laisser en interne
*/
public class ThreadRedirection extends Thread {
+ private static Log log = LogFactory.getLog(ThreadRedirection.class);
public static final String LINE_SEPARATOR = "\n";
protected StringBuffer str;
protected Process process;
@@ -44,24 +49,38 @@
@Override
public void run() {
+ BufferedReader reader =null;
try {
- BufferedReader reader = new BufferedReader(new InputStreamReader(
- process.getInputStream()));
- try {
+
+ reader = new BufferedReader(new InputStreamReader(
+ process.getInputStream()),8193);
+
String line;
while ((line = reader.readLine()) != null) {
- str.append(line + LINE_SEPARATOR);
+
+ /*Le doctype est modifie pour eviter que sax telecharge la DTD du HTML sur le net, car le traitement prend un certain temps.
+ On doit en revanche spécifier la signification de nbsp.
+ */
+
+ if(!line.equals("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">"))
+ {
+ str.append(line + LINE_SEPARATOR);
+ }
+ else {
+ str.append("<!DOCTYPE xsl:stylesheet [<!ENTITY nbsp \" \">]> " + LINE_SEPARATOR);
+ }
}
- } finally {
- reader.close();
+
}
- } catch (IOException ioe) {
+ catch (IOException ioe) {
ioe.printStackTrace();
- }
+ }
+ finally {
+ IOUtils.closeQuietly(reader);}
}
public String getOutput() {
- return str.toString();
+ return str.toString();
}
}
1
0
17 May '11
Author: kcardineaud
Date: 2011-05-17 16:17:34 +0200 (Tue, 17 May 2011)
New Revision: 581
Url: http://nuiton.org/repositories/revision/jrst/581
Log:
#1534 logs are too verbose
Modified:
trunk/jrst/src/main/java/org/nuiton/jrst/JRSTGenerator.java
Modified: trunk/jrst/src/main/java/org/nuiton/jrst/JRSTGenerator.java
===================================================================
--- trunk/jrst/src/main/java/org/nuiton/jrst/JRSTGenerator.java 2011-05-14 11:44:43 UTC (rev 580)
+++ trunk/jrst/src/main/java/org/nuiton/jrst/JRSTGenerator.java 2011-05-17 14:17:34 UTC (rev 581)
@@ -208,7 +208,7 @@
throws TransformerException, IOException {
if (log.isInfoEnabled()) {
- log.info("Transform document using : " + stylesheet);
+ log.debug("Transform document using : " + stylesheet);
}
// load the transformer using JAXP
1
0
Author: tchemit
Date: 2011-05-14 13:44:43 +0200 (Sat, 14 May 2011)
New Revision: 580
Url: http://nuiton.org/repositories/revision/jrst/580
Log:
Update mavenpom4redmineAndCentral to 2.5.4.
Modified:
trunk/pom.xml
Modified: trunk/pom.xml
===================================================================
--- trunk/pom.xml 2011-05-12 09:55:09 UTC (rev 579)
+++ trunk/pom.xml 2011-05-14 11:44:43 UTC (rev 580)
@@ -33,7 +33,7 @@
<parent>
<groupId>org.nuiton</groupId>
<artifactId>mavenpom4redmineAndCentral</artifactId>
- <version>2.5.3</version>
+ <version>2.5.4</version>
</parent>
<artifactId>jrst</artifactId>
1
0
r579 - in trunk/jrst/src: main/java/org/nuiton/jrst test/java/org/nuiton/jrst
by sletellier@users.nuiton.org 12 May '11
by sletellier@users.nuiton.org 12 May '11
12 May '11
Author: sletellier
Date: 2011-05-12 11:55:09 +0200 (Thu, 12 May 2011)
New Revision: 579
Url: http://nuiton.org/repositories/revision/jrst/579
Log:
- Refactor generate method to allow using it without using files
Modified:
trunk/jrst/src/main/java/org/nuiton/jrst/JRST.java
trunk/jrst/src/test/java/org/nuiton/jrst/JRSTTest.java
Modified: trunk/jrst/src/main/java/org/nuiton/jrst/JRST.java
===================================================================
--- trunk/jrst/src/main/java/org/nuiton/jrst/JRST.java 2011-04-28 10:05:53 UTC (rev 578)
+++ trunk/jrst/src/main/java/org/nuiton/jrst/JRST.java 2011-05-12 09:55:09 UTC (rev 579)
@@ -32,6 +32,7 @@
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
+import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
@@ -51,12 +52,14 @@
import javax.xml.transform.Result;
import javax.xml.transform.Source;
import javax.xml.transform.Transformer;
+import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.URIResolver;
import javax.xml.transform.sax.SAXResult;
import javax.xml.transform.sax.SAXSource;
import javax.xml.transform.stream.StreamSource;
+import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.fop.apps.FOUserAgent;
@@ -64,8 +67,6 @@
import org.apache.fop.apps.FopFactory;
import org.apache.fop.apps.MimeConstants;
import org.dom4j.Document;
-import org.dom4j.io.OutputFormat;
-import org.dom4j.io.XMLWriter;
import org.nuiton.i18n.I18n;
import org.nuiton.i18n.init.ClassPathI18nInitializer;
import org.nuiton.jrst.convertisor.DocUtils2RST;
@@ -93,6 +94,8 @@
*/
public class JRST {
+ public static final String UTF_8 = "UTF-8";
+
public enum Overwrite {
NEVER, IFNEWER, ALLTIME
}
@@ -249,22 +252,7 @@
public static void generate(String xslListOrOutType, File fileIn,
File fileOut, Overwrite overwrite) throws Exception {
- generate(xslListOrOutType, fileIn, "UTF-8", fileOut, "UTF-8", overwrite);
- }
- /**
- *
- * @param xslListOrOutType
- * @param fileIn
- * @param inputEncoding
- * @param fileOut
- * @param outputEncoding
- * @param overwrite
- * @throws Exception
- */
- public static void generate(String xslListOrOutType, File fileIn,
- String inputEncoding, File fileOut, String outputEncoding,
- Overwrite overwrite) throws Exception {
if (fileOut != null
&& fileOut.exists()
&& (overwrite == Overwrite.NEVER || (overwrite == Overwrite.IFNEWER && FileUtil
@@ -274,204 +262,191 @@
log.info("Don't generate file " + fileOut
+ ", because already exists");
} else {
- // search xsl file list to apply
- String xslList = stylesheets.get(xslListOrOutType);
- if (xslListOrOutType == null) {
- xslList = xslListOrOutType;
- }
-
- // parse rst file
URL url = fileIn.toURI().toURL();
- Reader in = new InputStreamReader(url.openStream(), inputEncoding);
- JRSTReader jrst = new JRSTReader();
- Document doc = jrst.read(in);
+ Reader reader = new InputStreamReader(url.openStream(), UTF_8);
+ FileWriter writer = new FileWriter(fileOut);
+ String result = generate(xslListOrOutType, reader);
- // Sortie vers rst
- if (xslListOrOutType.equals(TYPE_RST)){
- // Creation d'un visitor qui convertie de l'xml vers le rst
- DocUtilsVisitor visitor = new DocUtils2RST();
+ fileOut.getAbsoluteFile().getParentFile().mkdirs();
+ // generation PDF
+ if (xslListOrOutType.equals("pdf")) {
+ FopFactory fopFactory = FopFactory.newInstance();
+ // OutputStream outPDF = new BufferedOutputStream(new
+ // FileOutputStream(new File("C:/Temp/myfile.pdf")));
- // Atacher le visitor au document
- // il va parcourir tout les elements et reconstruire du rst
- doc.accept(visitor);
+ OutputStream outPDF = new BufferedOutputStream(new FileOutputStream(
+ fileOut));
- // Recuperation du resultat
- String result = visitor.getResult();
- // nettoyage du visiteur
- visitor.clear();
- // Ecriture du resultat dans un fichier
- // prepare the output flux
- FileWriter out = null;
- if (fileOut != null) {
- try {
- fileOut.getAbsoluteFile().getParentFile().mkdirs();
- out = new FileWriter(fileOut);
- // write generated document
- out.write(result);
- } finally {
- out.close();
- }
- } else {
- // Si aucun fichier de sortie nest definie, on utilise la sortie standard
- System.out.println(result);
- }
- }
- else {
- // apply xsl on rst xml document
- JRSTGenerator gen = new JRSTGenerator();
- String[] xsls = StringUtil.split(xslList, ",");
- for (String xsl : xsls) {
- URL stylesheet = null;
- File file = new File(xsl);
- if (file.exists()) {
- stylesheet = file.toURI().toURL();
- } else {
- //stylesheet = JRST.class.getResource(xsl);
- stylesheet = Resource.getURL(xsl);
- }
- if (stylesheet == null) {
- throw new FileNotFoundException("Can't find stylesheet: "
- + xsl);
- }
+ FOUserAgent userAgent = fopFactory.newFOUserAgent();
- final String finalXsl = xsl;
+ // Step 3: Construct fop with desired output format
+ Fop fop = fopFactory.newFop(MimeConstants.MIME_PDF,
+ userAgent, outPDF);
- // add entity resolver
- gen.setUriResolver(new URIResolver() {
- public Source resolve(String href, String base) {
- if (log.isDebugEnabled()) {
- log.debug("RESOLVING: href: "+href+" base: "+base);
- }
- String xslDir = finalXsl.substring(0, finalXsl.lastIndexOf('/') + 1);
- String resouceFullName = xslDir + href;
-
- if (log.isDebugEnabled()) {
- log.debug("RESOLVING: resouceFullName: "+resouceFullName);
- }
+ // Step 4: Setup JAXP using identity transformer
+ TransformerFactory factory = TransformerFactory
+ .newInstance();
+ Transformer transformer = factory.newTransformer(); // identity
+ // transformer
- try {
- InputStream stream = null;
- File file = new File(resouceFullName);
- if (file.exists()) {
- stream = new FileInputStream(file);
- } else {
- try {
- stream = Resource.getURL(resouceFullName).openStream();
- }
- catch (Exception e) {
- stream = Resource.getURL("/docbook/common/" + href).openStream();
- }
- }
+ // Step 5: Setup input and output for XSLT transformation
+ // Setup input stream
+ Source src = new StreamSource(new StringReader(result));
- SAXParserFactory parserFactory = SAXParserFactory.newInstance();
- SAXParser saxParser = parserFactory.newSAXParser();
- XMLReader xmlReader = saxParser.getXMLReader();
- xmlReader.setEntityResolver(new EntityResolver() {
- @Override
- public InputSource resolveEntity(String publicId, String systemId)
- throws SAXException, IOException {
+ // Resulting SAX events (the generated FO) must be piped
+ // through to FOP
+ Result res = new SAXResult(fop.getDefaultHandler());
- InputSource source = null;
+ // Step 6: Start XSLT transformation and FOP processing
+ transformer.transform(src, res);
- String smallSystemId = systemId.substring(systemId.lastIndexOf("/") + 1);
- URL url = Resource.getURL("/docbook/common/" + smallSystemId);
- if (url != null) {
- if (log.isDebugEnabled()) {
- log.debug("Resolved entity url : " + url);
- }
- InputStream stream = url.openStream();
- source = new InputSource(stream);
- }
+ outPDF.close();
+ } else {
+ // write generated document
+ writer.write(result);
- return source;
- }
- });
- InputSource inSrc = new InputSource(stream);
- SAXSource saxs = new SAXSource(xmlReader, inSrc);
- return saxs;
- } catch (IOException e) {
- e.printStackTrace();
- return null;
- } catch (ParserConfigurationException e) {
- e.printStackTrace();
- return null;
- } catch (SAXException e) {
- e.printStackTrace();
- return null;
- }
- }
- });
+ writer.close();
- doc = gen.transform(doc, stylesheet);
- }
+ }
+ }
+ }
- boolean pdf = false;
- // generation PDF
- if (xslListOrOutType != null) {
- if (xslListOrOutType.equals("pdf")) {
- pdf = true;
- FopFactory fopFactory = FopFactory.newInstance();
- // OutputStream outPDF = new BufferedOutputStream(new
- // FileOutputStream(new File("C:/Temp/myfile.pdf")));
+ /**
+ *
+ * @param xslListOrOutType
+ * @param in
+ * @throws Exception
+ */
+ public static String generate(String xslListOrOutType, Reader in) throws Exception {
- OutputStream outPDF = null;
- if (fileOut != null) {
- fileOut.getAbsoluteFile().getParentFile().mkdirs();
- outPDF = new BufferedOutputStream(new FileOutputStream(
- fileOut));
- } else {
- outPDF = new BufferedOutputStream(System.out);
- }
+ Document doc = generateXMl(in);
- FOUserAgent userAgent = fopFactory.newFOUserAgent();
+ // Sortie vers rst
+ if (xslListOrOutType.equals(TYPE_RST)){
+ return generateRST(doc);
+ } else if (!StringUtils.isEmpty(xslListOrOutType)) {
+ doc = applyXsls(doc, xslListOrOutType);
+ }
+ return doc.asXML();
+ }
- // Step 3: Construct fop with desired output format
- Fop fop = fopFactory.newFop(MimeConstants.MIME_PDF,
- userAgent, outPDF);
+ private static Document applyXsls(Document doc, String xslListOrOutType) throws IOException, FileNotFoundException, TransformerException {
- // Step 4: Setup JAXP using identity transformer
- TransformerFactory factory = TransformerFactory
- .newInstance();
- Transformer transformer = factory.newTransformer(); // identity
- // transformer
+ // search xsl file list to apply
+ String xslList = stylesheets.get(xslListOrOutType);
+ if (xslListOrOutType == null) {
+ xslList = xslListOrOutType;
+ }
- // Step 5: Setup input and output for XSLT transformation
- // Setup input stream
- Source src = new StreamSource(new StringReader(doc.asXML()));
+ // apply xsl on rst xml document
+ JRSTGenerator gen = new JRSTGenerator();
+ String[] xsls = StringUtil.split(xslList, ",");
+ for (String xsl : xsls) {
+ URL stylesheet = null;
+ File file = new File(xsl);
+ if (file.exists()) {
+ stylesheet = file.toURI().toURL();
+ } else {
+ //stylesheet = JRST.class.getResource(xsl);
+ stylesheet = Resource.getURL(xsl);
+ }
+ if (stylesheet == null) {
+ throw new FileNotFoundException("Can't find stylesheet: "
+ + xsl);
+ }
- // Resulting SAX events (the generated FO) must be piped
- // through to FOP
- Result res = new SAXResult(fop.getDefaultHandler());
+ final String finalXsl = xsl;
- // Step 6: Start XSLT transformation and FOP processing
- transformer.transform(src, res);
-
- if (fileOut != null) {
- outPDF.close();
- }
+ // add entity resolver
+ gen.setUriResolver(new URIResolver() {
+ public Source resolve(String href, String base) {
+ if (log.isDebugEnabled()) {
+ log.debug("RESOLVING: href: "+href+" base: "+base);
}
- }
- if (!pdf) {
- // prepare the output flux
- XMLWriter out = null;
- if (fileOut != null) {
- fileOut.getAbsoluteFile().getParentFile().mkdirs();
+ String xslDir = finalXsl.substring(0, finalXsl.lastIndexOf('/') + 1);
+ String resouceFullName = xslDir + href;
- out = new XMLWriter(FileUtil.getWriter(fileOut,
- outputEncoding), new OutputFormat(" ", true,
- outputEncoding));
- } else {
- out = new XMLWriter(System.out, new OutputFormat(" ",
- true, outputEncoding));
+ if (log.isDebugEnabled()) {
+ log.debug("RESOLVING: resouceFullName: "+resouceFullName);
}
- // write generated document
- out.write(doc);
- if (fileOut != null) {
- out.close();
+ try {
+ InputStream stream = null;
+ File file = new File(resouceFullName);
+ if (file.exists()) {
+ stream = new FileInputStream(file);
+ } else {
+ try {
+ stream = Resource.getURL(resouceFullName).openStream();
+ }
+ catch (Exception e) {
+ stream = Resource.getURL("/docbook/common/" + href).openStream();
+ }
+ }
+
+ SAXParserFactory parserFactory = SAXParserFactory.newInstance();
+ SAXParser saxParser = parserFactory.newSAXParser();
+ XMLReader xmlReader = saxParser.getXMLReader();
+ xmlReader.setEntityResolver(new EntityResolver() {
+ @Override
+ public InputSource resolveEntity(String publicId, String systemId)
+ throws SAXException, IOException {
+
+ InputSource source = null;
+
+ String smallSystemId = systemId.substring(systemId.lastIndexOf("/") + 1);
+ URL url = Resource.getURL("/docbook/common/" + smallSystemId);
+ if (url != null) {
+ if (log.isDebugEnabled()) {
+ log.debug("Resolved entity url : " + url);
+ }
+ InputStream stream = url.openStream();
+ source = new InputSource(stream);
+ }
+
+ return source;
+ }
+ });
+ InputSource inSrc = new InputSource(stream);
+ SAXSource saxs = new SAXSource(xmlReader, inSrc);
+ return saxs;
+ } catch (IOException e) {
+ e.printStackTrace();
+ return null;
+ } catch (ParserConfigurationException e) {
+ e.printStackTrace();
+ return null;
+ } catch (SAXException e) {
+ e.printStackTrace();
+ return null;
}
}
- }
+ });
+
+ doc = gen.transform(doc, stylesheet);
}
+ return doc;
}
+
+ public static Document generateXMl(Reader in) throws Exception {
+ // parse rst file
+ JRSTReader jrst = new JRSTReader();
+ return jrst.read(in);
+ }
+
+ public static String generateRST(Document doc) throws IOException {
+ // Creation d'un visitor qui convertie de l'xml vers le rst
+ DocUtilsVisitor visitor = new DocUtils2RST();
+
+ // Atacher le visitor au document
+ // il va parcourir tout les elements et reconstruire du rst
+ doc.accept(visitor);
+
+ // Recuperation du resultat
+ String result = visitor.getResult();
+ // nettoyage du visiteur
+ visitor.clear();
+
+ return result;
+ }
}
Modified: trunk/jrst/src/test/java/org/nuiton/jrst/JRSTTest.java
===================================================================
--- trunk/jrst/src/test/java/org/nuiton/jrst/JRSTTest.java 2011-04-28 10:05:53 UTC (rev 578)
+++ trunk/jrst/src/test/java/org/nuiton/jrst/JRSTTest.java 2011-05-12 09:55:09 UTC (rev 579)
@@ -125,6 +125,8 @@
JRST.generate(JRST.TYPE_RST, in, out, JRST.Overwrite.ALLTIME);
List<?> readLines = FileUtils.readLines(out);
+ log.info(OUT_LINES);
+ log.info(readLines);
Assert.assertEquals(OUT_LINES.size(), readLines.size());
for (int i = 0, j = OUT_LINES.size(); i < j; i++) {
String inLine = OUT_LINES.get(i);
1
0