From c8dd5ab13eeb2318bfdbd65c758fb6f1d2784e23 Mon Sep 17 00:00:00 2001 From: Christian Geisert Date: Mon, 9 Dec 2002 04:04:33 +0000 Subject: [PATCH] Removed old Servlet example (new is in contrib/servlet) git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/branches/fop-0_20_2-maintain@195748 13f79535-47bb-0310-9956-ffa450edef68 --- docs/examples/embedding/FopPrintServlet.java | 299 ------------------- docs/examples/embedding/FopServlet.java | 149 --------- docs/examples/embedding/fop.war | Bin 2901 -> 0 bytes 3 files changed, 448 deletions(-) delete mode 100644 docs/examples/embedding/FopPrintServlet.java delete mode 100644 docs/examples/embedding/FopServlet.java delete mode 100644 docs/examples/embedding/fop.war diff --git a/docs/examples/embedding/FopPrintServlet.java b/docs/examples/embedding/FopPrintServlet.java deleted file mode 100644 index b67c3aa9b..000000000 --- a/docs/examples/embedding/FopPrintServlet.java +++ /dev/null @@ -1,299 +0,0 @@ -/* - * $Id$ - * Copyright (C) 2002 The Apache Software Foundation. All rights reserved. - * For details on use and redistribution please refer to the - * LICENSE file included with these sources. - */ - -import java.io.*; -import java.util.Vector ; - -import java.awt.print.PrinterJob ; -import java.awt.print.PrinterException ; - -import javax.servlet.*; -import javax.servlet.http.*; - -import org.xml.sax.InputSource; -import org.xml.sax.XMLReader; - -import org.apache.fop.apps.Driver; -import org.apache.fop.layout.Page; -import org.apache.fop.apps.Version; -import org.apache.fop.apps.XSLTInputHandler; -import org.apache.fop.messaging.MessageHandler; - -import org.apache.fop.render.awt.AWTRenderer ; - -import org.apache.avalon.framework.logger.ConsoleLogger; -import org.apache.avalon.framework.logger.Logger; - -/** - * Example servlet to generate a fop printout from a servlet. - * Printing goes to the default printer on host where the servlet executes. - * Servlet param is: - * - * - * Example URL: http://servername/servlet/FopPrintServlet?fo=readme.fo - * Example URL: http://servername/servlet/FopPrintServlet?xml=data.xml&xsl=format.xsl - * Compiling: you will need - * - servlet_2_2.jar - * - fop.jar - * - sax api - * - avalon-framework-x.jar (where x is the version found the FOP lib dir) - * - * Running: you will need in the WEB-INF/lib/ directory: - * - fop.jar - * - batik.jar - * - avalon-framework-x.jar (where x is the version found the FOP lib dir) - * - xalan-2.0.0.jar - */ - -public class FopPrintServlet 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) - { - log = new ConsoleLogger(ConsoleLogger.LEVEL_WARN); - MessageHandler.setScreenLogger(log); - } - - try - { - 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 - { - response.setContentType ("text/html"); - - PrintWriter out = response.getWriter(); - out.println("Error\n"+ - "

FopServlet Error

No 'fo' or 'xml/xsl' "+ - "request param given.

"); - } - } - catch (ServletException ex) - { - throw ex; - } - catch (Exception ex) - { - throw new ServletException(ex); - } - } - - /** - * renders an FO inputsource into a PDF file which is rendered - * directly to the response object's OutputStream - */ - public void renderFO(InputSource foFile, HttpServletResponse response) - throws ServletException - { - try - { - Driver driver = new Driver(foFile, null); - PrinterJob pj = PrinterJob.getPrinterJob(); - PrintRenderer renderer = new PrintRenderer(pj); - - driver.setLogger (log); - driver.setRenderer(renderer); - driver.run(); - - reportOK (response) ; - } - catch (Exception ex) - { - throw new ServletException(ex); - } - } - - public void renderXML(XSLTInputHandler input, HttpServletResponse response) - throws ServletException - { - try - { - Driver driver = new Driver(); - PrinterJob pj = PrinterJob.getPrinterJob(); - PrintRenderer renderer = new PrintRenderer(pj); - - pj.setCopies(1); - - driver.setLogger (log); - driver.setRenderer (renderer); - driver.render (input.getParser(), input.getInputSource()); - - reportOK (response) ; - } - catch (Exception ex) - { - throw new ServletException(ex); - } - } - - // private helper, tell (browser) user that file printed - - private void reportOK (HttpServletResponse response) - throws ServletException - { - String sMsg = "Success\n" + - "

FopPrintServlet:

" + - "

The requested data was printed

" ; - - response.setContentType ("text/html"); - response.setContentLength (sMsg.length()); - - try - { - PrintWriter out = response.getWriter(); - out.println (sMsg) ; - out.flush() ; - } - catch (Exception ex) - { - throw new ServletException(ex); - } - } - - - /** - * creates a SAX parser, using the value of org.xml.sax.parser - * defaulting to org.apache.xerces.parsers.SAXParser - * - * @return the created SAX parser - */ - static XMLReader createParser() - throws ServletException - { - String parserClassName = System.getProperty("org.xml.sax.parser"); - if (parserClassName == null) - { - parserClassName = "org.apache.xerces.parsers.SAXParser"; - } - - try - { - return (XMLReader) Class.forName(parserClassName).newInstance(); - } - catch (Exception e) - { - throw new ServletException(e); - } - } - - // This is stolen from PrintStarter - class PrintRenderer extends AWTRenderer - { - - private static final int EVEN_AND_ALL = 0; - private static final int EVEN = 1; - private static final int ODD = 2; - - private int startNumber; - private int endNumber; - private int mode = EVEN_AND_ALL; - private int copies = 1; - private PrinterJob printerJob; - - PrintRenderer(PrinterJob printerJob) - { - super(null); - - this.printerJob = printerJob; - startNumber = 0 ; - endNumber = -1; - - printerJob.setPageable(this); - - mode = EVEN_AND_ALL; - String str = System.getProperty("even"); - if (str != null) - { - try - { - mode = Boolean.valueOf(str).booleanValue() ? EVEN : ODD; - } - catch (Exception e) - {} - - } - - } - - - - public void stopRenderer(OutputStream outputStream) - throws IOException { - super.stopRenderer(outputStream); - - if(endNumber == -1) - endNumber = getPageCount(); - - Vector numbers = getInvalidPageNumbers(); - for (int i = numbers.size() - 1; i > -1; i--) - removePage(Integer.parseInt((String)numbers.elementAt(i))); - - try { - printerJob.print(); - } catch (PrinterException e) { - e.printStackTrace(); - throw new IOException( - "Unable to print: " + e.getClass().getName() + - ": " + e.getMessage()); - } - } - - public void renderPage(Page page) { - pageWidth = (int)((float)page.getWidth() / 1000f); - pageHeight = (int)((float)page.getHeight() / 1000f); - super.renderPage(page); - } - - - private Vector getInvalidPageNumbers() { - - Vector vec = new Vector(); - int max = getPageCount(); - boolean isValid; - for (int i = 0; i < max; i++) { - isValid = true; - if (i < startNumber || i > endNumber) { - isValid = false; - } else if (mode != EVEN_AND_ALL) { - if (mode == EVEN && ((i + 1) % 2 != 0)) - isValid = false; - else if (mode == ODD && ((i + 1) % 2 != 1)) - isValid = false; - } - - if (!isValid) - vec.add(i + ""); - } - - return vec; - } - } // class PrintRenderer - - -} - diff --git a/docs/examples/embedding/FopServlet.java b/docs/examples/embedding/FopServlet.java deleted file mode 100644 index decdf5818..000000000 --- a/docs/examples/embedding/FopServlet.java +++ /dev/null @@ -1,149 +0,0 @@ -/* - * $Id$ - * Copyright (C) 2001 The Apache Software Foundation. All rights reserved. - * For details on use and redistribution please refer to the - * LICENSE file included with these sources. - */ - -import java.io.*; - -import javax.servlet.*; -import javax.servlet.http.*; - -import org.xml.sax.InputSource; -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.fop.messaging.MessageHandler; - -import org.apache.avalon.framework.logger.ConsoleLogger; -import org.apache.avalon.framework.logger.Logger; - -/** - * Example servlet to generate a PDF from a servlet. - * Servlet param is: - * - * - * 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 - * - avalon-framework-x.jar (where x is the version found the FOP lib dir) - * - * Running: you will need in the WEB-INF/lib/ directory: - * - fop.jar - * - batik.jar - * - xalan-2.0.0.jar - * - avalon-framework-x.jar (where x is the version found the FOP lib dir) - */ -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) { - log = new ConsoleLogger(ConsoleLogger.LEVEL_WARN); - MessageHandler.setScreenLogger(log); - } - try { - 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"+ - "

FopServlet Error

No 'fo' "+ - "request param given."); - } - } catch (ServletException ex) { - throw ex; - } - catch (Exception ex) { - throw new ServletException(ex); - } - } - - /** - * renders an FO inputsource into a PDF file which is rendered - * directly to the response object's OutputStream - */ - public void renderFO(InputSource foFile, - HttpServletResponse response) throws ServletException { - try { - ByteArrayOutputStream out = new ByteArrayOutputStream(); - - 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); - } - } - - /** - * creates a SAX parser, using the value of org.xml.sax.parser - * defaulting to org.apache.xerces.parsers.SAXParser - * - * @return the created SAX parser - */ - static XMLReader createParser() throws ServletException { - String parserClassName = System.getProperty("org.xml.sax.parser"); - if (parserClassName == null) { - parserClassName = "org.apache.xerces.parsers.SAXParser"; - } - - try { - return (XMLReader) Class.forName( - parserClassName).newInstance(); - } catch (Exception e) { - throw new ServletException(e); - } - } - -} diff --git a/docs/examples/embedding/fop.war b/docs/examples/embedding/fop.war deleted file mode 100644 index f5607c11c07ce5ce8b1b0279bffea0b940062744..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 2901 zcmZ{m3pCW}8^_1GHj;{wYsfVWi42pOMT|6t(F}t~#KvwT&CpCj<<_`Fh**~_6Ps(2 z%gDV!mURgkty~&HM6N>^f74!A=fBT;e&@WubH3mAeV*q$=e!>@lAA{qAh5l9Fb3*? zU9k_q13;N!jlmXH2rc$+001`tjpP^LD8BnkhW<~p=(ge?Gs@V?0%3;1YN8N}sP;BX zBv`Xs2nkl}XzwgNf1+1sWSpRR4y9p%>h{ay*(W|NL6;Ig?#c7$fs=J*LSIpqs4*xwo;_ zbps$dBSn<(z0;?4SZnWZT|sQIJJ(4iLa@sGQB{QGJkMcCgti#n!9ZC`J7%BIgb$n| zh^nNt%GHX~A4Y0L30ALtN2F}|d3 zT%9>;7I2DE?6nH5m2ZXE1|XX%Y^$l4TDm3^$3_N-AxsfmGhaNn0?_1Df4f1?>(sDl z?O6uRB*)r#@p?X*&>l=2YJU_KoPNYS90HuJ*01%#Ul{sL)l;T?CfZf(cdVVblXiHa zC4$i_MVSB^sSN^v=r)=U6btqnPwTD2G8sxLOVgX-}#@@2gV=je|a-oafVjy z6J5X*y`P}S95Oj?h!IoDof8>2XNFMxO0~uNz?CAcVg!M~<*L*$m~P&PDSi1?klwY2 zzfNO+vA@w=_&oja<8y)8xp9=^`chBB+?v%EO6^Zl21E1NREM(@5$(C%#kp5qp>FLj zT8reQr<^AAJ}ZZ%+!%dp$ht>3-1GU&+sN8v-P~+hm##xC6Sma_OupJzFS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