DLESE Tools
v1.6.0

org.dlese.dpc.webapps.servlets.filters
Class XMLPostProcessingFilter

java.lang.Object
  extended by org.dlese.dpc.webapps.servlets.filters.FilterCore
      extended by org.dlese.dpc.webapps.servlets.filters.XMLPostProcessingFilter
All Implemented Interfaces:
Filter
Direct Known Subclasses:
RecordValidationFilter

public class XMLPostProcessingFilter
extends FilterCore

Performs post-processing of an XML stream and gzips the response if supported by the browser. Supported post-processing actions include XML validation, XML transform to localized XML, and XML to JSON serialization.

The XML validation is implemented using a servlet response Filter that checks the content for validity against an XML schema or DTD, which must be referenced in the content itself.

The JSON serialization is implemented using the json.org XML serializer and appropriate classes must be included in your classpath. See http://www.json.org/javadoc/ .

Author:
John Weatherley

Constructor Summary
XMLPostProcessingFilter()
           
 
Method Summary
 void destroy()
          Destroy is called at application shut-down time.
 void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
          Performs XML post-processing and gzipping of the response.
protected  String getValidationMessage(String xml, ServletRequest request)
          Validate the provided xml and return a validation message.
 void init(FilterConfig config)
          Init is called once at application start-up.
protected  void prtln(String s)
          Output a line of text to standard out, with datestamp, if debug is set to true.
protected  void prtlnErr(String s)
          Output a line of text to error out, with datestamp.
protected  void setDebugz(boolean db)
          Sets the debug attribute of the XMLPostProcessingFilter object
protected  String xmlToHtml(String xml)
          Get html-displayable version of provided xml
 
Methods inherited from class org.dlese.dpc.webapps.servlets.filters.FilterCore
getDateStamp, handleErrorCodes, isGzipSupported, prtlnCore, writeGzipResponse, writeRegularResponse
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

XMLPostProcessingFilter

public XMLPostProcessingFilter()
Method Detail

doFilter

public final void doFilter(ServletRequest request,
                           ServletResponse response,
                           FilterChain chain)
                    throws ServletException,
                           IOException
Performs XML post-processing and gzipping of the response.

Parameters:
request - The request
response - The response
chain - The chain of Filters
Throws:
ServletException - Iff error
IOException - Iff IO error

getValidationMessage

protected String getValidationMessage(String xml,
                                      ServletRequest request)
Validate the provided xml and return a validation message.

Parameters:
xml - XML string to be validated
Returns:
The validationMessage value or null if xml is valid

xmlToHtml

protected String xmlToHtml(String xml)
Get html-displayable version of provided xml

Parameters:
xml - xml to be displayed as html
Returns:
html as string

init

public void init(FilterConfig config)
          throws ServletException
Init is called once at application start-up.

Parameters:
config - The FilterConfig object that holds the ServletContext and init information.
Throws:
ServletException - If an error occurs

destroy

public void destroy()
Destroy is called at application shut-down time.


prtlnErr

protected final void prtlnErr(String s)
Output a line of text to error out, with datestamp.

Parameters:
s - The text that will be output to error out.

prtln

protected void prtln(String s)
Output a line of text to standard out, with datestamp, if debug is set to true.

Parameters:
s - The String that will be output.

setDebugz

protected final void setDebugz(boolean db)
Sets the debug attribute of the XMLPostProcessingFilter object

Parameters:
db - The new debug value

DLESE Tools
v1.6.0