From cc10c67344520bcb395569dbc739cfb308acee27 Mon Sep 17 00:00:00 2001 From: Keiron Liddle Date: Tue, 25 Sep 2001 08:32:58 +0000 Subject: [PATCH] updated servlet to reflect changes to fop git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@194481 13f79535-47bb-0310-9956-ffa450edef68 --- docs/examples/embedding/FopServlet.java | 60 ++++++++++++++++++++---- docs/examples/embedding/fop.war | Bin 8374 -> 2901 bytes 2 files changed, 52 insertions(+), 8 deletions(-) diff --git a/docs/examples/embedding/FopServlet.java b/docs/examples/embedding/FopServlet.java index 022f7a3cf..86c8ee3a9 100644 --- a/docs/examples/embedding/FopServlet.java +++ b/docs/examples/embedding/FopServlet.java @@ -5,8 +5,6 @@ * LICENSE file included with these sources. */ -package org.apache.fop.tools.servlet; - import java.io.*; import javax.servlet.*; @@ -17,7 +15,9 @@ import org.xml.sax.XMLReader; import org.apache.fop.apps.Driver; import org.apache.fop.apps.Version; +import org.apache.fop.apps.XSLTInputHandler; +import org.apache.log.*; /** * Example servlet to generate a PDF from a servlet. @@ -26,23 +26,45 @@ import org.apache.fop.apps.Version; *
  • fo: the path to a formatting object file to render * * - * Example URL: http://servername/servlet/FopServlet?fo=/home/fop/example/readme.fo + * Example URL: http://servername/servlet/FopServlet?fo=readme.fo + * Example URL: http://servername/servlet/FopServlet?xml=data.xml&xsl=format.xsl * Compiling: you will need * - servlet_2_2.jar * - fop.jar * - sax api + * - logkit jar + * + * Running: you will need in the WEB-INF/lib/ directory: + * - fop.jar + * - batik.jar + * - avalon-framework-4.0.jar + * - logkit-1.0b4.jar + * - xalan-2.0.0.jar */ - public class FopServlet extends HttpServlet { public static final String FO_REQUEST_PARAM = "fo"; + public static final String XML_REQUEST_PARAM = "xml"; + public static final String XSL_REQUEST_PARAM = "xsl"; + Logger log = null; public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException { + if(log == null) { + Hierarchy hierarchy = Hierarchy.getDefaultHierarchy(); + log = hierarchy.getLoggerFor("fop"); + log.setPriority(Priority.WARN); + } try { - if (request.getParameter(FO_REQUEST_PARAM) != null) { - FileInputStream file = new FileInputStream( - request.getParameter(FO_REQUEST_PARAM)); + String foParam = request.getParameter(FO_REQUEST_PARAM); + String xmlParam = request.getParameter(XML_REQUEST_PARAM); + String xslParam = request.getParameter(XSL_REQUEST_PARAM); + + if (foParam != null) { + FileInputStream file = new FileInputStream(foParam); renderFO(new InputSource(file), response); + } else if((xmlParam != null) && (xslParam != null)) { + XSLTInputHandler input = new XSLTInputHandler(new File(xmlParam), new File(xslParam)); + renderXML(input, response); } else { PrintWriter out = response.getWriter(); out.println("Error\n"+ @@ -69,17 +91,39 @@ public class FopServlet extends HttpServlet { response.setContentType("application/pdf"); Driver driver = new Driver(foFile, out); + driver.setLogger(log); + driver.setRenderer(Driver.RENDER_PDF); driver.run(); byte[] content = out.toByteArray(); response.setContentLength(content.length); response.getOutputStream().write(content); response.getOutputStream().flush(); - } catch (Exception ex) { throw new ServletException(ex); } + } + + public void renderXML(XSLTInputHandler input, + HttpServletResponse response) throws ServletException { + try { + ByteArrayOutputStream out = new ByteArrayOutputStream(); + + response.setContentType("application/pdf"); + Driver driver = new Driver(); + driver.setLogger(log); + driver.setRenderer(Driver.RENDER_PDF); + driver.setOutputStream(out); + driver.render(input.getParser(), input.getInputSource()); + + byte[] content = out.toByteArray(); + response.setContentLength(content.length); + response.getOutputStream().write(content); + response.getOutputStream().flush(); + } catch (Exception ex) { + throw new ServletException(ex); + } } /** diff --git a/docs/examples/embedding/fop.war b/docs/examples/embedding/fop.war index 41cbd3dbed5f669210975665b0d9c223963b4d84..f5607c11c07ce5ce8b1b0279bffea0b940062744 100644 GIT binary patch delta 2511 zcmZ9Oc{m%`7QkaHHPO(P7+Wf8EmD(Kg;X-ArD|^wlv>J^PJ;?fsz{4yETyCjW2qsP zskN$>XsnH>VJuY@9knzJDy7y?+iRw8G4H$Iz2`gkoO|xM=l*eib*4kIl8!dQA~FE+ zFJlm6q?0abB=Wb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