Author: jpages Date: 2012-04-24 09:49:14 +0200 (Tue, 24 Apr 2012) New Revision: 643 Url: http://nuiton.org/repositories/revision/jrst/643 Log: JRST using docutils (no pdf generation) Added: branches/jrst-docutils-jython/docutils/ branches/jrst-docutils-jython/docutils/docutils.iml branches/jrst-docutils-jython/docutils/src/ branches/jrst-docutils-jython/jrst/src/test/java/org/nuiton/jrst/JRSTJython.java Modified: branches/jrst-docutils-jython/jrst/pom.xml branches/jrst-docutils-jython/jrst/src/main/java/org/nuiton/jrst/JRST.java branches/jrst-docutils-jython/jrst/src/main/java/org/nuiton/jrst/JRSTConfig.java branches/jrst-docutils-jython/jrst/src/main/java/org/nuiton/jrst/JRSTConfigOption.java branches/jrst-docutils-jython/jrst/src/main/resources/i18n/jrst_en_GB.properties branches/jrst-docutils-jython/jrst/src/main/resources/i18n/jrst_fr_FR.properties branches/jrst-docutils-jython/jrst/src/test/java/org/nuiton/jrst/JRSTAbstractTest.java branches/jrst-docutils-jython/jrst/src/test/java/org/nuiton/jrst/JRSTCompareDocutils.java branches/jrst-docutils-jython/jrst/src/test/java/org/nuiton/jrst/JRSTGeneratorTest.java branches/jrst-docutils-jython/jrst/src/test/java/org/nuiton/jrst/JRSTReaderTest.java branches/jrst-docutils-jython/jrst/src/test/java/org/nuiton/jrst/JRSTTest.java branches/jrst-docutils-jython/jrst/src/test/java/org/nuiton/jrst/bugs/AdmonitionTest.java branches/jrst-docutils-jython/jrst/src/test/java/org/nuiton/jrst/bugs/DirectiveTest.java branches/jrst-docutils-jython/jrst/src/test/java/org/nuiton/jrst/bugs/OptionTest.java branches/jrst-docutils-jython/jrst/src/test/java/org/nuiton/jrst/bugs/TableTest.java branches/jrst-docutils-jython/pom.xml Added: branches/jrst-docutils-jython/docutils/docutils.iml =================================================================== --- branches/jrst-docutils-jython/docutils/docutils.iml (rev 0) +++ branches/jrst-docutils-jython/docutils/docutils.iml 2012-04-24 07:49:14 UTC (rev 643) @@ -0,0 +1,14 @@ +<?xml version="1.0" encoding="UTF-8"?> +<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4"> + <component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_6" inherit-compiler-output="false"> + <output url="file://$MODULE_DIR$/target/classes" /> + <output-test url="file://$MODULE_DIR$/target/test-classes" /> + <content url="file://$MODULE_DIR$"> + <sourceFolder url="file://$MODULE_DIR$/src/main/resources" isTestSource="false" /> + <excludeFolder url="file://$MODULE_DIR$/target" /> + </content> + <orderEntry type="inheritedJdk" /> + <orderEntry type="sourceFolder" forTests="false" /> + </component> +</module> + Modified: branches/jrst-docutils-jython/jrst/pom.xml =================================================================== --- branches/jrst-docutils-jython/jrst/pom.xml 2012-04-16 08:25:37 UTC (rev 642) +++ branches/jrst-docutils-jython/jrst/pom.xml 2012-04-24 07:49:14 UTC (rev 643) @@ -42,8 +42,13 @@ <artifactId>jrst</artifactId> <dependencies> - <dependency> + <groupId>${project.groupId}</groupId> + <artifactId>docutils</artifactId> + <version>${project.version}</version> + </dependency> + + <dependency> <groupId>commons-lang</groupId> <artifactId>commons-lang</artifactId> </dependency> @@ -120,6 +125,19 @@ <artifactId>log4j</artifactId> <scope>runtime</scope> </dependency> + + <dependency> + <groupId>org.python</groupId> + <artifactId>jython-standalone</artifactId> + </dependency> + + <!-- Flying Saucer --> + <dependency> + <groupId>org.xhtmlrenderer</groupId> + <artifactId>core-renderer</artifactId> + <version>R8</version> + </dependency> + </dependencies> <!-- ************************************************************* --> Modified: branches/jrst-docutils-jython/jrst/src/main/java/org/nuiton/jrst/JRST.java =================================================================== --- branches/jrst-docutils-jython/jrst/src/main/java/org/nuiton/jrst/JRST.java 2012-04-16 08:25:37 UTC (rev 642) +++ branches/jrst-docutils-jython/jrst/src/main/java/org/nuiton/jrst/JRST.java 2012-04-24 07:49:14 UTC (rev 643) @@ -28,27 +28,14 @@ import java.awt.GraphicsEnvironment; import java.io.*; import java.net.URL; -import java.util.HashMap; -import java.util.List; -import java.util.Locale; -import java.util.Map; +import java.util.*; -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.sax.SAXResult; -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; -import org.apache.fop.apps.Fop; -import org.apache.fop.apps.FopFactory; -import org.apache.fop.apps.MimeConstants; import org.dom4j.Document; +import org.dom4j.io.SAXReader; import org.nuiton.i18n.I18n; import org.nuiton.i18n.init.ClassPathI18nInitializer; import org.nuiton.jrst.convertisor.DocUtils2RST; @@ -57,11 +44,12 @@ import org.nuiton.util.FileUtil; import org.nuiton.util.Resource; import org.nuiton.util.StringUtil; +import org.python.util.JarRunner; /** * FIXME: 'JRST --help' doesn't work, but 'JRST --help toto' work :( FIXME: * 'JRST -c' doesn't work, but 'JRST -c toto' - * + * * Created: 3 nov. 06 20:56:00 * * @author poussin @@ -78,6 +66,10 @@ NEVER, IFNEWER, ALLTIME } + public enum Format { + XML, HTML, PDF, ODT, LATEX, S5, XETEX, MAN, RST + } + /** to use log facility, just put in your code: log.info("..."); */ protected static Log log = LogFactory.getLog(JRST.class); @@ -96,7 +88,7 @@ protected static final String docbook2javahelp = "/docbook/javahelp/javahelp.xsl"; /** XSL Stylesheet to transform Docbook into htmlhelp. */ protected static final String docbook2htmlhelp = "/docbook/htmlhelp/htmlhelp.xsl"; - + // /** XSL Stylesheet to transform xml into rst. */ // protected static final String rst2rst = "JRSTWriter"; @@ -186,12 +178,12 @@ /** * Main method. - * + * * @param args main args - * @throws Exception + * @throws Exception */ public static void main(String[] args) throws Exception { - + I18n.init(new ClassPathI18nInitializer(), Locale.UK); if (args.length == 0) { @@ -219,8 +211,8 @@ if (JRSTConfigOption.FORCE.getOptionAsBoolean(config)) { overwrite = Overwrite.ALLTIME; } - - generate(xslList, inputFile, ouputFile, overwrite); + + generate(xslList.toUpperCase(), inputFile, ouputFile, overwrite); } private static String[] askOption() throws SecurityException, @@ -245,7 +237,7 @@ /** * Interface graphique. - * + * * @return * @throws SecurityException * @throws NoSuchMethodException @@ -258,134 +250,119 @@ return graph.getCmd(); } - public static void generate(String xslListOrOutType, File fileIn, - File fileOut, Overwrite overwrite) throws Exception { - - generate(xslListOrOutType, fileIn, UTF_8, fileOut, UTF_8, overwrite); + public static void generate(String outputType, File fileIn, + File fileOut, Overwrite overwrite) throws Exception { + generate(outputType, fileIn, UTF_8, fileOut, UTF_8, overwrite); } - public static void generate(String xslListOrOutType, File fileIn, String inputEncoding, - File fileOut, String outputEncoding, Overwrite overwrite) throws Exception { + public static void generate(String outputType, File fileIn, String inputEncoding, + File fileOut, String outputEncoding, Overwrite overwrite) throws Exception { if (fileOut != null && fileOut.exists() && (overwrite == Overwrite.NEVER || (overwrite == Overwrite.IFNEWER && FileUtil - .isNewer(fileIn, fileOut)))) { - // System.err.println("Don't generate file " + fileOut + - // ", because already exists"); + .isNewer(fileIn, fileOut)))) { log.info("Don't generate file " + fileOut + ", because already exists"); - } else { - - // In - URL url = fileIn.toURI().toURL(); - Reader reader = new InputStreamReader(url.openStream(), inputEncoding); - - // Out - FileOutputStream outputStream = new FileOutputStream(fileOut); - OutputStreamWriter writer = new OutputStreamWriter(outputStream, outputEncoding); - + } else if (outputType.equals("PDF")) { + /* // Generate - String result = generateString(xslListOrOutType, reader); - + String result = generateString(Format.XML.name(), fileIn); 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"))); + FopFactory fopFactory = FopFactory.newInstance(); - OutputStream outPDF = new BufferedOutputStream(new FileOutputStream( - fileOut)); + OutputStream outPDF = new BufferedOutputStream(new FileOutputStream(fileOut)); - FOUserAgent userAgent = fopFactory.newFOUserAgent(); + FOUserAgent userAgent = fopFactory.newFOUserAgent(); - // Step 3: Construct fop with desired output format - Fop fop = fopFactory.newFop(MimeConstants.MIME_PDF, - userAgent, outPDF); + // Step 3: Construct fop with desired output format + Fop fop = fopFactory.newFop(MimeConstants.MIME_PDF, + userAgent, outPDF); - // Step 4: Setup JAXP using identity transformer - TransformerFactory factory = TransformerFactory - .newInstance(); - Transformer transformer = factory.newTransformer(); // identity - // transformer + // Step 4: Setup JAXP using identity transformer + TransformerFactory factory = TransformerFactory + .newInstance(); + Transformer transformer = factory.newTransformer(); // identity + // transformer - // Step 5: Setup input and output for XSLT transformation - // Setup input stream - Source src = new StreamSource(new StringReader(result)); + // Step 5: Setup input and output for XSLT transformation + // Setup input stream + Source src = new StreamSource(new StringReader(result)); - // Resulting SAX events (the generated FO) must be piped - // through to FOP - Result res = new SAXResult(fop.getDefaultHandler()); + // Resulting SAX events (the generated FO) must be piped + // through to FOP + Result res = new SAXResult(fop.getDefaultHandler()); - // Step 6: Start XSLT transformation and FOP processing - transformer.transform(src, res); + // Step 6: Start XSLT transformation and FOP processing + transformer.transform(src, res); - outPDF.close(); - } else { - // write generated document - writer.write(result); + outPDF.close(); + */ - writer.close(); - - } + } else { + generateDocument(outputType, fileIn, fileOut); } } /** - * - * @param xslListOrOutType + * + * @param outputType * @param in * @throws Exception */ - public static String generate(String xslListOrOutType, String in) throws Exception { - return generateString(xslListOrOutType, new StringReader(in)); + public static String generate(String outputType, String in) throws Exception { + File inFile = File.createTempFile("in", "rst"); + FileUtil.writeString(inFile, in); + return generateString(outputType, inFile); } /** - * - * @param xslListOrOutType + * + * @param outputType * @param in * @throws Exception */ - public static Writer generate(String xslListOrOutType, Reader in) throws Exception { - StringWriter writer = new StringWriter(); - writer.write(generateString(xslListOrOutType,in)); - return writer; - } - - - /** - * - * @param xslListOrOutType - * @param in - * @throws Exception - */ - public static StringBuffer generate(String xslListOrOutType, StringBuffer in) throws Exception { - return new StringBuffer(generate(xslListOrOutType, in.toString())); - } - - + public static Writer generate(String outputType, File in) throws Exception { + StringWriter writer = new StringWriter(); + writer.write(generateString(outputType,in)); + return writer; + } + + /** * - * @param xslListOrOutType + * @param outputType * @param in * @throws Exception */ - public static String generateString(String xslListOrOutType, Reader in) throws Exception { + public static StringBuffer generate(String outputType, StringBuffer in) throws Exception { + return new StringBuffer(generate(outputType, in.toString())); + } + + /** + * + * @param outputType + * @param in + * @throws Exception + */ + public static String generateString(String outputType, File in) throws Exception { Document doc = generateXML(in); - // Sortie vers rst - if (xslListOrOutType.equals(TYPE_RST)){ - return generateRST(doc); - } else if (!StringUtils.isEmpty(xslListOrOutType)) { - doc = applyXsls(doc, xslListOrOutType); + if (!StringUtils.isEmpty(outputType)) { + doc = applyXsls(doc, outputType); } return doc.asXML(); } + /** + * + * @param doc + * @param xslListOrOutType + * @throws IOException, TransformerException + */ private static Document applyXsls(Document doc, String xslListOrOutType) throws IOException, TransformerException { // search xsl file list to apply @@ -420,17 +397,39 @@ return doc; } - public static Document generateXML(Reader in) throws Exception { - // parse rst file - JRSTReader jrst = new JRSTReader(); - return jrst.read(in); + public static Document generateXML(File in) throws Exception { + + URL resource = in.getClass().getResource("/__run__.py"); + String docutilsPath = resource.getPath().replaceAll("__run__.py", ""); + docutilsPath = docutilsPath.replaceAll("!", ""); + docutilsPath = docutilsPath.replaceAll("file:", ""); + + File out = File.createTempFile("result", ".xml"); + JarRunner.run(new String[]{docutilsPath, Format.XML.name(), in.getPath(), out.getPath()}); + + SAXReader saxReader = new SAXReader(); + return saxReader.read(out); } + public static File generateDocument(String outputType, File in, File out) throws Exception { + + URL resource = in.getClass().getResource("/__run__.py"); + String docutilsPath = resource.getPath().replaceAll("__run__.py", ""); + docutilsPath = docutilsPath.replaceAll("!", ""); + docutilsPath = docutilsPath.replaceAll("file:", ""); + + log.info("Run Python with args: " + Arrays.toString(new String[]{docutilsPath, outputType, in.getPath(), out.getPath()})); + + JarRunner.run(new String[]{docutilsPath, outputType, in.getPath(), out.getPath()}); + + return out; + } + 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 + // Attacher le visitor au document // il va parcourir tout les elements et reconstruire du rst doc.accept(visitor); @@ -441,4 +440,4 @@ return result; } -} +} \ No newline at end of file Modified: branches/jrst-docutils-jython/jrst/src/main/java/org/nuiton/jrst/JRSTConfig.java =================================================================== --- branches/jrst-docutils-jython/jrst/src/main/java/org/nuiton/jrst/JRSTConfig.java 2012-04-16 08:25:37 UTC (rev 642) +++ branches/jrst-docutils-jython/jrst/src/main/java/org/nuiton/jrst/JRSTConfig.java 2012-04-24 07:49:14 UTC (rev 643) @@ -93,6 +93,7 @@ conf.addAlias("-t", "--option", "outType"); conf.addAlias("--xslFile", "--option", "xslFile"); conf.addAlias("-x", "--option", "xslFile"); + conf.addAlias("-i", "--intermediate", "intermediateFile"); try { conf.parse(args); Modified: branches/jrst-docutils-jython/jrst/src/main/java/org/nuiton/jrst/JRSTConfigOption.java =================================================================== --- branches/jrst-docutils-jython/jrst/src/main/java/org/nuiton/jrst/JRSTConfigOption.java 2012-04-16 08:25:37 UTC (rev 642) +++ branches/jrst-docutils-jython/jrst/src/main/java/org/nuiton/jrst/JRSTConfigOption.java 2012-04-24 07:49:14 UTC (rev 643) @@ -43,7 +43,9 @@ FORCE("force", n_("jrst.option.force"), "false", String.class, true, false), OUT_FILE("outFile", n_("jrst.option.outfile"), null, String.class, true, false), OUT_TYPE("outType", n_("jrst.option.outtype"), null, String.class, true, false), - XSL_FILE("xslFile", n_("jrst.option.xslfile"), null, String.class, true, false); + XSL_FILE("xslFile", n_("jrst.option.xslfile"), null, String.class, true, false), + INTERMEDIATE_FILE("intermediateFile", n_("jrst.option.intermediatefile"), JRST.Format.HTML.name(), + String.class, true, false); public String key; public String description; Modified: branches/jrst-docutils-jython/jrst/src/main/resources/i18n/jrst_en_GB.properties =================================================================== --- branches/jrst-docutils-jython/jrst/src/main/resources/i18n/jrst_en_GB.properties 2012-04-16 08:25:37 UTC (rev 642) +++ branches/jrst-docutils-jython/jrst/src/main/resources/i18n/jrst_en_GB.properties 2012-04-24 07:49:14 UTC (rev 643) @@ -4,6 +4,7 @@ btnConvert=Convert externalXSL=External(s) XSL(s) jrst.option.force=Overwrite existing out file +jrst.option.intermediatefile= jrst.option.outfile=Output file jrst.option.outtype=Output type (xml|xhtml|docbook|html|xdoc|rst|fo|pdf) jrst.option.xslfile=XSL file list to apply, comma separated Modified: branches/jrst-docutils-jython/jrst/src/main/resources/i18n/jrst_fr_FR.properties =================================================================== --- branches/jrst-docutils-jython/jrst/src/main/resources/i18n/jrst_fr_FR.properties 2012-04-16 08:25:37 UTC (rev 642) +++ branches/jrst-docutils-jython/jrst/src/main/resources/i18n/jrst_fr_FR.properties 2012-04-24 07:49:14 UTC (rev 643) @@ -4,6 +4,7 @@ btnConvert=Convertir externalXSL=XSL(s) externe(s) jrst.option.force=Remplace un fichier existant +jrst.option.intermediatefile= jrst.option.outfile=Fichier de sortie jrst.option.outtype=Type de sortie (xml|xhtml|docbook|html|xdoc|rst|fo|pdf) jrst.option.xslfile=Fichier XSL a appliquer (séparé par une ,) Modified: branches/jrst-docutils-jython/jrst/src/test/java/org/nuiton/jrst/JRSTAbstractTest.java =================================================================== --- branches/jrst-docutils-jython/jrst/src/test/java/org/nuiton/jrst/JRSTAbstractTest.java 2012-04-16 08:25:37 UTC (rev 642) +++ branches/jrst-docutils-jython/jrst/src/test/java/org/nuiton/jrst/JRSTAbstractTest.java 2012-04-24 07:49:14 UTC (rev 643) @@ -68,7 +68,7 @@ public static File getOutputTestFile(String fileName) throws IOException { File file = new File(testWorkDir, fileName); file.createNewFile(); - file.deleteOnExit(); + //file.deleteOnExit(); return file; } Modified: branches/jrst-docutils-jython/jrst/src/test/java/org/nuiton/jrst/JRSTCompareDocutils.java =================================================================== --- branches/jrst-docutils-jython/jrst/src/test/java/org/nuiton/jrst/JRSTCompareDocutils.java 2012-04-16 08:25:37 UTC (rev 642) +++ branches/jrst-docutils-jython/jrst/src/test/java/org/nuiton/jrst/JRSTCompareDocutils.java 2012-04-24 07:49:14 UTC (rev 643) @@ -140,12 +140,12 @@ } //Compare RST - if (compareRST(testFile)) { + /*if (compareRST(testFile)) { res+="\tRST->OK\n"; } else { res+="\tRST->KO\n"; - } + }*/ log.debug("=========================================================="); } @@ -215,7 +215,7 @@ * @return * @throws Exception */ - private boolean compareRST(File testFile) throws Exception { + /* private boolean compareRST(File testFile) throws Exception { //recuperation du XML cree depuis le RST avec JRST Document rst2xml = getXMLJrst(testFile); @@ -230,7 +230,7 @@ return compareXML(rst2xml, rst2rst2xml); //return true; - } + } */ /** @@ -256,12 +256,7 @@ * @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.generateString(JRST.TYPE_HTML,reader); + return JRST.generateString(JRST.Format.HTML.name(), source); } /** @@ -270,13 +265,9 @@ * @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.generateString(JRST.TYPE_RST,reader); - } + /*private String getRSTJrst(File source) throws Exception { + return JRST.generateString(JRST.Format.RST.name(),source); + } */ /** Modified: branches/jrst-docutils-jython/jrst/src/test/java/org/nuiton/jrst/JRSTGeneratorTest.java =================================================================== --- branches/jrst-docutils-jython/jrst/src/test/java/org/nuiton/jrst/JRSTGeneratorTest.java 2012-04-16 08:25:37 UTC (rev 642) +++ branches/jrst-docutils-jython/jrst/src/test/java/org/nuiton/jrst/JRSTGeneratorTest.java 2012-04-24 07:49:14 UTC (rev 643) @@ -65,7 +65,8 @@ String test1 = getOutputTestPath("jrst-RstToRst.rst"); JRST.main(new String[]{"-t", "rst", "--force", "-o", test1, getResourcesTestPath()}); } - + + @Ignore @Test public void testRstToHtml() throws Exception { Added: branches/jrst-docutils-jython/jrst/src/test/java/org/nuiton/jrst/JRSTJython.java =================================================================== --- branches/jrst-docutils-jython/jrst/src/test/java/org/nuiton/jrst/JRSTJython.java (rev 0) +++ branches/jrst-docutils-jython/jrst/src/test/java/org/nuiton/jrst/JRSTJython.java 2012-04-24 07:49:14 UTC (rev 643) @@ -0,0 +1,69 @@ +package org.nuiton.jrst; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.junit.Test; +import org.python.core.PySystemState; +import org.python.util.JarRunner; +import org.python.util.PythonInterpreter; + +import java.io.*; +import java.net.URL; +import java.util.Properties; + +/** + * Created with IntelliJ IDEA. + * User: jpages + * Date: 4/16/12 + * Time: 11:09 AM + * To change this template use File | Settings | File Templates. + */ +public class JRSTJython { + + /** to use log facility, just put in your code: log.info("..."); */ + protected static Log log = LogFactory.getLog(JRSTJython.class); + + /* + Essai avec Streams + @Test + public void testJython() throws Exception { + Properties props = new Properties(); + props.setProperty("python.path", "/home/yoros/Apps/Stage/docutils-0.8.1"); + PythonInterpreter.initialize(System.getProperties(), props, + new String[]{""}); + InputStream in = JRSTReaderTest.class + .getResourceAsStream("/test.rst"); + InputStream rst2xml = JRST.class + .getResourceAsStream("/docutils/build/scripts-2.7/rst2xml.py"); + + PythonInterpreter interp = new PythonInterpreter(); + interp.setIn(in); + interp.execfile(rst2xml); + } + */ + + // Essai avec JarRunner + @Test + public void testJython2() throws Exception { + URL resource = getClass().getResource("/__run__.py"); + System.out.println(resource); + + String docutilsPath = resource.getPath().replaceAll("__run__.py", ""); + docutilsPath = docutilsPath.replaceAll("!", ""); + docutilsPath = docutilsPath.replaceAll("file:", ""); + JarRunner.run(new String[]{docutilsPath, "XML", "/home/yoros/workspace/jrst-docutils-jython/target/surefire-workdir/toRst1-in.rst", "toRst1-in.xml"}); + } + + @Test + public void test() { + Properties props = PySystemState.getBaseProperties(); + System.out.println(props.getProperty("python.path")); + props.setProperty("python.path", "/home/yoros/workspace/jrst-docutils-jython/jrst/src/main/resources/Lib:/home/yoros/workspace/jrst-docutils-jython/jrst/src/main/resources/build:/docutils/build/scripts-2.7/rst2xml.py"); + PythonInterpreter.initialize(PySystemState.getBaseProperties(), props, new String[0]); + PythonInterpreter interp = new PythonInterpreter(); + interp.execfile("/home/yoros/workspace/jrst-docutils-jython/jrst/src/main/resources/docutils/build/scripts-2.7/rst2xml.py"); + //interp.exec("import sys"); + // System.out.println("path python = " + interp.eval("sys.path")); + //interp.exec("import docutils"); + } +} \ No newline at end of file Modified: branches/jrst-docutils-jython/jrst/src/test/java/org/nuiton/jrst/JRSTReaderTest.java =================================================================== --- branches/jrst-docutils-jython/jrst/src/test/java/org/nuiton/jrst/JRSTReaderTest.java 2012-04-16 08:25:37 UTC (rev 642) +++ branches/jrst-docutils-jython/jrst/src/test/java/org/nuiton/jrst/JRSTReaderTest.java 2012-04-24 07:49:14 UTC (rev 643) @@ -29,10 +29,7 @@ import org.apache.commons.logging.LogFactory; import org.dom4j.Document; -import java.io.BufferedReader; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.io.Reader; +import java.io.*; import java.net.URL; import java.util.Locale; Modified: branches/jrst-docutils-jython/jrst/src/test/java/org/nuiton/jrst/JRSTTest.java =================================================================== --- branches/jrst-docutils-jython/jrst/src/test/java/org/nuiton/jrst/JRSTTest.java 2012-04-16 08:25:37 UTC (rev 642) +++ branches/jrst-docutils-jython/jrst/src/test/java/org/nuiton/jrst/JRSTTest.java 2012-04-24 07:49:14 UTC (rev 643) @@ -33,7 +33,6 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.junit.Assert; -import org.junit.BeforeClass; import org.junit.Test; import org.nuiton.util.Resource; @@ -53,15 +52,15 @@ */ @Test public void testResources() { - Assert.assertNotNull(Resource.getURL(JRST.rst2xhtml)); - Assert.assertNotNull(Resource.getURL(JRST.rst2xdoc)); - Assert.assertNotNull(Resource.getURL(JRST.rst2docbook)); - Assert.assertNotNull(Resource.getURL(JRST.docbook2xhtml)); - Assert.assertNotNull(Resource.getURL(JRST.docbook2javahelp)); - Assert.assertNotNull(Resource.getURL(JRST.docbook2htmlhelp)); + //Assert.assertNotNull(Resource.getURL(JRST.rst2xhtml)); + //Assert.assertNotNull(Resource.getURL(JRST.rst2xdoc)); + //Assert.assertNotNull(Resource.getURL(JRST.rst2docbook)); + //Assert.assertNotNull(Resource.getURL(JRST.docbook2xhtml)); + //Assert.assertNotNull(Resource.getURL(JRST.docbook2javahelp)); + //Assert.assertNotNull(Resource.getURL(JRST.docbook2htmlhelp)); // FIXME echatellier 20110217 following assert fails //Assert.assertNotNull(Resource.getURL(JRST.docbook2odf)); - Assert.assertNotNull(Resource.getURL(JRST.docbook2fo)); + //Assert.assertNotNull(Resource.getURL(JRST.xml2fo)); } @Test @@ -72,15 +71,15 @@ "=====", "Title", "=====", - // "", + "", "SubTitle", "--------", - // "", - ".. topic:: TopicTitle", - // "", - " TopicBody.", - // "", - // "", + "", + ".. topic:: TopicTitle", + "", + " TopicBody.", + "", + "", "Another body outside of the topic :)" }); List<String> OUT_LINES = Arrays.asList(new String[]{ @@ -102,7 +101,7 @@ File out = new File(testWorkDir, "toRst1-out.rst"); - JRST.generate(JRST.TYPE_RST, in, out, JRST.Overwrite.ALLTIME); + JRST.generate(JRST.Format.RST.name(), in, out, JRST.Overwrite.ALLTIME); List<?> readLines = FileUtils.readLines(out); log.info(OUT_LINES); @@ -117,13 +116,75 @@ } @Test + public void generateXml() throws Exception { + + File in = getTestFile("text.rst"); + + File out = getOutputTestFile("jrst-RstToXml2.xml"); + + JRST.generate(JRST.Format.XML.name(), in, out, JRST.Overwrite.ALLTIME); + } + + @Test public void generateHtml() throws Exception { File in = getTestFile("text.rst"); File out = getOutputTestFile("jrst-RstToHtml2.html"); - JRST.generate(JRST.TYPE_HTML, in, out, JRST.Overwrite.ALLTIME); + JRST.generate(JRST.Format.HTML.name(), in, out, JRST.Overwrite.ALLTIME); + } + + @Test + public void generateOdt() throws Exception { + + File in = getTestFile("text.rst"); + + File out = getOutputTestFile("jrst-RstToOdt.odt"); + + JRST.generate(JRST.Format.ODT.name(), in, out, JRST.Overwrite.ALLTIME); } -} + + + /* Does not work because "Cells that span multiple rows *and* columns are not supported" in rst2latex*/ + @Test + public void generateLatex() throws Exception { + + File in = getTestFile("text.rst"); + + File out = getOutputTestFile("jrst-RstToLatex.tex"); + + JRST.generate(JRST.Format.LATEX.name(), in, out, JRST.Overwrite.ALLTIME); + } + + @Test + public void generateMan() throws Exception { + + File in = getTestFile("text.rst"); + + File out = getOutputTestFile("jrst-RstToMan.man"); + + JRST.generate(JRST.Format.MAN.name(), in, out, JRST.Overwrite.ALLTIME); + } + + @Test + public void generateS5() throws Exception { + + File in = getTestFile("text.rst"); + + File out = getOutputTestFile("jrst-RstToS5.s5"); + + JRST.generate(JRST.Format.S5.name(), in, out, JRST.Overwrite.ALLTIME); + } + + @Test + public void generatePDF() throws Exception { + + File in = getTestFile("text.rst"); + + File out = getOutputTestFile("jrst-RstToPDF.pdf"); + + JRST.generate(JRST.Format.PDF.name(), in, out, JRST.Overwrite.ALLTIME); + } +} \ No newline at end of file Modified: branches/jrst-docutils-jython/jrst/src/test/java/org/nuiton/jrst/bugs/AdmonitionTest.java =================================================================== --- branches/jrst-docutils-jython/jrst/src/test/java/org/nuiton/jrst/bugs/AdmonitionTest.java 2012-04-16 08:25:37 UTC (rev 642) +++ branches/jrst-docutils-jython/jrst/src/test/java/org/nuiton/jrst/bugs/AdmonitionTest.java 2012-04-24 07:49:14 UTC (rev 643) @@ -27,16 +27,11 @@ import org.apache.commons.io.FileUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.junit.Assert; -import org.junit.BeforeClass; import org.junit.Test; import org.nuiton.jrst.JRST; import org.nuiton.jrst.JRSTAbstractTest; -import org.nuiton.jrst.JRSTCompareDocutils; -import org.nuiton.util.Resource; import java.io.File; -import java.io.IOException; /** * Test concernant les admonitions. @@ -59,7 +54,7 @@ File in = getBugTestFile("testAdminitionInList1787.rst"); File out = getOutputTestFile("jrst-testAdminitionInList1787.html"); // out.deleteOnExit(); - JRST.generate(JRST.TYPE_HTML, in, out, JRST.Overwrite.ALLTIME); + JRST.generate(JRST.Format.HTML.name(), in, out, JRST.Overwrite.ALLTIME); String content = FileUtils.readFileToString(out); Modified: branches/jrst-docutils-jython/jrst/src/test/java/org/nuiton/jrst/bugs/DirectiveTest.java =================================================================== --- branches/jrst-docutils-jython/jrst/src/test/java/org/nuiton/jrst/bugs/DirectiveTest.java 2012-04-16 08:25:37 UTC (rev 642) +++ branches/jrst-docutils-jython/jrst/src/test/java/org/nuiton/jrst/bugs/DirectiveTest.java 2012-04-24 07:49:14 UTC (rev 643) @@ -54,7 +54,7 @@ File in = getBugTestFile("testImages21.rst"); File out = getOutputTestFile("jrst-testImages.html"); // out.deleteOnExit(); - JRST.generate(JRST.TYPE_HTML, in, out, JRST.Overwrite.ALLTIME); + JRST.generate(JRST.Format.HTML.name(), in, out, JRST.Overwrite.ALLTIME); String content = FileUtils.readFileToString(out); assertTrue(content.indexOf("alt=\"alternate text\"") > 0); @@ -76,7 +76,7 @@ File in = getBugTestFile("testContent877.rst"); File out = getOutputTestFile("jrst-testContent.html"); // out.deleteOnExit(); - JRST.generate(JRST.TYPE_HTML, in, out, JRST.Overwrite.ALLTIME); + JRST.generate(JRST.Format.HTML.name(), in, out, JRST.Overwrite.ALLTIME); String content = FileUtils.readFileToString(out); assertTrue(content.indexOf("Table des matières") > 0); @@ -92,7 +92,7 @@ File in = getBugTestFile("testContents.rst"); File out = getOutputTestFile("jrst-testContents.html"); // out.deleteOnExit(); - JRST.generate(JRST.TYPE_HTML, in, out, JRST.Overwrite.ALLTIME); + JRST.generate(JRST.Format.HTML.name(), in, out, JRST.Overwrite.ALLTIME); String content = FileUtils.readFileToString(out); assertTrue(content.indexOf("<b>") > 0); Modified: branches/jrst-docutils-jython/jrst/src/test/java/org/nuiton/jrst/bugs/OptionTest.java =================================================================== --- branches/jrst-docutils-jython/jrst/src/test/java/org/nuiton/jrst/bugs/OptionTest.java 2012-04-16 08:25:37 UTC (rev 642) +++ branches/jrst-docutils-jython/jrst/src/test/java/org/nuiton/jrst/bugs/OptionTest.java 2012-04-24 07:49:14 UTC (rev 643) @@ -24,18 +24,13 @@ */ package org.nuiton.jrst.bugs; -import org.apache.commons.io.FileUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.junit.Assert; -import org.junit.BeforeClass; import org.junit.Test; import org.nuiton.jrst.JRST; import org.nuiton.jrst.JRSTAbstractTest; -import org.nuiton.jrst.JRSTCompareDocutils; import java.io.File; -import java.io.IOException; /** * Test concernant les options. Modified: branches/jrst-docutils-jython/jrst/src/test/java/org/nuiton/jrst/bugs/TableTest.java =================================================================== --- branches/jrst-docutils-jython/jrst/src/test/java/org/nuiton/jrst/bugs/TableTest.java 2012-04-16 08:25:37 UTC (rev 642) +++ branches/jrst-docutils-jython/jrst/src/test/java/org/nuiton/jrst/bugs/TableTest.java 2012-04-24 07:49:14 UTC (rev 643) @@ -25,16 +25,12 @@ package org.nuiton.jrst.bugs; -import junit.framework.Assert; import org.apache.commons.io.FileUtils; -import org.junit.BeforeClass; import org.junit.Test; import org.nuiton.jrst.JRST; import org.nuiton.jrst.JRSTAbstractTest; -import org.nuiton.jrst.JRSTCompareDocutils; import java.io.File; -import java.io.IOException; /** * Test concernant les tables en général. Modified: branches/jrst-docutils-jython/pom.xml =================================================================== --- branches/jrst-docutils-jython/pom.xml 2012-04-16 08:25:37 UTC (rev 642) +++ branches/jrst-docutils-jython/pom.xml 2012-04-24 07:49:14 UTC (rev 643) @@ -40,6 +40,7 @@ <version>1.6-SNAPSHOT</version> <modules> + <module>docutils</module> <module>jrst</module> <!-- Evolution #35: Suppression du module "maven-jrst-plugin" --> <!--<module>maven-jrst-plugin</module>--> @@ -305,6 +306,19 @@ <scope>test</scope> </dependency> + <dependency> + <groupId>org.python</groupId> + <artifactId>jython-standalone</artifactId> + <version>2.5.2</version> + </dependency> + + <!-- Flying Saucer --> + <dependency> + <groupId>org.xhtmlrenderer</groupId> + <artifactId>core-renderer</artifactId> + <version>R8</version> + </dependency> + </dependencies> </dependencyManagement>