fop 0.91beta

org.apache.fop.servlet
Class FopServlet

java.lang.Object
  |
  +--javax.servlet.GenericServlet
        |
        +--javax.servlet.http.HttpServlet
              |
              +--org.apache.fop.servlet.FopServlet
All Implemented Interfaces:
java.io.Serializable, javax.servlet.Servlet, javax.servlet.ServletConfig

public class FopServlet
extends javax.servlet.http.HttpServlet

Example servlet to generate a PDF from a servlet.
Servlet param is:

or
Example URL: http://servername/fop/servlet/FopServlet?fo=readme.fo
Example URL: http://servername/fop/servlet/FopServlet?xml=data.xml&xslt=format.xsl
For this to work with Internet Explorer, you might need to append "&ext=.pdf" to the URL.

Version:
$Id: FopServlet.java 332793 2005-11-12 16:01:52Z jeremias $ (todo) Ev. add caching mechanism for Templates objects
Author:
Apache XML FOP Development Team
See Also:
Serialized Form

Field Summary
protected static java.lang.String FO_REQUEST_PARAM
          Name of the parameter used for the XSL-FO file
protected  org.apache.commons.logging.impl.SimpleLog log
          Logger to give to FOP
protected  javax.xml.transform.TransformerFactory transFactory
          The TransformerFactory to use to create Transformer instances
protected static java.lang.String XML_REQUEST_PARAM
          Name of the parameter used for the XML file
protected static java.lang.String XSLT_REQUEST_PARAM
          Name of the parameter used for the XSLT file
 
Constructor Summary
FopServlet()
           
 
Method Summary
protected  javax.xml.transform.Source convertString2Source(java.lang.String param)
          Converts a String parameter to a JAXP Source object.
 void doGet(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
           
 void init()
           
protected  byte[] render(javax.xml.transform.Source src, javax.xml.transform.Transformer transformer)
          Renders an input file (XML or XSL-FO) into a PDF file.
protected  byte[] renderFO(java.lang.String fo)
          Renders an XSL-FO file into a PDF file.
protected  byte[] renderXML(java.lang.String xml, java.lang.String xslt)
          Renders an XML file into a PDF file by applying a stylesheet that converts the XML to XSL-FO.
 
Methods inherited from class javax.servlet.http.HttpServlet
doDelete, doOptions, doPost, doPut, doTrace, getLastModified, service, service
 
Methods inherited from class javax.servlet.GenericServlet
destroy, getInitParameter, getInitParameterNames, getServletConfig, getServletContext, getServletInfo, getServletName, init, log, log
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

FO_REQUEST_PARAM

protected static final java.lang.String FO_REQUEST_PARAM
Name of the parameter used for the XSL-FO file

XML_REQUEST_PARAM

protected static final java.lang.String XML_REQUEST_PARAM
Name of the parameter used for the XML file

XSLT_REQUEST_PARAM

protected static final java.lang.String XSLT_REQUEST_PARAM
Name of the parameter used for the XSLT file

log

protected org.apache.commons.logging.impl.SimpleLog log
Logger to give to FOP

transFactory

protected javax.xml.transform.TransformerFactory transFactory
The TransformerFactory to use to create Transformer instances
Constructor Detail

FopServlet

public FopServlet()
Method Detail

init

public void init()
          throws javax.servlet.ServletException
Overrides:
init in class javax.servlet.GenericServlet
See Also:
GenericServlet.init()

doGet

public void doGet(javax.servlet.http.HttpServletRequest request,
                  javax.servlet.http.HttpServletResponse response)
           throws javax.servlet.ServletException
Overrides:
doGet in class javax.servlet.http.HttpServlet
See Also:
HttpServlet.doGet(HttpServletRequest, HttpServletResponse)

convertString2Source

protected javax.xml.transform.Source convertString2Source(java.lang.String param)
Converts a String parameter to a JAXP Source object.
Parameters:
param - a String parameter
Returns:
Source the generated Source object

renderFO

protected byte[] renderFO(java.lang.String fo)
                   throws FOPException,
                          javax.xml.transform.TransformerException
Renders an XSL-FO file into a PDF file. The PDF is written to a byte array that is returned as the method's result.
Parameters:
fo - the XSL-FO file
Returns:
byte[] the rendered PDF file
Throws:
FOPException - If an error occurs during the rendering of the XSL-FO
javax.xml.transform.TransformerException - If an error occurs while parsing the input file

renderXML

protected byte[] renderXML(java.lang.String xml,
                           java.lang.String xslt)
                    throws FOPException,
                           javax.xml.transform.TransformerException
Renders an XML file into a PDF file by applying a stylesheet that converts the XML to XSL-FO. The PDF is written to a byte array that is returned as the method's result.
Parameters:
xml - the XML file
xslt - the XSLT file
Returns:
byte[] the rendered PDF file
Throws:
FOPException - If an error occurs during the rendering of the XSL-FO
javax.xml.transform.TransformerException - If an error occurs during XSL transformation

render

protected byte[] render(javax.xml.transform.Source src,
                        javax.xml.transform.Transformer transformer)
                 throws FOPException,
                        javax.xml.transform.TransformerException
Renders an input file (XML or XSL-FO) into a PDF file. It uses the JAXP transformer given to optionally transform the input document to XSL-FO. The transformer may be an identity transformer in which case the input must already be XSL-FO. The PDF is written to a byte array that is returned as the method's result.
Parameters:
src - Input XML or XSL-FO
transformer - Transformer to use for optional transformation
Returns:
byte[] the rendered PDF file
Throws:
FOPException - If an error occurs during the rendering of the XSL-FO
javax.xml.transform.TransformerException - If an error occurs during XSL transformation

fop 0.91beta

Copyright 1999-2005 The Apache Software Foundation. All Rights Reserved.