r669 - in branches/jrst-docutils-jython: . docutils/src/main/resources/docutils doxia-module-jrst/src/main/java/org/nuiton/jrst jrst jrst/src/main/java/org jrst/src/main/java/org/dom4j jrst/src/main/java/org/dom4j/io jrst/src/main/java/org/nuiton/jrst jrst/src/main/java/org/nuiton/jrst/convertisor jrst/src/main/resources/xsl jrst/src/site jrst/src/test/java/org/nuiton/jrst jrst/src/test/java/org/nuiton/jrst/bugs jrst/src/test/resources jrst-doc/src/site jrst-doc/src/site/en/rst jrst-doc/src/s
Author: jpages Date: 2012-05-23 16:35:21 +0200 (Wed, 23 May 2012) New Revision: 669 Url: http://nuiton.org/repositories/revision/jrst/669 Log: Correction de la g?\195?\169n?\195?\169ration de PDF en utilisant IText et nouveaux tests pour les images dans les pdfs. Added: branches/jrst-docutils-jython/jrst/src/main/java/org/dom4j/ branches/jrst-docutils-jython/jrst/src/main/java/org/dom4j/io/ branches/jrst-docutils-jython/jrst/src/main/java/org/dom4j/io/MyDocumentInputSource.java branches/jrst-docutils-jython/jrst/src/main/java/org/nuiton/jrst/JRSTUserAgent.java branches/jrst-docutils-jython/jrst/src/test/resources/docDeveloppeur.rst Modified: branches/jrst-docutils-jython/docutils/src/main/resources/docutils/__run__.py branches/jrst-docutils-jython/doxia-module-jrst/src/main/java/org/nuiton/jrst/JrstParser.java branches/jrst-docutils-jython/jrst-doc/src/site/en/rst/devel/developerDoc.rst branches/jrst-docutils-jython/jrst-doc/src/site/en/rst/index.rst branches/jrst-docutils-jython/jrst-doc/src/site/en/rst/user/index.rst branches/jrst-docutils-jython/jrst-doc/src/site/rst/index.rst branches/jrst-docutils-jython/jrst-doc/src/site/rst/user/index.rst branches/jrst-docutils-jython/jrst-doc/src/site/site_en.xml branches/jrst-docutils-jython/jrst-doc/src/site/site_fr.xml 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/convertisor/DocUtils2RST.java branches/jrst-docutils-jython/jrst/src/main/resources/xsl/rst2xhtml.xsl branches/jrst-docutils-jython/jrst/src/site/site_en.xml branches/jrst-docutils-jython/jrst/src/site/site_fr.xml branches/jrst-docutils-jython/jrst/src/test/java/org/nuiton/jrst/JRSTGeneratorTest.java branches/jrst-docutils-jython/jrst/src/test/java/org/nuiton/jrst/bugs/DirectiveTest.java branches/jrst-docutils-jython/pom.xml Modified: branches/jrst-docutils-jython/docutils/src/main/resources/docutils/__run__.py =================================================================== --- branches/jrst-docutils-jython/docutils/src/main/resources/docutils/__run__.py 2012-05-21 07:17:23 UTC (rev 668) +++ branches/jrst-docutils-jython/docutils/src/main/resources/docutils/__run__.py 2012-05-23 14:35:21 UTC (rev 669) @@ -12,18 +12,19 @@ # Define the function jaropen which will be able to read into the jar. # Examples : # If the value of the resourcePath is - # '/home/user/workspace/jrst-docutils-jython/jrst/src/test/resources/text.rst', + # '/home/user/workspace/jrst/src/test/resources/text.rst', # the classic function "open" can be used, but if the value is # '__pyclasspath__/docutils/writers/html4css1/html4css1.css', # python doesn't be able to find the resource, so it must have the # absolute path to the jar to read it with jaropen after. + # ex: jar:file:/home/user/workspace/jrst/docutils/docutils.jar! def jaropen(resourcePath, mode, bufsize=-1): if "__pyclasspath__" in resourcePath: # Replace the relative resource filepath by the absolute path docutilsAbsolutePath = "jar:file:" + os.path.dirname(docutilsPath) + "!" resourcePath = string.replace(resourcePath, "__pyclasspath__", docutilsAbsolutePath) # Get the url and open a stream to access to the resource - # /!\ Warning : we use a deprecated function, it will could be a problem later + # /!\ Warning : we use a deprecated function, it could be a problem later url = URL(resourcePath) inStream = url.openStream() f = __builtin__.openlegacy(inStream, bufsize) @@ -56,4 +57,4 @@ from docutils.core import publish_file publish_file( source_path=filein, writer_name=typeOutput ) else: - print "Wrong output format" + print "Wrong output format" \ No newline at end of file Modified: branches/jrst-docutils-jython/doxia-module-jrst/src/main/java/org/nuiton/jrst/JrstParser.java =================================================================== --- branches/jrst-docutils-jython/doxia-module-jrst/src/main/java/org/nuiton/jrst/JrstParser.java 2012-05-21 07:17:23 UTC (rev 668) +++ branches/jrst-docutils-jython/doxia-module-jrst/src/main/java/org/nuiton/jrst/JrstParser.java 2012-05-23 14:35:21 UTC (rev 669) @@ -49,7 +49,6 @@ * @plexus.component role="org.apache.maven.doxia.parser.Parser" role-hint="jrst" */ public class JrstParser extends XdocParser { - protected static Log log = LogFactory.getLog(JRST.class); @Override public void parse(Reader source, Sink sink) throws ParseException { Modified: branches/jrst-docutils-jython/jrst/pom.xml =================================================================== --- branches/jrst-docutils-jython/jrst/pom.xml 2012-05-21 07:17:23 UTC (rev 668) +++ branches/jrst-docutils-jython/jrst/pom.xml 2012-05-23 14:35:21 UTC (rev 669) @@ -132,13 +132,19 @@ <artifactId>jython-standalone</artifactId> </dependency> - <!-- Flying Saucer --> - <!--dependency> + <!-- itext --> + <dependency> <groupId>org.xhtmlrenderer</groupId> <artifactId>core-renderer</artifactId> <version>R8</version> - </dependency--> + </dependency> + <dependency> + <groupId>com.lowagie</groupId> + <artifactId>itext</artifactId> + <version>2.0.8</version> + </dependency> + </dependencies> <!-- ************************************************************* --> Added: branches/jrst-docutils-jython/jrst/src/main/java/org/dom4j/io/MyDocumentInputSource.java =================================================================== --- branches/jrst-docutils-jython/jrst/src/main/java/org/dom4j/io/MyDocumentInputSource.java (rev 0) +++ branches/jrst-docutils-jython/jrst/src/main/java/org/dom4j/io/MyDocumentInputSource.java 2012-05-23 14:35:21 UTC (rev 669) @@ -0,0 +1,16 @@ +package org.dom4j.io; + +import org.dom4j.Document; + +/** + * Created with IntelliJ IDEA. + * User: jpages + * Date: 22/05/12 + * Time: 16:36 + * To change this template use File | Settings | File Templates. + */ +public class MyDocumentInputSource extends DocumentInputSource { + public MyDocumentInputSource(Document document) { + super(document); + } +} 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-05-21 07:17:23 UTC (rev 668) +++ branches/jrst-docutils-jython/jrst/src/main/java/org/nuiton/jrst/JRST.java 2012-05-23 14:35:21 UTC (rev 669) @@ -30,24 +30,16 @@ 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.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; 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.DocumentException; import org.dom4j.DocumentHelper; +import org.dom4j.io.MyDocumentInputSource; import org.nuiton.i18n.I18n; import org.nuiton.i18n.init.ClassPathI18nInitializer; import org.nuiton.jrst.convertisor.DocUtils2RST; @@ -57,8 +49,7 @@ import org.nuiton.util.Resource; import org.nuiton.util.StringUtil; import org.python.util.PythonInterpreter; -import org.xml.sax.InputSource; -import org.xml.sax.XMLReader; +import org.xhtmlrenderer.pdf.ITextRenderer; /** * FIXME: 'JRST --help' doesn't work, but 'JRST --help toto' work :( FIXME: @@ -92,13 +83,6 @@ NEVER, IFNEWER, ALLTIME } - /* - // Formats created with Docutils and Jython - public enum Docutils_Formats { - 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); @@ -118,9 +102,6 @@ /** 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"; - /** XSL Stylesheet to transform Docbook into PDF. */ protected static final String docbook2fo = "/docbook/fo/docbook.xsl"; @@ -183,7 +164,7 @@ stylesheets.put(TYPE_RST, ""); //stylesheets.put(TYPE_ODT, rst2docbook + "," + docbook2odf); stylesheets.put(TYPE_FO, rst2docbook + "," + docbook2fo); - stylesheets.put(TYPE_PDF, rst2docbook + "," + docbook2fo); + stylesheets.put(TYPE_PDF, rst2xhtml); mimeType = new HashMap<String, String>(); mimeType.put(TYPE_HTML, "text/html"); @@ -298,51 +279,53 @@ + ", because already exists"); } else { // Out - FileOutputStream outputStream = new FileOutputStream(fileOut); - OutputStreamWriter writer = new OutputStreamWriter(outputStream, outputEncoding); + OutputStream outputStream = new FileOutputStream(fileOut); // Generate - String result = generateString(outputType, fileIn); + Document result = generateDocument(outputType, fileIn); - fileOut.getAbsoluteFile().getParentFile().mkdirs(); - // generation PDF if (outputType.equals("pdf")) { - FopFactory fopFactory = FopFactory.newInstance(); + try { + DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); + builder.setEntityResolver(result.getEntityResolver()); + MyDocumentInputSource source = new MyDocumentInputSource(result); + org.w3c.dom.Document doc = builder.parse(source); - OutputStream outPDF = new BufferedOutputStream(new FileOutputStream( - fileOut)); + ITextRenderer renderer = new ITextRenderer(); - FOUserAgent userAgent = fopFactory.newFOUserAgent(); + // Settings to resolve paths with the JRST User Agent + String absolutePath = fileIn.getParentFile().getAbsolutePath() + "/"; + JRSTUserAgent jrstUserAgent = new JRSTUserAgent(absolutePath); + jrstUserAgent.setBaseURL(absolutePath); + renderer.getSharedContext().setUserAgentCallback(jrstUserAgent); + jrstUserAgent.setSharedContext(renderer.getSharedContext()); - // Step 3: Construct fop with desired output format - Fop fop = fopFactory.newFop(MimeConstants.MIME_PDF, - userAgent, outPDF); + // Generation of the pdf file + renderer.setDocument(doc, null); + renderer.layout(); + renderer.createPDF(outputStream); + } catch (Exception eee) { + log.error("Failed to write PDF", eee); + } finally { + outputStream.close(); + } - // 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)); - - // 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); - - outPDF.close(); } else { - // write generated document - writer.write(result); + OutputStreamWriter writer = null; + try { + writer = new OutputStreamWriter(outputStream, outputEncoding); - writer.close(); + // write generated document + writer.write(result.asXML()); + }catch (Exception eee) { + log.error("Failed to write " + outputType + " file", eee); + } finally { + if (writer != null) { + writer.close(); + } + } } } @@ -392,15 +375,21 @@ */ public static String generateString(String outputType, File in) throws Exception { + return generateDocument(outputType, in).asXML(); + } + /** + * + * @param outputType + * @param in + * @throws Exception + */ + public static Document generateDocument(String outputType, File in) throws Exception { + Document doc = generateXML(in); // Sortie vers rst - if (outputType.equals(TYPE_RST)){ - return generateRST(doc); - } else if (!StringUtils.isEmpty(outputType)) { - doc = applyXsls(doc, outputType); - } - return doc.asXML(); + doc = applyXsls(doc, outputType); + return doc; } private static Document applyXsls(Document doc, String xslListOrOutType) throws IOException, TransformerException { Added: branches/jrst-docutils-jython/jrst/src/main/java/org/nuiton/jrst/JRSTUserAgent.java =================================================================== --- branches/jrst-docutils-jython/jrst/src/main/java/org/nuiton/jrst/JRSTUserAgent.java (rev 0) +++ branches/jrst-docutils-jython/jrst/src/main/java/org/nuiton/jrst/JRSTUserAgent.java 2012-05-23 14:35:21 UTC (rev 669) @@ -0,0 +1,162 @@ +package org.nuiton.jrst; + +import com.lowagie.text.Image; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.xhtmlrenderer.extend.UserAgentCallback; +import org.xhtmlrenderer.layout.SharedContext; +import org.xhtmlrenderer.pdf.ITextFSImage; +import org.xhtmlrenderer.resource.CSSResource; +import org.xhtmlrenderer.resource.ImageResource; +import org.xhtmlrenderer.resource.XMLResource; +import org.xhtmlrenderer.swing.NaiveUserAgent; +import org.xhtmlrenderer.util.XRLog; + +import java.io.File; +import java.net.MalformedURLException; +import java.net.URI; +import java.net.URL; + +/** + * Created with IntelliJ IDEA. + * User: jpages + * Date: 22/05/12 + * Time: 17:38 + * To change this template use File | Settings | File Templates. + */ +public class JRSTUserAgent implements UserAgentCallback { + + public static final String THIS_DIRECTORY = "./"; + + public static final String PREVIOUS_DIRECTORY = "../"; + + /** to use log facility, just put in your code: log.info("..."); */ + protected static Log log = LogFactory.getLog(JRSTUserAgent.class); + + protected NaiveUserAgent delegate; + + // Resources path + protected String path; + + private SharedContext sharedContext; + + public JRSTUserAgent(String path) { + this.path = path; + this.delegate = new NaiveUserAgent(); + } + + + @Override + public CSSResource getCSSResource(String uri) { + return delegate.getCSSResource(uri); + } + + @Override + public ImageResource getImageResource(String uri) { + uri = resolveURI(uri); + return createImageResource(uri); + } + + protected ImageResource createImageResource(String uri) { + ImageResource imageResource = null; + + try { + // Gets the image with its url + URL source = new URI(uri).toURL(); + Image image = Image.getInstance(source); + + // Sets the scale of the image + scaleToOutputResolution(image); + + ITextFSImage iTextFSImage = new ITextFSImage(image); + imageResource = new ImageResource(iTextFSImage); + } catch (Exception eee) { + log.error("Failed to create image resource", eee); + } + + return imageResource; + } + + @Override + public XMLResource getXMLResource(String uri) { + return delegate.getXMLResource(uri); + } + + @Override + public byte[] getBinaryResource(String uri) { + return delegate.getBinaryResource(uri); + } + + @Override + public boolean isVisited(String uri) { + return delegate.isVisited(uri); + } + + @Override + public void setBaseURL(String url) { + delegate.setBaseURL(url); + } + + @Override + public String getBaseURL() { + return delegate.getBaseURL(); + } + + public String resolveURI(String uri) { + if (uri == null) return null; + String ret = null; + if (path == null) { + try { + URL result = new URL(uri); + setBaseURL(result.toExternalForm()); + } catch (MalformedURLException e) { + try { + setBaseURL(new File(".").toURI().toURL().toExternalForm()); + } catch (Exception e1) { + XRLog.exception("The default NaiveUserAgent doesn't know how to resolve the base URL for " + uri); + return null; + } + } + } + + try { + return new URL(uri).toString(); + } catch (MalformedURLException e) { + XRLog.load("Could not read " + uri + " as a URL; may be relative. Testing using parent URL " + path); + String ResourcePath = path; + try { + // Transforms relative path to use it after + if (uri.startsWith(THIS_DIRECTORY)) { + uri = uri.replace(THIS_DIRECTORY, ""); + } else if ((uri.startsWith(PREVIOUS_DIRECTORY))) { + while (uri.startsWith(PREVIOUS_DIRECTORY)) { + uri = uri.replace(PREVIOUS_DIRECTORY, ""); + // ResourcePath becomes the path of the parent directory + ResourcePath = path.substring(0, path.lastIndexOf("/", path.length()-2)); + ResourcePath = ResourcePath + "/"; + } + } + // Builds the full resource path + File file = new File(ResourcePath + uri); + URL result = file.toURI().toURL(); + ret = result.toString(); + } catch (Exception e1) { + XRLog.exception("The default NaiveUserAgent cannot resolve the URL " + uri + " with base URL " + path); + } + } + return ret; + } + + private void scaleToOutputResolution(Image image) { + float factor = this.sharedContext.getDotsPerPixel(); + image.scaleAbsolute(image.getPlainWidth() * factor, image.getPlainHeight() * factor); + } + + public SharedContext getSharedContext() { + return this.sharedContext; + } + + public void setSharedContext(SharedContext sharedContext) { + this.sharedContext = sharedContext; + } +} Modified: branches/jrst-docutils-jython/jrst/src/main/java/org/nuiton/jrst/convertisor/DocUtils2RST.java =================================================================== --- branches/jrst-docutils-jython/jrst/src/main/java/org/nuiton/jrst/convertisor/DocUtils2RST.java 2012-05-21 07:17:23 UTC (rev 668) +++ branches/jrst-docutils-jython/jrst/src/main/java/org/nuiton/jrst/convertisor/DocUtils2RST.java 2012-05-23 14:35:21 UTC (rev 669) @@ -506,6 +506,8 @@ @Override public String composeFootnoteReference(Element e) { + String result = indent(e.getText(), level); + log.warn("composeFootnoteReference :\n" + result); return EMPTY_STRING; } Modified: branches/jrst-docutils-jython/jrst/src/main/resources/xsl/rst2xhtml.xsl =================================================================== --- branches/jrst-docutils-jython/jrst/src/main/resources/xsl/rst2xhtml.xsl 2012-05-21 07:17:23 UTC (rev 668) +++ branches/jrst-docutils-jython/jrst/src/main/resources/xsl/rst2xhtml.xsl 2012-05-23 14:35:21 UTC (rev 669) @@ -489,7 +489,7 @@ </xsl:template> <xsl:template match="footnote"> - <table class="footnote" frame="void" id="{@id}" rules="none"> + <table class="footnote" frame="void" id="{@ids}" rules="none"> <colgroup> <col class="label"/> <col/> @@ -497,7 +497,7 @@ <tbody valign="top"> <tr> <td class="label"> - <a class="backref" href="#{@backrefs}" name="{id}"> + <a class="backref" href="#{@backrefs}" name="{@ids}"> [<xsl:value-of select="label"/>] </a> </td> @@ -513,9 +513,9 @@ </xsl:template> <xsl:template match="footnote_reference"> - <a class="footnote_reference" href="#{@refid}" id="{@id}" name="{@id}"> + <a class="footnote_reference" href="#{@refid}" id="{@ids}" name="{@ids}"> [<xsl:value-of select="text()"/>] </a> </xsl:template> -</xsl:stylesheet> \ No newline at end of file +</xsl:stylesheet> Modified: branches/jrst-docutils-jython/jrst/src/site/site_en.xml =================================================================== --- branches/jrst-docutils-jython/jrst/src/site/site_en.xml 2012-05-21 07:17:23 UTC (rev 668) +++ branches/jrst-docutils-jython/jrst/src/site/site_en.xml 2012-05-23 14:35:21 UTC (rev 669) @@ -25,7 +25,22 @@ --> <project name="${project.name}"> + <skin> + <groupId>org.apache.maven.skins</groupId> + <artifactId>maven-fluido-skin</artifactId> + <version>1.2.1</version> + </skin> + <custom> + <fluidoSkin> + <topBarEnabled>true</topBarEnabled> + <googleSearch/> + <sideBarEnabled>false</sideBarEnabled> + <searchEnabled>true</searchEnabled> + <sourceLineNumbersEnabled>true</sourceLineNumbersEnabled> + </fluidoSkin> + </custom> + <bannerLeft> <name>Java ReStructuredText parser</name> <href>/</href> Modified: branches/jrst-docutils-jython/jrst/src/site/site_fr.xml =================================================================== --- branches/jrst-docutils-jython/jrst/src/site/site_fr.xml 2012-05-21 07:17:23 UTC (rev 668) +++ branches/jrst-docutils-jython/jrst/src/site/site_fr.xml 2012-05-23 14:35:21 UTC (rev 669) @@ -25,7 +25,24 @@ --> <project name="${project.name}"> + <skin> + <groupId>org.apache.maven.skins</groupId> + <artifactId>maven-fluido-skin</artifactId> + <version>1.2.1</version> + </skin> + <custom> + <fluidoSkin> + <topBarEnabled>true</topBarEnabled> + <googleSearch/> + <sideBarEnabled>false</sideBarEnabled> + <searchEnabled>true</searchEnabled> + <sourceLineNumbersEnabled>true</sourceLineNumbersEnabled> + </fluidoSkin> + </custom> + + + <bannerLeft> <name>Java ReStructuredText parser</name> <href>/</href> 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-05-21 07:17:23 UTC (rev 668) +++ branches/jrst-docutils-jython/jrst/src/test/java/org/nuiton/jrst/JRSTGeneratorTest.java 2012-05-23 14:35:21 UTC (rev 669) @@ -73,11 +73,23 @@ log.info("Testing RST to HTML (test.rst)..."); } - String test1 = getOutputTestPath("jrst-RstToHtml2.html"); + String test1 = getOutputTestPath("jrst-RstToHtml.html"); JRST.main(new String[]{"-t", "html", "--force", "-o", test1, getResourcesTestPath()}); } - + @Test + public void testRstToHtml2() throws Exception { + + if (log.isInfoEnabled()) { + log.info("Testing RST to HTML (docDeveloppeur.rst) ..."); + } + + String test1 = getOutputTestPath("jrst-RstToHtml2.html"); + JRST.main(new String[]{"-t", "html", "--force", "-o", test1, getTestFile("docDeveloppeur.rst").getPath()}); + } + + + @Test public void testRstToDocbook() throws Exception { if (log.isInfoEnabled()) { @@ -153,12 +165,21 @@ public void testRstToPDF() throws Exception { if (log.isInfoEnabled()) { - log.info("Testing RST to PDF (frEntier.rst) ..."); + log.info("Testing RST to PDF (test.rst) ..."); } String test1 = getOutputTestPath("jrst-RstToPDF.pdf"); - // Doesn't work with test.rst, so we use an other file - JRST.main(new String[]{"-t", "pdf", "--force", "-o", test1, getTestFile("test5.rst").getPath()}); - //JRST.main(new String[]{"-t", "pdf", "--force", "-o", test1, getResourcesTestPath()}); + JRST.main(new String[]{"-t", "pdf", "--force", "-o", test1, getResourcesTestPath()}); } + + @Test + public void testRstToPDF2() throws Exception { + + if (log.isInfoEnabled()) { + log.info("Testing RST to PDF (docDeveloppeur.rst) ..."); + } + + String test1 = getOutputTestPath("jrst-RstToPDF2.pdf"); + JRST.main(new String[]{"-t", "pdf", "--force", "-o", test1, getTestFile("docDeveloppeur.rst").getPath()}); + } } 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-05-21 07:17:23 UTC (rev 668) +++ branches/jrst-docutils-jython/jrst/src/test/java/org/nuiton/jrst/bugs/DirectiveTest.java 2012-05-23 14:35:21 UTC (rev 669) @@ -55,7 +55,7 @@ File out = getOutputTestFile("jrst-testImages.html"); // out.deleteOnExit(); JRST.generate(JRST.TYPE_HTML, in, out, JRST.Overwrite.ALLTIME); - + String content = FileUtils.readFileToString(out, JRST.UTF_8); assertTrue(content.indexOf("alt=\"alternate text\"") > 0); assertTrue(content.indexOf("width=\"200px\"") > 0); Added: branches/jrst-docutils-jython/jrst/src/test/resources/docDeveloppeur.rst =================================================================== --- branches/jrst-docutils-jython/jrst/src/test/resources/docDeveloppeur.rst (rev 0) +++ branches/jrst-docutils-jython/jrst/src/test/resources/docDeveloppeur.rst 2012-05-23 14:35:21 UTC (rev 669) @@ -0,0 +1,153 @@ +.. - +.. * #%L +.. * JRst :: Documentation +.. * +.. * $Id: docDeveloppeur.rst 668 2012-05-21 07:17:23Z jpages $ +.. * $HeadURL: http://svn.nuiton.org/svn/jrst/branches/jrst-docutils-jython/jrst-doc/src/si... $ +.. * %% +.. * Copyright (C) 2009 - 2010 CodeLutin +.. * %% +.. * This program is free software: you can redistribute it and/or modify +.. * it under the terms of the GNU Lesser General Public License as +.. * published by the Free Software Foundation, either version 3 of the +.. * License, or (at your option) any later version. +.. * +.. * This program is distributed in the hope that it will be useful, +.. * but WITHOUT ANY WARRANTY; without even the implied warranty of +.. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +.. * GNU General Lesser Public License for more details. +.. * +.. * You should have received a copy of the GNU General Lesser Public +.. * License along with this program. If not, see +.. * <http://www.gnu.org/licenses/lgpl-3.0.html>. +.. * #L% +.. - + +========================= +Documentation développeur +========================= + +.. contents:: Sommaire + +Le diagramme de Class +===================== + +.. image:: ./schemas/diagrammeClass.png + :alt: Diagramme de classes + :align: center + :width: 400 px + +La classe **JRST** contient la méthode main(), elle gère les options, la lecture et l'écriture des fichiers. Elle appelle dans un premier temps la classe **PythonInterpreter** de Jython_ permettant d'exécuter les scripts en Python de DocUtils_ pour générer un fichier XML intermédiaire. Ensuite, il ne reste qu'à appliquer le XSL désiré (si besoin) grâce à la classe **JRSTGenerator**. + +La génération +============= + +.. image:: ../resources/schemas/diagrammeGeneration.png + :alt: Arbre des différentes générations possibles + :align: center + :width: 600 px + + +Référence : + + * xml2rst.xsl (convertion de xml de docutils vers rst) : http://www.merten-home.de/FreeSoftware/xml2rst + * dn2dbk.xsl (convertion de xml de docutils vers docbook) : http://membres.lycos.fr/ebellot/dn2dbk + * les xsl de nwalsh (convertion de docbook vers FO et xhtml) : http://nwalsh.com + + * XMLmind (convertion de FO vers ODT et RTF) : http://www.xmlmind.com/foconverter/what_is_xfc.html + * FOP (convertion de FO vers PDF) : http://xmlgraphics.apache.org/fop + + +Exemple d'utilisation +===================== + + +L'on souhaite convertir le document rst (text.rst) suivant en html (text.html) : + +:: + + ===== + Titre + ===== + + :Author: Letellier Sylvain + + .. Attention:: texte à être réinterprété comme un fichier rst indépendant + ceci est considéré comme un **paragraphe** + +On utilise donc la commande suivante:: + + JRST -t html -o text.html text.rst + +Ce diagramme de séquence décrit le fonctionnement du parseur tout au long de la génération : + +.. image:: ./schemas/diagrammeSequence.png + :alt: Diagramme de séquence d'une génération + :align: center + :width: 600 px + + +La Classe **JRSTGenerator**, grâce au fichier XSL rst2xhtml.xsl, renvoie le fichier html suivant:: + + <?xml version="1.0" encoding="UTF-8"?> + <html xmlns="http://www.w3.org/TR/xhtml1/strict"> + <head> + <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/> + <meta name="generator" content="JRST http://jrst.labs.libre-entreprise.org/"/> + <title>Titre</title> + </head> + <body> + <h1>Titre</h1> + <table class="docinfo" frame="void" rules="none"> + <col class="docinfo-name"/> + <col class="docinfo-content"/> + <tbody valign="top"> + <tr> + <th class="docpatterninfo-name">author :</th> + <td class="docinfo-content">Letellier Sylvain</td> + </tr> + </tbody> + </table> + <div class="attention"> + <p class="title">attention :</p> + <p class="body"> + <p>texte à être réinterprété comme un fichier rst indépendant + ceci est considéré comme un <strong>paragraphe</strong></p> + </p> + </div> + </body> + </html> + +Qui affiche la page (un CSS [1]_ à été ajouté pour la mise en forme) : + +.. topic:: Titre + + :Author: Letellier Sylvain + + .. Attention:: texte à être réinterprété comme un fichier rst indépendant + ceci est considéré comme un **paragraphe** + +Utilisation de XSL externe +========================== + +JRST propose de transformer le XML de docutils_ avec des fichiers XSL [2]_ externe. +Pour cela, il faut utiliser la commande:: + + JRST -x fichierXSL, fichierXSL2 fichierRST + +ou:: + + JRST --xslFile fichierXSL, fichierXSL2 fichierRST + +JRST traitera le fichierRST, le XML de DocUtils_ qui est retourné sera transformé par la Class JRSTgenerator +en commençant par le fichierXSL puis par le fichierXSL2... + +.. [1] `Cascading Style Sheets`_ +.. [2] Une documentation sur le XSL est diponible ici_. + +.. _ici: ./presentationXSL.html +.. _Cascading Style Sheets: http://fr.wikipedia.org/wiki/Feuilles_de_style_en_cascade +.. _RST: http://docutils.sourceforge.net/rst.html +.. _DocUtils: http://docutils.sourceforge.net/docs/ref/doctree.html +.. _Jython: http://jython.org/index.html + Modified: branches/jrst-docutils-jython/jrst-doc/src/site/en/rst/devel/developerDoc.rst =================================================================== --- branches/jrst-docutils-jython/jrst-doc/src/site/en/rst/devel/developerDoc.rst 2012-05-21 07:17:23 UTC (rev 668) +++ branches/jrst-docutils-jython/jrst-doc/src/site/en/rst/devel/developerDoc.rst 2012-05-23 14:35:21 UTC (rev 669) @@ -33,9 +33,6 @@ |classDiagramme| -La classe **JRST** contient la méthode main(), elle gère les options, la lecture et l'écriture des fichiers. Elle appelle dans un premier temps la classe **PythonInterpreter** de Jython_ permettant d'exécuter les scripts en Python de DocUtils_ pour générer un fichier XML intermédiaire. Ensuite, il ne reste qu'à appliquer le XSL désiré (si besoin) grâce à la classe **JRSTGenerator**. - - **JRST** Class contents main() method, it's looking after options, files reading and writing. Iinitially, it calls Jython_ class **PythonInterpreter** which allows to execute DocUtils' Python script to generate an intermediate file. Then it only remains to apply the wish XSL (if needed) by using **JRSTGenerator** Class. Generation Modified: branches/jrst-docutils-jython/jrst-doc/src/site/en/rst/index.rst =================================================================== --- branches/jrst-docutils-jython/jrst-doc/src/site/en/rst/index.rst 2012-05-21 07:17:23 UTC (rev 668) +++ branches/jrst-docutils-jython/jrst-doc/src/site/en/rst/index.rst 2012-05-23 14:35:21 UTC (rev 669) @@ -60,11 +60,11 @@ This command converts myfile.rst toward XML file, displayed to the standard output (console). Several options are available : --o file,--outFile=file to write toward a file. --t format,--outType format to specify exit format, so using generation XSL_ file(s). Several formats are available xhtml, docbook, xml, HTML, xdoc, rst, pdf, odt, rtf. --x xslFile,--xslFile xslFile to specify generation XSL_ file at using. ---force to overwrite, if file exists, it will be replaced by the new one. ---help to display available options : +-o file, --outFile=file To write toward a file. +-t format, --outType format To specify exit format, so using generation XSL_ file(s). Several formats are available xhtml, docbook, xml, HTML, xdoc, rst, pdf, odt, rtf. +-x xslFile, --xslFile xslFile To specify generation XSL_ file at using. +--force To overwrite, if file exists, it will be replaced by the new one. +--help To display available options : :: Modified: branches/jrst-docutils-jython/jrst-doc/src/site/en/rst/user/index.rst =================================================================== --- branches/jrst-docutils-jython/jrst-doc/src/site/en/rst/user/index.rst 2012-05-21 07:17:23 UTC (rev 668) +++ branches/jrst-docutils-jython/jrst-doc/src/site/en/rst/user/index.rst 2012-05-23 14:35:21 UTC (rev 669) @@ -60,11 +60,11 @@ This command converts myfile.rst toward XML file, displayed to the standard output (console). Several options are available : --o file,--outFile=file to write toward a file. --t format,--outType format to specify exit format, so using generation XSL_ file(s). Several formats are available xhtml, docbook, xml, HTML, xdoc, rst, pdf, odt, rtf. --x xslFile,--xslFile xslFile to specify generation XSL_ file at using. ---force to overwrite, if file exists, it will be replaced by the new one. ---help to display available options : +-o file, --outFile=file To write toward a file. +-t format, --outType format To specify exit format, so using generation XSL_ file(s). Several formats are available xhtml, docbook, xml, HTML, xdoc, rst, pdf, odt, rtf. +-x xslFile, --xslFile xslFile To specify generation XSL_ file at using. +--force To overwrite, if file exists, it will be replaced by the new one. +--help To display available options : :: Modified: branches/jrst-docutils-jython/jrst-doc/src/site/rst/index.rst =================================================================== --- branches/jrst-docutils-jython/jrst-doc/src/site/rst/index.rst 2012-05-21 07:17:23 UTC (rev 668) +++ branches/jrst-docutils-jython/jrst-doc/src/site/rst/index.rst 2012-05-23 14:35:21 UTC (rev 669) @@ -61,11 +61,11 @@ Cette commande aura pour effet de convertir le fichier myfile.rst en XML qui sera affiché sur la sortie standard (console). Plusieurs options sont disponibles : --o file,--outFile=file pour rediriger la sortie vers un fichier. --t format,--outType format pour préciser un format de sortie, donc utiliser un ou des fichiers XSL_ de génération. Plusieurs formats sont disponibles xhtml, docbook, xml, html, xdoc, rst, pdf, odt, rtf. --x xslFile,--xslFile xslFile sert à préciser le fichier xsl de génération à utiliser. ---force forcer l'écriture d'un fichier, si le fichier de sortie existe, il sera remplacé. ---help pour afficher les options disponibles : +-o file, --outFile=file Pour rediriger la sortie vers un fichier. +-t format, --outType format Pour préciser un format de sortie, donc utiliser un ou des fichiers XSL_ de génération. Plusieurs formats sont disponibles xhtml, docbook, xml, html, xdoc, rst, pdf, odt, rtf. +-x xslFile, --xslFile xslFile Sert à préciser le fichier xsl de génération à utiliser. +--force Forcer l'écriture d'un fichier, si le fichier de sortie existe, il sera remplacé. +--help Pour afficher les options disponibles : :: @@ -95,7 +95,7 @@ http://maven-site.nuiton.org/jrst/maven-jrst-plugin. Il permet l'utilisation depuis Maven_ de JRst. -.. [1] Seul les formats html, xhtml, DocBook_, xdoc et pdf sont disponible pour le moment. +.. [1] Seuls les formats html, xhtml, DocBook_, xdoc et pdf sont disponibles pour le moment. .. _reStructuredText: ./user/presentationRST.html .. _RST: ./user/presentationRST.html Modified: branches/jrst-docutils-jython/jrst-doc/src/site/rst/user/index.rst =================================================================== --- branches/jrst-docutils-jython/jrst-doc/src/site/rst/user/index.rst 2012-05-21 07:17:23 UTC (rev 668) +++ branches/jrst-docutils-jython/jrst-doc/src/site/rst/user/index.rst 2012-05-23 14:35:21 UTC (rev 669) @@ -61,11 +61,11 @@ Cette commande aura pour effet de convertir le fichier myfile.rst en XML qui sera affiché sur la sortie standard (console). Plusieurs options sont disponibles : --o file,--outFile=file pour rediriger la sortie vers un fichier. --t format,--outType format pour préciser un format de sortie, donc utiliser un ou des fichiers XSL_ de génération. Plusieurs formats sont disponibles xhtml, docbook, xml, html, xdoc, rst, pdf, odt, rtf. --x xslFile,--xslFile xslFile sert à préciser le fichier xsl de génération à utiliser. ---force forcer l'écriture d'un fichier, si le fichier de sortie existe, il sera remplacé. ---help pour afficher les options disponibles : +-o file, --outFile=file Pour rediriger la sortie vers un fichier. +-t format, --outType format Pour préciser un format de sortie, donc utiliser un ou des fichiers XSL_ de génération. Plusieurs formats sont disponibles xhtml, docbook, xml, html, xdoc, rst, pdf, odt, rtf. +-x xslFile, --xslFile xslFile Sert à préciser le fichier xsl de génération à utiliser. +--force Forcer l'écriture d'un fichier, si le fichier de sortie existe, il sera remplacé. +--help Pour afficher les options disponibles : :: Modified: branches/jrst-docutils-jython/jrst-doc/src/site/site_en.xml =================================================================== --- branches/jrst-docutils-jython/jrst-doc/src/site/site_en.xml 2012-05-21 07:17:23 UTC (rev 668) +++ branches/jrst-docutils-jython/jrst-doc/src/site/site_en.xml 2012-05-23 14:35:21 UTC (rev 669) @@ -25,7 +25,22 @@ --> <project name="${project.name}"> + <skin> + <groupId>org.apache.maven.skins</groupId> + <artifactId>maven-fluido-skin</artifactId> + <version>1.2.1</version> + </skin> + <custom> + <fluidoSkin> + <topBarEnabled>true</topBarEnabled> + <googleSearch/> + <sideBarEnabled>false</sideBarEnabled> + <searchEnabled>true</searchEnabled> + <sourceLineNumbersEnabled>true</sourceLineNumbersEnabled> + </fluidoSkin> + </custom> + <poweredBy> <logo href="http://jrst.labs.libre-entreprise.org" name="JRst" img="${project.url}/images/jrst-logo.png"/> Modified: branches/jrst-docutils-jython/jrst-doc/src/site/site_fr.xml =================================================================== --- branches/jrst-docutils-jython/jrst-doc/src/site/site_fr.xml 2012-05-21 07:17:23 UTC (rev 668) +++ branches/jrst-docutils-jython/jrst-doc/src/site/site_fr.xml 2012-05-23 14:35:21 UTC (rev 669) @@ -26,6 +26,22 @@ <project name="${project.name}"> + <skin> + <groupId>org.apache.maven.skins</groupId> + <artifactId>maven-fluido-skin</artifactId> + <version>1.2.1</version> + </skin> + + <custom> + <fluidoSkin> + <topBarEnabled>true</topBarEnabled> + <googleSearch/> + <sideBarEnabled>false</sideBarEnabled> + <searchEnabled>true</searchEnabled> + <sourceLineNumbersEnabled>true</sourceLineNumbersEnabled> + </fluidoSkin> + </custom> + <poweredBy> <logo href="http://jrst.labs.libre-entreprise.org" name="JRst" img="${project.url}/images/jrst-logo.png"/> Modified: branches/jrst-docutils-jython/pom.xml =================================================================== --- branches/jrst-docutils-jython/pom.xml 2012-05-21 07:17:23 UTC (rev 668) +++ branches/jrst-docutils-jython/pom.xml 2012-05-23 14:35:21 UTC (rev 669) @@ -312,13 +312,20 @@ <version>2.5.2</version> </dependency> - <!-- Flying Saucer --> + <!-- itext --> <dependency> <groupId>org.xhtmlrenderer</groupId> <artifactId>core-renderer</artifactId> <version>R8</version> </dependency> + <dependency> + <groupId>com.lowagie</groupId> + <artifactId>itext</artifactId> + <version>2.0.8</version> + </dependency> + + </dependencies> </dependencyManagement>
participants (1)
-
jpages@users.nuiton.org