r290 - in jrst/trunk: . src/main/java/org/codelutin/jrst
Author: chatellier Date: 2009-04-02 14:35:20 +0000 (Thu, 02 Apr 2009) New Revision: 290 Modified: jrst/trunk/changelog.txt jrst/trunk/pom.xml jrst/trunk/src/main/java/org/codelutin/jrst/JRST.java jrst/trunk/src/main/java/org/codelutin/jrst/JRSTGenerator.java jrst/trunk/src/main/java/org/codelutin/jrst/JRSTLexer.java jrst/trunk/src/main/java/org/codelutin/jrst/JRSTReader.java Log: Fix admonition (warning, etc...) Improve code. Modified: jrst/trunk/changelog.txt =================================================================== --- jrst/trunk/changelog.txt 2009-03-03 16:25:43 UTC (rev 289) +++ jrst/trunk/changelog.txt 2009-04-02 14:35:20 UTC (rev 290) @@ -1,3 +1,10 @@ +ver-0.8.5 xxx 20090218 + + * Fix admonition + * Fix comment directive and titles trailing spaces + * Readd ODT support ? + * Readd PDF support ? + ver-0.8.4 chemit 20090218 * Fix javadoc Modified: jrst/trunk/pom.xml =================================================================== --- jrst/trunk/pom.xml 2009-03-03 16:25:43 UTC (rev 289) +++ jrst/trunk/pom.xml 2009-04-02 14:35:20 UTC (rev 290) @@ -1,5 +1,8 @@ <?xml version="1.0" encoding="UTF-8"?> -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> +<project xmlns="http://maven.apache.org/POM/4.0.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 + http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> @@ -72,13 +75,10 @@ <scope>runtime</scope> </dependency> <dependency> - <groupId>net.sf.docbook</groupId> + <groupId>org.docbook</groupId> <artifactId>docbook-xsl</artifactId> - <version>1.74.0</version> - <type>zip</type> - <classifier>resources</classifier> - <scope>runtime</scope> - </dependency> + <version>1.72.0</version> + </dependency> </dependencies> <!-- ************************************************************* --> @@ -178,9 +178,9 @@ <plugin> <artifactId>maven-dependency-plugin</artifactId> - <!--configuration> + <configuration> <outputDirectory>${project.build.directory}/lib</outputDirectory> - </configuration--> + </configuration> <executions> <execution> <id>copy-dependencies</id> @@ -210,17 +210,17 @@ </executions> </plugin> - <!--plugin> + <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-javadoc-plugin</artifactId> <version>2.5</version> <configuration> <links> <link>http://java.sun.com/javase/6/docs/api/</link> - <link>http://lutinutil.labs.libre-entreprise.org/apidocs/</link> + <link>http://lutinutil.labs.libre-entreprise.org/lutinutil/apidocs/</link> </links> </configuration> - </plugin--> + </plugin> </plugins> <pluginManagement> @@ -251,11 +251,10 @@ <!-- ************************************************************* --> <!-- *** Build Environment ************************************** --> <!-- ************************************************************* --> - <!--Source control management--> <scm> - <connection>scm:svn:svn://anonymous@labs.libre-entreprise.org/svnroot/jrst/jrst/trunk</connection> - <developerConnection>scm:svn:svn+ssh://tchemit@labs.libre-entreprise.org/svnroot/jrst/jrst/trunk</developerConnection> - <url>http://labs.libre-entreprise.org/plugins/scmsvn/viewcvs.php/jrst/trunk/?root=jrst</url> + <connection>${maven.scm.connection}</connection> + <developerConnection>${maven.scm.developerConnection}</developerConnection> + <url>${maven.scm.url}</url> </scm> <!--Code Lutin Repository--> Modified: jrst/trunk/src/main/java/org/codelutin/jrst/JRST.java =================================================================== --- jrst/trunk/src/main/java/org/codelutin/jrst/JRST.java 2009-03-03 16:25:43 UTC (rev 289) +++ jrst/trunk/src/main/java/org/codelutin/jrst/JRST.java 2009-04-02 14:35:20 UTC (rev 290) @@ -52,6 +52,7 @@ import org.codelutin.i18n.I18n; import org.codelutin.util.FileCompletion; import org.codelutin.util.FileUtil; +import org.codelutin.util.Resource; import org.codelutin.util.StringUtil; import org.dom4j.Document; import org.dom4j.io.OutputFormat; @@ -82,60 +83,65 @@ NEVER, IFNEWER, ALLTIME } - /** to use log facility, just put in your code: log.info(\"...\"); */ - static private Log log = LogFactory.getLog(JRST.class); + /** to use log facility, just put in your code: log.info("..."); */ + protected static Log log = LogFactory.getLog(JRST.class); - // XSL Stylesheet to transforme something to other format - static final private String rst2xhtml = "/xsl/rst2xhtml.xsl"; + /** XSL Stylesheet to transform RST into HTML. */ + protected static final String rst2xhtml = "/xsl/rst2xhtml.xsl"; + /** XSL Stylesheet to transform RST into Xdoc. */ + protected static final String rst2xdoc = "/xsl/rst2xdoc.xsl"; + /** XSL Stylesheet to transform RST into Docbook. */ + protected static final String rst2docbook = "/xsl/dn2dbk.xsl"; - static final private String rst2xdoc = "/xsl/rst2xdoc.xsl"; + /** XSL Stylesheet to transform Docbook into xHTML. */ + protected static final String docbook2xhtml = "/xhtml/docbook.xsl"; + /** XSL Stylesheet to transform Docbook into javahelp. */ + protected static final String docbook2javahelp = "/javahelp/javahelp.xsl"; + /** XSL Stylesheet to transform Docbook into htmlhelp. */ + protected static final String docbook2htmlhelp = "/htmlhelp/htmlhelp.xsl"; + + /** XSL Stylesheet to transform xml into rst. */ + protected static final String rst2rst = "/xsl/xml2rst.xsl"; - static final private String rst2docbook = "/xsl/dn2dbk.xsl"; - // static final private String walshDir = - // "/home/letellier/docbook5-xsl-1.72.0/"; - // static final private String walshDir = "/docbook-xsl-nwalsh"; - static final private String walshDir = ""; + /** XSL Stylesheet to transform Docbook into ODF. */ + protected static final String docbook2odf = "/xsl/docbook2odf-0.244/docbook.xsl"; + /** XSL Stylesheet to transform Docbook into PDF. */ + protected static final String docbook2fo = "/fo/docbook.xsl"; - // static final private String docbook2odfDir = "/docbook2odf-0.211"; - static final private String docbook2xhtml = walshDir + "/xhtml/docbook.xsl"; + /** HTML output format type */ + public static final String TYPE_HTML = "html"; - static final private String docbook2javahelp = walshDir - + "/javahelp/javahelp.xsl"; + /** XDOC output format type */ + public static final String TYPE_XDOC = "xdoc"; - // static final private String dbkx2html = walshDir + "/html/onechunk.xsl"; - static final private String docbook2htmlhelp = walshDir - + "/htmlhelp/htmlhelp.xsl"; + /** DOCBOOK output format type */ + public static final String TYPE_DOCBOOK = "docbook"; - static final private String rst2rst = "/xsl/xml2rst.xsl"; + /** XHTML output format type */ + public static final String TYPE_XHTML = "xhtml"; - // static final private String docbook2odf = docbook2odfDir + - // "/xsl/docbook.xsl"; - static final private String docbook2fo = walshDir + "/fo/docbook.xsl"; + /** JAVA HELP output format type */ + public static final String TYPE_JAVAHELP = "javahelp"; - // Out put type available - static final public String TYPE_HTML = "html"; + /** HTML HELP output format type */ + public static final String TYPE_HTMLHELP = "htmlhelp"; - static final public String TYPE_XDOC = "xdoc"; + /** RST output format type */ + public static final String TYPE_RST = "rst"; - static final public String TYPE_DOCBOOK = "docbook"; + /** ODT output format type */ + public static final String TYPE_ODT = "odt"; + + /** FO output format type */ + public static final String TYPE_FO = "fo"; - static final public String TYPE_XHTML = "xhtml"; + /** PDF output format type */ + public static final String TYPE_PDF = "pdf"; - static final public String TYPE_JAVAHELP = "javahelp"; - - static final public String TYPE_HTMLHELP = "htmlhelp"; - - static final public String TYPE_RST = "rst"; - - // static final public String TYPE_ODT = "odt"; - static final public String TYPE_FO = "fo"; - - static final public String TYPE_PDF = "pdf"; - /** * key, Out type; value: chain of XSL file to provide wanted file for output */ - static private Map<String, String> stylesheets = null; + protected static Map<String, String> stylesheets = null; static { stylesheets = new HashMap<String, String>(); @@ -146,12 +152,17 @@ stylesheets.put(TYPE_JAVAHELP, rst2docbook + "," + docbook2javahelp); stylesheets.put(TYPE_HTMLHELP, rst2docbook + "," + docbook2htmlhelp); stylesheets.put(TYPE_RST, rst2rst); - // stylesheets.put(TYPE_ODT, rst2docbook+","+docbook2odf); + stylesheets.put(TYPE_ODT, rst2docbook + "," + docbook2odf); stylesheets.put(TYPE_FO, rst2docbook + "," + docbook2fo); stylesheets.put(TYPE_PDF, rst2docbook + "," + docbook2fo); } - static public void main(String[] args) throws Exception { + /** + * + * @param args + * @throws Exception + */ + public static void main(String[] args) throws Exception { I18n.init(); @@ -169,8 +180,9 @@ System.out.println(cli.getHelpMessage()); return; } - if (option.isConsole()) + if (option.isConsole()) { args = askOptionText(); + } option = CliFactory.parseArguments(JRSTOption.class, args); // search xsl file list to apply String xslList = null; @@ -198,8 +210,9 @@ done = true; } } - if (!done) + if (!done) { result = askOptionText(); + } } catch (java.awt.HeadlessException e) { result = askOptionText(); } @@ -233,14 +246,7 @@ * @throws IOException */ private static String[] askOptionText() throws IOException { - // language - /*if (Locale.getDefault().getLanguage() == "fr") - I18n.init("fr", "FR"); - else - I18n.init("en", "US");*/ - //I18n.init(); - System.out.println(_("help?")); Boolean done = false; String cheminRST = ""; @@ -304,8 +310,9 @@ } if (cheminXSL.length() == 0 || !type - .matches("xhtml|docbook|xml|html|xdoc|rst|pdf|odt|rtf")) + .matches("xhtml|docbook|xml|html|xdoc|rst|pdf|odt|rtf")) { type = "xml"; + } } boolean ecraser = false; done = false; @@ -423,7 +430,8 @@ if (file.exists()) { stylesheet = file.toURL(); } else { - stylesheet = JRST.class.getResource(xsl); + //stylesheet = JRST.class.getResource(xsl); + stylesheet = Resource.getURL(xsl); } if (stylesheet == null) { throw new FileNotFoundException("Can't find stylesheet: " Modified: jrst/trunk/src/main/java/org/codelutin/jrst/JRSTGenerator.java =================================================================== --- jrst/trunk/src/main/java/org/codelutin/jrst/JRSTGenerator.java 2009-03-03 16:25:43 UTC (rev 289) +++ jrst/trunk/src/main/java/org/codelutin/jrst/JRSTGenerator.java 2009-04-02 14:35:20 UTC (rev 290) @@ -283,7 +283,7 @@ */ public InputSource resolveEntity(String publicId, String systemId) throws SAXException, IOException { - System.err.println("## resolveEntity publicId '" + publicId + log.debug("## resolveEntity publicId '" + publicId + "' systemId: '" + systemId + "'"); return null; } Modified: jrst/trunk/src/main/java/org/codelutin/jrst/JRSTLexer.java =================================================================== --- jrst/trunk/src/main/java/org/codelutin/jrst/JRSTLexer.java 2009-03-03 16:25:43 UTC (rev 289) +++ jrst/trunk/src/main/java/org/codelutin/jrst/JRSTLexer.java 2009-04-02 14:35:20 UTC (rev 290) @@ -57,10 +57,10 @@ private static Log log = LogFactory.getLog(JRSTLexer.class); public static final String BULLET_CHAR = "*" + "+" + "-"/* - * + "\u2022" + - * "\u2023" + - * "\u2043" - */; + * + "\u2022" + + * "\u2023" + + * "\u2043" + */; public static final String TITLE_CHAR = "-=-~'`^+:!\"#$%&*,./;|?@\\_[\\]{}<>()"; @@ -259,11 +259,7 @@ in.unread(firstLine, true); int level = level(firstLine); if (level >= minLeftMargin) { - - // FIXME should be somethings like that: - // result = in.readWhile("^\\S{" + level + "}.*"); - // but tests fail - result = in.readWhile("^ {" + level + "}\\S+.*"); + result = in.readWhile("^\\s{" + level + "}\\S+.*"); } } @@ -968,7 +964,7 @@ * @return Element * @throws IOException */ - private Element peekAdmonition() throws IOException { + protected Element peekAdmonition() throws IOException { beginPeek(); Element result = null; String line = in.readLine(); @@ -997,29 +993,31 @@ .length()); result.addAttribute("title", title); - } else + } else { result.addAttribute("type", matcher.group()); - + } + String firstLine = ""; - if (!admonition && matcher.end() + 2 < line.length()) + if (!admonition && matcher.end() + 2 < line.length()) { firstLine = line .substring(matcher.end() + 2, line.length()); + } line = in.readLine(); if (line != null) { - if (line.matches("\\s*")) + if (line.matches("\\s*")) { line = in.readLine(); - if (line != null) { - if (!line.matches("\\s*")) { - level = level(line); - String txt = firstLine.trim() + "\n" + line + "\n"; - txt += "\n" + readBlockWithBlankLine(level); - result.setText(txt); - } - - } else + } + if (line != null && !line.matches("\\s*")) { + level = level(line); + String txt = firstLine.trim() + "\n" + line + "\n"; + txt += "\n" + readBlockWithBlankLine(level); + result.setText(txt); + } else { result.setText(firstLine); - } else + } + } else { result.setText(firstLine); + } } } endPeek(); @@ -1941,12 +1939,15 @@ } } else { String title = in.readLine(); - if (title != null && startsWithTitleChar(title) - && line.replaceFirst("\\s*$", "").length() == title.length()) { + if (title != null + && startsWithTitleChar(title) + && line.replaceFirst("\\s*$", "").length() == title + .length()) { result = DocumentHelper.createElement(TITLE).addAttribute( "type", "simple").addAttribute("char", - title.substring(0, 1)).addText(line.replaceFirst("\\s*$", "")); + title.substring(0, 1)).addText( + line.replaceFirst("\\s*$", "")); } } } @@ -2084,7 +2085,7 @@ result = DocumentHelper.createElement("comment"); result.addAttribute("level", "0"); result.addAttribute("xml:space", "preserve"); - + // first line is part of comment result.setText(line.substring(2).trim() + "\n"); line = in.readLine(); Modified: jrst/trunk/src/main/java/org/codelutin/jrst/JRSTReader.java =================================================================== --- jrst/trunk/src/main/java/org/codelutin/jrst/JRSTReader.java 2009-03-03 16:25:43 UTC (rev 289) +++ jrst/trunk/src/main/java/org/codelutin/jrst/JRSTReader.java 2009-04-02 14:35:20 UTC (rev 290) @@ -29,23 +29,82 @@ package org.codelutin.jrst; -import org.apache.commons.lang.ObjectUtils; -import org.apache.commons.lang.StringEscapeUtils; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; import static org.codelutin.i18n.I18n._; -import static org.codelutin.jrst.ReStructuredText.*; -import org.codelutin.jrst.directive.ContentDirective; -import org.codelutin.jrst.directive.DateDirective; -import org.codelutin.jrst.directive.ImageDirective; -import org.codelutin.jrst.directive.SectnumDirective; -import org.codelutin.util.StringUtil; -import org.dom4j.Document; -import org.dom4j.DocumentException; -import org.dom4j.DocumentHelper; -import org.dom4j.Element; -import org.dom4j.Node; -import org.dom4j.VisitorSupport; +import static org.codelutin.jrst.ReStructuredText.ADDRESS; +import static org.codelutin.jrst.ReStructuredText.ADMONITION; +import static org.codelutin.jrst.ReStructuredText.ATTRIBUTION; +import static org.codelutin.jrst.ReStructuredText.AUTHOR; +import static org.codelutin.jrst.ReStructuredText.AUTHORS; +import static org.codelutin.jrst.ReStructuredText.BLOCK_QUOTE; +import static org.codelutin.jrst.ReStructuredText.BULLET_LIST; +import static org.codelutin.jrst.ReStructuredText.COLSPEC; +import static org.codelutin.jrst.ReStructuredText.COMMENT; +import static org.codelutin.jrst.ReStructuredText.CONTACT; +import static org.codelutin.jrst.ReStructuredText.COPYRIGHT; +import static org.codelutin.jrst.ReStructuredText.DATE; +import static org.codelutin.jrst.ReStructuredText.DECORATION; +import static org.codelutin.jrst.ReStructuredText.DEFINITION; +import static org.codelutin.jrst.ReStructuredText.DEFINITION_LIST; +import static org.codelutin.jrst.ReStructuredText.DEFINITION_LIST_ITEM; +import static org.codelutin.jrst.ReStructuredText.DESCRIPTION; +import static org.codelutin.jrst.ReStructuredText.DOCINFO; +import static org.codelutin.jrst.ReStructuredText.DOCTEST_BLOCK; +import static org.codelutin.jrst.ReStructuredText.DOCUMENT; +import static org.codelutin.jrst.ReStructuredText.EMPHASIS; +import static org.codelutin.jrst.ReStructuredText.ENTRY; +import static org.codelutin.jrst.ReStructuredText.ENUMERATED_LIST; +import static org.codelutin.jrst.ReStructuredText.FIELD; +import static org.codelutin.jrst.ReStructuredText.FIELD_BODY; +import static org.codelutin.jrst.ReStructuredText.FIELD_LIST; +import static org.codelutin.jrst.ReStructuredText.FIELD_NAME; +import static org.codelutin.jrst.ReStructuredText.FOOTER; +import static org.codelutin.jrst.ReStructuredText.FOOTNOTE; +import static org.codelutin.jrst.ReStructuredText.FOOTNOTE_REFERENCE; +import static org.codelutin.jrst.ReStructuredText.FOOTNOTE_SYMBOL; +import static org.codelutin.jrst.ReStructuredText.HEADER; +import static org.codelutin.jrst.ReStructuredText.IMAGE; +import static org.codelutin.jrst.ReStructuredText.LINE; +import static org.codelutin.jrst.ReStructuredText.LINE_BLOCK; +import static org.codelutin.jrst.ReStructuredText.LIST_ITEM; +import static org.codelutin.jrst.ReStructuredText.LITERAL; +import static org.codelutin.jrst.ReStructuredText.LITERAL_BLOCK; +import static org.codelutin.jrst.ReStructuredText.OPTION; +import static org.codelutin.jrst.ReStructuredText.OPTION_ARGUMENT; +import static org.codelutin.jrst.ReStructuredText.OPTION_GROUP; +import static org.codelutin.jrst.ReStructuredText.OPTION_LIST; +import static org.codelutin.jrst.ReStructuredText.OPTION_LIST_ITEM; +import static org.codelutin.jrst.ReStructuredText.OPTION_STRING; +import static org.codelutin.jrst.ReStructuredText.ORGANIZATION; +import static org.codelutin.jrst.ReStructuredText.PARAGRAPH; +import static org.codelutin.jrst.ReStructuredText.REFERENCE; +import static org.codelutin.jrst.ReStructuredText.REGEX_ANONYMOUS_HYPERLINK_REFERENCE; +import static org.codelutin.jrst.ReStructuredText.REGEX_EMAIL; +import static org.codelutin.jrst.ReStructuredText.REGEX_EMPHASIS; +import static org.codelutin.jrst.ReStructuredText.REGEX_FOOTNOTE_REFERENCE; +import static org.codelutin.jrst.ReStructuredText.REGEX_HYPERLINK_REFERENCE; +import static org.codelutin.jrst.ReStructuredText.REGEX_INLINE_REFERENCE; +import static org.codelutin.jrst.ReStructuredText.REGEX_LITERAL; +import static org.codelutin.jrst.ReStructuredText.REGEX_REFERENCE; +import static org.codelutin.jrst.ReStructuredText.REGEX_STRONG; +import static org.codelutin.jrst.ReStructuredText.REGEX_SUBSTITUTION_REFERENCE; +import static org.codelutin.jrst.ReStructuredText.REVISION; +import static org.codelutin.jrst.ReStructuredText.ROW; +import static org.codelutin.jrst.ReStructuredText.SECTION; +import static org.codelutin.jrst.ReStructuredText.SIDEBAR; +import static org.codelutin.jrst.ReStructuredText.STATUS; +import static org.codelutin.jrst.ReStructuredText.STRONG; +import static org.codelutin.jrst.ReStructuredText.SUBSTITUTION_DEFINITION; +import static org.codelutin.jrst.ReStructuredText.SUBTITLE; +import static org.codelutin.jrst.ReStructuredText.TABLE; +import static org.codelutin.jrst.ReStructuredText.TARGET; +import static org.codelutin.jrst.ReStructuredText.TBODY; +import static org.codelutin.jrst.ReStructuredText.TERM; +import static org.codelutin.jrst.ReStructuredText.TGROUP; +import static org.codelutin.jrst.ReStructuredText.THEAD; +import static org.codelutin.jrst.ReStructuredText.TITLE; +import static org.codelutin.jrst.ReStructuredText.TOPIC; +import static org.codelutin.jrst.ReStructuredText.TRANSITION; +import static org.codelutin.jrst.ReStructuredText.VERSION; import java.io.BufferedReader; import java.io.File; @@ -63,6 +122,22 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; +import org.apache.commons.lang.ObjectUtils; +import org.apache.commons.lang.StringEscapeUtils; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.codelutin.jrst.directive.ContentDirective; +import org.codelutin.jrst.directive.DateDirective; +import org.codelutin.jrst.directive.ImageDirective; +import org.codelutin.jrst.directive.SectnumDirective; +import org.codelutin.util.StringUtil; +import org.dom4j.Document; +import org.dom4j.DocumentException; +import org.dom4j.DocumentHelper; +import org.dom4j.Element; +import org.dom4j.Node; +import org.dom4j.VisitorSupport; + /* * * <pre> +--------------------------------------------------------------------+ | @@ -2199,8 +2274,12 @@ text = start + temporaries.get(tempKey) + end; matcher = p.matcher(text); } + + String resultElementText = text.trim(); + resultElementText = resultElementText.replace("<", "<"); + resultElementText = resultElementText.replace(">", ">"); Element result = DocumentHelper.parseText( - "<TMP>" + text.trim() + "</TMP>").getRootElement(); + "<TMP>" + resultElementText + "</TMP>").getRootElement(); e.setText(""); e.appendContent(result);
participants (1)
-
chatellierï¼ users.labs.libre-entreprise.org