Author: jpages Date: 2012-04-30 12:29:41 +0200 (Mon, 30 Apr 2012) New Revision: 652 Url: http://nuiton.org/repositories/revision/jrst/652 Log: La g?\195?\169n?\195?\169ration fonctionne pour tous les nouveaux types (Latex, man, etc...) Modified: branches/jrst-docutils-jython/docutils/src/main/resources/docutils/__run__.py branches/jrst-docutils-jython/jrst/src/main/java/org/nuiton/jrst/JRST.java branches/jrst-docutils-jython/jrst/src/test/java/org/nuiton/jrst/JRSTTest.java Modified: branches/jrst-docutils-jython/docutils/src/main/resources/docutils/__run__.py =================================================================== --- branches/jrst-docutils-jython/docutils/src/main/resources/docutils/__run__.py 2012-04-27 15:28:13 UTC (rev 651) +++ branches/jrst-docutils-jython/docutils/src/main/resources/docutils/__run__.py 2012-04-30 10:29:41 UTC (rev 652) @@ -23,6 +23,7 @@ jarpath = string.replace(jarpath, "__pyclasspath__", filepath) url = URL(jarpath) inStream = url.openStream() + print "jarpath : " + jarpath f = __builtin__.openlegacy(inStream, bufsize) else: f = __builtin__.openlegacy(jarpath, mode, bufsize) @@ -46,11 +47,19 @@ fileout = sys.argv[4] # If Docutils can manage this output format, we call it -from docutils.core import publish_file, default_description +from docutils.core import publish_file listType = ["xml", "html", "odt", "latex", "man", "s5", "xetex"] if typeOutput in listType: - print publish_file( source_path=filein, destination_path=fileout, - writer_name=typeOutput ) + import subprocess + if typeOutput == "odt": + subprocess.call(['rst2odt.py', filein, fileout]) + elif typeOutput == "man": + subprocess.call(['rst2man.py', filein, fileout]) + elif typeOutput == "s5": + subprocess.call(['rst2s5.py', filein, fileout]) + else: + print publish_file( source_path=filein, destination_path=fileout, + writer_name=typeOutput ) else: print "Wrong output format" 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-27 15:28:13 UTC (rev 651) +++ branches/jrst-docutils-jython/jrst/src/main/java/org/nuiton/jrst/JRST.java 2012-04-30 10:29:41 UTC (rev 652) @@ -30,10 +30,21 @@ import java.net.URL; 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; @@ -44,7 +55,6 @@ import org.nuiton.util.FileUtil; import org.nuiton.util.Resource; import org.nuiton.util.StringUtil; -import org.python.modules.zipimport.zipimporter; import org.python.util.JarRunner; /** @@ -96,12 +106,9 @@ /** XSL Stylesheet to transform Docbook into PDF. */ protected static final String docbook2fo = "/docbook/fo/docbook.xsl"; - public static final String PATTERN_TYPE = "xml|xhtml|docbook|html|htmlInnerBody|xdoc|rst|fo|pdf|odt|rtf"; + public static final String PATTERN_TYPE = "xml|docbook|html|htmlInnerBody|xdoc|fo|pdf|odt|rtf|latex|s5|xetex"; - /** HTML output format type */ - public static final String TYPE_HTML = "html"; - - /** HTML output format type */ + /** HTML INNER BODY output format type */ public static final String TYPE_HTML_INNER_BODY = "htmlInnerBody"; /** XDOC output format type */ @@ -111,7 +118,7 @@ public static final String TYPE_DOCBOOK = "docbook"; /** XHTML output format type */ - public static final String TYPE_XHTML = "xhtml"; + public static final String TYPE_HTML = "xhtml"; /** JAVA HELP output format type */ public static final String TYPE_JAVAHELP = "javahelp"; @@ -142,11 +149,10 @@ static { stylesheets = new HashMap<String, String>(); - stylesheets.put(TYPE_HTML, rst2xhtml); stylesheets.put(TYPE_HTML_INNER_BODY, rst2xhtmlInnerBody); stylesheets.put(TYPE_XDOC, rst2xdoc); stylesheets.put(TYPE_DOCBOOK, rst2docbook); - stylesheets.put(TYPE_XHTML, rst2docbook + "," + docbook2xhtml); + stylesheets.put(TYPE_HTML, rst2docbook + "," + docbook2xhtml); stylesheets.put(TYPE_JAVAHELP, rst2docbook + "," + docbook2javahelp); stylesheets.put(TYPE_HTMLHELP, rst2docbook + "," + docbook2htmlhelp); stylesheets.put(TYPE_RST, xml2rst); @@ -155,11 +161,10 @@ stylesheets.put(TYPE_PDF, rst2docbook + "," + docbook2fo); mimeType = new HashMap<String, String>(); - mimeType.put(TYPE_HTML, "text/html"); mimeType.put(TYPE_HTML_INNER_BODY, "text/html"); mimeType.put(TYPE_XDOC, "text/xml"); mimeType.put(TYPE_DOCBOOK, "text/xml"); - mimeType.put(TYPE_XHTML, "text/html"); + mimeType.put(TYPE_HTML, "text/html"); mimeType.put(TYPE_JAVAHELP, "text/plain"); mimeType.put(TYPE_HTMLHELP, "text/html"); mimeType.put(TYPE_RST, "text/plain"); @@ -277,9 +282,7 @@ // generation PDF if (outputType.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)); @@ -293,7 +296,7 @@ // Step 4: Setup JAXP using identity transformer TransformerFactory factory = TransformerFactory .newInstance(); - Transformer transformer = factory.newTransformer(); // identity + Transformer transformer = factory.newTransformer(); // identity // transformer // Step 5: Setup input and output for XSLT transformation @@ -307,7 +310,7 @@ // Step 6: Start XSLT transformation and FOP processing transformer.transform(src, res); - outPDF.close(); */ + outPDF.close(); } else { // write generated document writer.write(result); @@ -435,7 +438,9 @@ docutilsPath = docutilsPath.replaceAll("!", ""); docutilsPath = docutilsPath.replaceAll("file:", ""); + // Only for debugging 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; 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-27 15:28:13 UTC (rev 651) +++ branches/jrst-docutils-jython/jrst/src/test/java/org/nuiton/jrst/JRSTTest.java 2012-04-30 10:29:41 UTC (rev 652) @@ -35,7 +35,6 @@ import org.junit.Assert; import org.junit.Ignore; import org.junit.Test; -import org.nuiton.util.Resource; /** * @@ -146,22 +145,23 @@ 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*/ + /* Does not work for 'text.rst', cause this message with rst2latex : + "Cells that span multiple rows *and* columns are not supported"*/ @Test public void generateLatex() throws Exception { - File in = getTestFile("text.rst"); + File in = getTestFile("test4.rst"); File out = getOutputTestFile("jrst-RstToLatex.tex"); JRST.generate(JRST.Format.LATEX.name(), in, out, JRST.Overwrite.ALLTIME); } + /* Does not work for 'text.rst', the header causes an 'NotImplementedError' */ @Test public void generateMan() throws Exception { - File in = getTestFile("text.rst"); + File in = getTestFile("test4.rst"); File out = getOutputTestFile("jrst-RstToMan.man");