Package org.apache.fop.servlet
Class FopServlet
java.lang.Object
HttpServlet
org.apache.fop.servlet.FopServlet
- Direct Known Subclasses:
FopPrintServlet
public class FopServlet
extends HttpServlet
Example servlet to generate a PDF from a servlet.
Servlet param is:
Example URL: http://servername/fop/servlet/FopServlet?fo=readme.fo
Example URL: http://servername/fop/servlet/FopServlet?xml=data.xml
For this to work with Internet Explorer, you might need to append "ext=.pdf" to the URL. (todo) Ev. add caching mechanism for Templates objects
Servlet param is:
- fo: the path to a XSL-FO file to render
- xml: the path to an XML file to render
- xslt: the path to an XSLT file that can transform the above XML to XSL-FO
Example URL: http://servername/fop/servlet/FopServlet?fo=readme.fo
Example URL: http://servername/fop/servlet/FopServlet?xml=data.xml
For this to work with Internet Explorer, you might need to append "ext=.pdf" to the URL. (todo) Ev. add caching mechanism for Templates objects
-
Field Summary
Modifier and TypeFieldDescriptionprotected static final String
Name of the parameter used for the XSL-FO fileprotected FopFactory
The FopFactory used to create Fop instancesprotected TransformerFactory
The TransformerFactory used to create Transformer instancesprotected URIResolver
URIResolver for use by this servletprotected static final String
Name of the parameter used for the XML fileprotected static final String
Name of the parameter used for the XSLT file -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected void
configureFopFactory
(FopFactoryBuilder builder) This method is called right after the FopFactory is instantiated and can be overridden by subclasses to perform additional configuration.protected Source
convertString2Source
(String param) Converts a String parameter to a JAXP Source object.void
doGet
(HttpServletRequest request, HttpServletResponse response) protected FOUserAgent
void
init()
protected void
render
(Source src, Transformer transformer, HttpServletResponse response) Renders an input file (XML or XSL-FO) into a PDF file.protected void
Renders an XSL-FO file into a PDF file.protected void
Renders an XML file into a PDF file by applying a stylesheet that converts the XML to XSL-FO.
-
Field Details
-
FO_REQUEST_PARAM
Name of the parameter used for the XSL-FO file- See Also:
-
XML_REQUEST_PARAM
Name of the parameter used for the XML file- See Also:
-
XSLT_REQUEST_PARAM
Name of the parameter used for the XSLT file- See Also:
-
transFactory
The TransformerFactory used to create Transformer instances -
fopFactory
The FopFactory used to create Fop instances -
uriResolver
URIResolver for use by this servlet
-
-
Constructor Details
-
FopServlet
public FopServlet()
-
-
Method Details
-
init
public void init() throws ServletException- Throws:
ServletException
-
configureFopFactory
This method is called right after the FopFactory is instantiated and can be overridden by subclasses to perform additional configuration. -
doGet
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException - Throws:
ServletException
-
convertString2Source
Converts a String parameter to a JAXP Source object.- Parameters:
param
- a String parameter- Returns:
- Source the generated Source object
-
renderFO
protected void renderFO(String fo, HttpServletResponse response) throws FOPException, TransformerException, IOException 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 fileresponse
- HTTP response object- Throws:
FOPException
- If an error occurs during the rendering of the XSL-FOTransformerException
- If an error occurs while parsing the input fileIOException
- In case of an I/O problem
-
renderXML
protected void renderXML(String xml, String xslt, HttpServletResponse response) throws FOPException, TransformerException, IOException 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 filexslt
- the XSLT fileresponse
- HTTP response object- Throws:
FOPException
- If an error occurs during the rendering of the XSL-FOTransformerException
- If an error occurs during XSL transformationIOException
- In case of an I/O problem
-
render
protected void render(Source src, Transformer transformer, HttpServletResponse response) throws FOPException, TransformerException, IOException 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-FOtransformer
- Transformer to use for optional transformationresponse
- HTTP response object- Throws:
FOPException
- If an error occurs during the rendering of the XSL-FOTransformerException
- If an error occurs during XSL transformationIOException
- In case of an I/O problem
-
getFOUserAgent
- Returns:
- a new FOUserAgent for FOP
-