Title: Message
I do this using FOP.  I do everything 'in memory' however, and I actually wrote a jsp page to do this process, as it directly uses the 'response', and when I wrote it as a .cfm, it kept crashing the server (the server admins don't like it when I do that ;)
 
Here's some JSP code, say in file index.jsp

<%@ page import="java.io.*,javax.servlet.*,javax.servlet.http.*,org.xml.sax.InputSource,org.xml.sax.XMLReader,org.apache.fop.apps.Driver,org.apache.fop.apps.Version,org.apache.fop.apps.XSLTInputHandler,org.apache.fop.messaging.MessageHandler" %>
 

<%
 
String FO_REQUEST_PARAM = "fo";
 
 String foParam = (String)request.getAttribute(FO_REQUEST_PARAM);
 
 if (foParam != null) {
  try {
   //renderFO(new InputSource(new StringReader(foParam)), response);
   InputSource foFile = new InputSource(new StringReader(foParam));
   
   //public void renderFO(InputSource foFile,
 
         ByteArrayOutputStream outn = new ByteArrayOutputStream();
   org.apache.fop.apps.Driver driver = new Driver(foFile, outn);
         driver.setRenderer(Driver.RENDER_PDF);
         driver.run();
 
         byte[] content = outn.toByteArray();
 
   response.reset();
         response.setContentType("application/pdf");
         response.setContentLength(content.length);
         response.getOutputStream().write(content);
         response.getOutputStream().flush();
         response.getOutputStream().close();
  } catch (Exception e) {
   response.reset();
         response.setContentType("text/html");
   PrintWriter outn = response.getWriter();
   outn.println("<html><head><title>Error</title></head>\n"+
   "<body><h1>FopServlet Error</h1><h3>Something bad happened</h3></body></html>");
  }
 } else {
  PrintWriter outn = response.getWriter();
  outn.println("<html><head><title>Error</title></head>\n"+
  "<body><h1>FopServlet Error</h1><h3>No 'fo' "+
  "request param given.</body></html>");
 }
%>
 
So then I have a .CFM file, like so:
 
<cfsavecontent variable="request.fo"><?xml version="1.0" encoding="UTF-8"?>
<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
  <fo:layout-master-set>
    <fo:simple-page-master
      <fo:block>
... lots more fo xml goes here...     
      </fo:block>
    </fo:flow>
  </fo:page-sequence>
</fo:root></cfsavecontent><CFSET GetPageContext().forward("index.jsp")>

So I use the .jsp file over and over, using coldfusion to generate my FO XML, and then forwarding it to the .JSP to be rendered as a PDF, which is then passed on...
 
I'm pretty sure anyone with any know-how on this stuff will look at this code and cringe.  It's a big hack, but it works.  Although the .JSP code is picky...  use at your own risk.  Also, it is seriously ineffecient, as the FOP engine is getting initialized each time.  Some form of pooling and locking should be used to have a single FOP engine, probably.  Oh, and this should all occur with a servlet, not a .JSP page.  They go over all that stuff on the fop website.  I was just looking for something quick, and this worked.  I would not use it in any in any serious production enviroment.
 
If you wanted to generate RTF instead, you'd just have to change a few things in the JSP...  content type, and the driver type, I think.
 
The advantage to this method is it all happens in memory, no having to write files to disk to serve them up.
 
 
-----Original Message-----
From: Mafalda Jordan [mailto:[EMAIL PROTECTED]
Sent: Thursday, June 26, 2003 11:06 AM
To: [EMAIL PROTECTED]
Subject: [cf-xml] (no subject)

Hi everyone,
 
I am trying to transform xsl-fo into rtf using a java open source application called jfor (www.jfor.org). It works well from the command line, but I cannot get it to run as a CFX tag.
The problem is that it cannot find the input xml file, but the file is there and the path is correct. Has anybody used jfor before?
 
Thank you
 

Reply via email to