Class JakartaPDFFilter
- java.lang.Object
-
- org.faceless.report.JakartaPDFFilter
-
- All Implemented Interfaces:
Filter
,org.xml.sax.ErrorHandler
public class JakartaPDFFilter extends java.lang.Object implements Filter, org.xml.sax.ErrorHandler
The
JakartaPDFFilter
class is an implementation of the Servlet 6 Filter interface, which automatically converts an XML report into a PDF which is returned to the client. It is identical toPDFFilter
except based on thejakarta.servlet
package instead ofjavax.servlet
.More information on installing filters is available in the Servlet Specification and has probably been supplied with your Servlet engine. For the impatient, here's an example setup which would cause all requests to anything in the
/pdf/
path of your website to be converted to a PDF. Add the following lines to yourWEB-INF/web.xml
file:<filter> <filter-name>bforeport</filter-name> <filter-class>org.faceless.report.JakartaPDFFilter</filter-class> </filter> <filter-mapping> <filter-name>bforeport</filter-name> <url-pattern>/pdf/*</url-pattern> </filter-mapping>
Meta tags that aren't already known to the Report Generator and that begin with "
HTTP-
" are added to the response header (minus the "HTTP-" prefix). An example would be to place<meta name="HTTP-Expires" value="Mon, 01 Jan 1999 12:00:00 GMT">
in the head of the XML, which would set the "Expires" header in the HTTP response.The following custom Meta-Tags may also be used to control the behaviour of the servlet.
Servlet-Filename
- ask the client browser to save the file as the specified filename instead of displaying it inline. This uses theContent-Disposition
header, which in theory is accepted by NS4+ and IE5+, although this known bug in IE5.5 may prevent the document from being viewed at all. Use with caution unless you know your audiences browsers.
web.xml
file to further control various internal aspects of the servlet:org.xml.sax.driver
- may be set to the base class of your SAX parsersXMLReader
implementation, if the generator is unable to locate it.org.faceless.report.flag.WarningUnknownTag
- may be set totrue
orfalse
to generate warnings about unknown tags. Default is "true"org.faceless.report.flag.WarningUnknownAttribute
- may be set totrue
orfalse
to generate warnings about unknown attributes. Default is "true"org.faceless.report.flag.WarningMisplacedText
- may be set totrue
orfalse
to generate warnings about misplaced text. Default is "true"cache-minsize
andcache-prefix
- can be set to cache parts of the created document to disk.
These last two parameters were added in version 1.1.19 to cause parts of the document to be cached to disk. This can reduce memory footprint slightly, although it may slow things down a little so you must decide whether it's appropriate or not. The
cache-prefix
andcache-minsize
parameters are passed into theDiskCache
constructor - essentially theprefix
should be a temporary directory, optionally with the first half of a filename. Theminsize
parameter sets the minimum size a stream may be before it's considered to be worth caching to disk. For example, to store streams greater than 8k in the "/tmp/cache" directory and call them "bfo.1", "bfo.2" and so on, you could do something like this:<filter> <filter-name>bforeport</filter-name> <filter-class>org.faceless.report.JakartaPDFFilter</filter-class> <init-param> <param-name>cache-minsize</param-name> <param-value>8192</param-value> </init-param> <init-param> <param-name>cache-prefix</param-name> <param-value>/tmp/cache/bfo.</param-value> </init-param> </filter>
This class also implements
org.xml.sax.ErrorHandler
, to deal with any errors found during the XML parsing process. Currently all warnings and errors are fatal, and logged toSystem.err
. To change this behaviour, subclass this class and override thewarning
,error
andfatalError
methods.
-
-
Constructor Summary
Constructors Constructor Description JakartaPDFFilter()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
destroy()
void
doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
void
error(org.xml.sax.SAXParseException exception)
void
fatalError(org.xml.sax.SAXParseException exception)
FilterConfig
getFilterConfig()
Return the Filter Config.void
init(FilterConfig config)
void
metaTag(HttpServletRequest reader, HttpServletResponse writer, java.lang.String name, java.lang.String value)
Handle any meta tags that aren't recognised by the core Report Generator.protected void
modifyPDF(PDF pdf)
If you need to modify the PDF in any way after it has been generated, you can do it by extending the PDFFilter class and overriding this method.void
setFilterConfig(FilterConfig conf)
Set the Filter Config.void
warning(org.xml.sax.SAXParseException exception)
-
-
-
Method Detail
-
init
public void init(FilterConfig config) throws ServletException
- Specified by:
init
in interfaceFilter
- Throws:
ServletException
-
getFilterConfig
public FilterConfig getFilterConfig()
Return the Filter Config. A non-standard method required for WebLogic 6.1
-
setFilterConfig
public void setFilterConfig(FilterConfig conf)
Set the Filter Config. A non-standard method required for WebLogic 6.1
-
doFilter
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws ServletException, java.io.IOException
- Specified by:
doFilter
in interfaceFilter
- Throws:
ServletException
java.io.IOException
-
modifyPDF
protected void modifyPDF(PDF pdf)
If you need to modify the PDF in any way after it has been generated, you can do it by extending the PDFFilter class and overriding this method. By default this method is a no-op.
-
metaTag
public void metaTag(HttpServletRequest reader, HttpServletResponse writer, java.lang.String name, java.lang.String value) throws ServletException, java.io.IOException
Handle any meta tags that aren't recognised by the core Report Generator. This method recognises tags begining withHTTP-
, as well asServlet-FileName
.- Parameters:
request
- the Servlet requestresponse
- the Servlet requestname
- the "name" attribute from the meta tagvalue
- the "value" attribute from the meta tag- Throws:
ServletException
java.io.IOException
-
warning
public void warning(org.xml.sax.SAXParseException exception) throws org.xml.sax.SAXException
- Specified by:
warning
in interfaceorg.xml.sax.ErrorHandler
- Throws:
org.xml.sax.SAXException
-
error
public void error(org.xml.sax.SAXParseException exception) throws org.xml.sax.SAXException
- Specified by:
error
in interfaceorg.xml.sax.ErrorHandler
- Throws:
org.xml.sax.SAXException
-
fatalError
public void fatalError(org.xml.sax.SAXParseException exception) throws org.xml.sax.SAXException
- Specified by:
fatalError
in interfaceorg.xml.sax.ErrorHandler
- Throws:
org.xml.sax.SAXException
-
-