Hi,
has anybody a piece of code that works like the example code should
(generate a PDF with xml and xsl and fop).
This well known code does not compile with Fop-0.20.1
I am sure if is not the right mailing list but I couldn't find a list
that matches that topic.
I get the errors:
Error #: 300 : method addPropertyList(java.lang.String) not found in
class org.apache.fop.apps.Driver
Error #: 300 : method addPropertyList(java.lang.String) not found in
class org.apache.fop.apps.Driver
Error #: 300 : method buildFOTree(org.xml.sax.XMLReader,
org.xml.sax.InputSource) not found in class org.apache.fop.apps.Driver
Error #: 300 : method format() not found in class
org.apache.fop.apps.Driver at line 128
Error #: 300 : method render() not found in class
org.apache.fop.apps.Driver at line 129
Greetings,
Andreas
---------------------------------------------------------------------------
// Servlet
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.ServletOutputStream;
// Java
import java.io.FileReader;
import java.io.File;
import java.io.FileWriter;
import java.io.PrintWriter;
import java.io.IOException;
import java.io.FileNotFoundException;
import java.io.OutputStream;
import java.io.FileOutputStream;
import java.net.URL;
// SAX
import org.xml.sax.XMLReader;
import org.xml.sax.helpers.XMLReaderFactory;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import org.xml.sax.SAXParseException;
// FOP
import org.apache.fop.messaging.MessageHandler;
import org.apache.fop.apps.*;
// JAXP
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.Transformer;
import javax.xml.transform.stream.StreamSource;
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerConfigurationException;
public class PDFEngine extends HttpServlet {
public void doGet( HttpServletRequest request, HttpServletResponse
response ) throws ServletException, IOException {
response.setContentType("application/pdf");
ServletOutputStream out = response.getOutputStream();
String xslName = request.getParameter("xsl");
String xmlName = request.getParameter("xml");
//you can omit this parameter and can give same file name to fo as of
xsl or xml
String foName = request.getParameter("pdf");
String xslPath = xslName +".xsl";
String xmlPath = xmlName +".xml";
String foPath = foName + ".fo";
try {
//XSLT Transformation using JAXP
TransformerFactory tfactory = TransformerFactory.newInstance();
String filepath = "e:/Netscape/Server4/docs/"+foPath;
Transformer transformer = tfactory.newTransformer(new
StreamSource(getServletContext().getResource(xslPath).toString()));
transformer.transform(new
StreamSource(getServletContext().getResource(xmlPath).toString()),new
StreamResult(new FileOutputStream(filepath )));
InputSource fopfile = new InputSource(filepath);
buildPDFFromFO(fopfile,out);
out.flush();
}
catch(Exception ex){
System.out.println("Exception in Transformation :"+ex.getMessage());
}
}
public static void buildPDFFromFO(InputSource in, OutputStream out)
throws Exception {
String version = org.apache.fop.apps.Version.getVersion() ;
System.setProperty("org.xml.sax.driver","org.apache.xerces.parsers.SAXParser");
//XMLReader is the interface.
//This interface allows an application to set and query features and
//properties in the parser, to register event handlers for document
processing,
//and to initiate a document parse.
XMLReader parser = XMLReaderFactory.createXMLReader();
parser.setFeature("http://xml.org/sax/features/namespace-prefixes",
true);
org.apache.fop.apps.Driver driver = new org.apache.fop.apps.Driver();
driver.setRenderer("org.apache.fop.render.pdf.PDFRenderer", version);
driver.addElementMapping("org.apache.fop.fo.StandardElementMapping");
driver.addElementMapping("org.apache.fop.svg.SVGElementMapping");
driver.addPropertyList("org.apache.fop.fo.StandardPropertyListMapping");
driver.addPropertyList("org.apache.fop.svg.SVGPropertyListMapping");
driver.setOutputStream(out);
driver.buildFOTree(parser, in);
driver.format();
driver.render();
out.flush();
}
}
--
To unsubscribe: <mailto:[EMAIL PROTECTED]>
For additional commands: <mailto:[EMAIL PROTECTED]>
Troubles with the list: <mailto:[EMAIL PROTECTED]>