DLESE Tools
v1.6.0

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

java.lang.Object
  extended by org.dlese.dpc.webapps.servlets.filters.FilterCore
      extended by org.dlese.dpc.webapps.servlets.filters.JavaScriptWritelnFilter
All Implemented Interfaces:
Filter

public final class JavaScriptWritelnFilter
extends FilterCore

Converts JSP, servlet, HTML or other output into a JavaScript writeln statement or places it into a JavaScript variable. Activated by specifying a query parameter - if none is supplied, the output is left unchanged (except for Gziping). This Filter may be used to create a JavaScript proxy for conetnt. Gzip compresses the response if the browser supports it.

To use, configure the filter to be activated for the pages you want in your web.xml configuration. Then send a request to the page with the one or more of the following query parameters:

rt=jswl - Instructions the filter to output the content as a document.write( content ); statement
rt=jsvar - Instructs the filter to place the content into a JavaScript variable named 'jsvar'.
jsvarname=myvarname - (optional) When jsvar is used, this instructs the filter to place the ouput into the a variable by the name provided. If not supplied, defaults to 'jsvar'.

Examples:

<script type='text/javascript' src='http://example.org/myPage.jsp?rt=jswl'></script>
<script type='text/javascript' src='http://example.org/myPage.jsp?rt=jsvar&jsvarname=myXml'> </script>

Version:
$Id: JavaScriptWritelnFilter.java,v 1.9 2009/03/20 23:34:01 jweather Exp $
Author:
John Weatherley

Constructor Summary
JavaScriptWritelnFilter()
           
 
Method Summary
 void destroy()
          Destroy is called at application shut-down time.
 void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
          Converts the http response into a JavaScript output if parameter rt=jsvar or rt=jswl.
 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 setDebugzz(boolean db)
          Sets the debug attribute of the JavaScriptWritelnFilter object
 
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

JavaScriptWritelnFilter

public JavaScriptWritelnFilter()
Method Detail

doFilter

public final void doFilter(ServletRequest request,
                           ServletResponse response,
                           FilterChain chain)
                    throws ServletException,
                           IOException
Converts the http response into a JavaScript output if parameter rt=jsvar or rt=jswl. Gzip compresses the response regardless.

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

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 final 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.

setDebugzz

protected final void setDebugzz(boolean db)
Sets the debug attribute of the JavaScriptWritelnFilter object

Parameters:
db - The new debug value

DLESE Tools
v1.6.0