com.twitter.common.net.http.handlers
Class StringTemplateServlet

java.lang.Object
  extended by javax.servlet.GenericServlet
      extended by javax.servlet.http.HttpServlet
          extended by com.twitter.common.net.http.handlers.StringTemplateServlet
All Implemented Interfaces:
Serializable, javax.servlet.Servlet, javax.servlet.ServletConfig
Direct Known Subclasses:
LogConfig, LogPrinter, ThriftServlet

public abstract class StringTemplateServlet
extends javax.servlet.http.HttpServlet

A base class for servlets that render using the string template templating system. Subclasses can call one of the writeTemplate(javax.servlet.http.HttpServletResponse, com.twitter.common.base.ExceptionalClosure) methods to render their content with the associated template.

See Also:
Serialized Form

Nested Class Summary
static interface StringTemplateServlet.CacheTemplates
          A @BindingAnnotation that allows configuration of whether or not StringTemplateServlets should cache their templates.
 
Constructor Summary
protected StringTemplateServlet(String templateName, boolean cacheTemplates)
          Creates a new StringTemplateServlet that expects to find its template located in the same package on the classpath at 'templateName.st'.
 
Method Summary
protected  void writeTemplate(javax.servlet.http.HttpServletResponse response, ExceptionalClosure<org.antlr.stringtemplate.StringTemplate,?> parameterSetter)
           
protected  void writeTemplate(javax.servlet.http.HttpServletResponse response, String contentType, int status, ExceptionalClosure<org.antlr.stringtemplate.StringTemplate,?> parameterSetter)
           
 
Methods inherited from class javax.servlet.http.HttpServlet
doDelete, doGet, doHead, doOptions, doPost, doPut, doTrace, getLastModified, service, service
 
Methods inherited from class javax.servlet.GenericServlet
destroy, getInitParameter, getInitParameterNames, getServletConfig, getServletContext, getServletInfo, getServletName, init, init, log, log
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

StringTemplateServlet

protected StringTemplateServlet(String templateName,
                                boolean cacheTemplates)
Creates a new StringTemplateServlet that expects to find its template located in the same package on the classpath at 'templateName.st'.

Parameters:
templateName - The name of the string template to use.
cacheTemplates - true to re-use loaded templates, false to reload the template for each request.
Method Detail

writeTemplate

protected final void writeTemplate(javax.servlet.http.HttpServletResponse response,
                                   ExceptionalClosure<org.antlr.stringtemplate.StringTemplate,?> parameterSetter)
                            throws IOException
Throws:
IOException

writeTemplate

protected final void writeTemplate(javax.servlet.http.HttpServletResponse response,
                                   String contentType,
                                   int status,
                                   ExceptionalClosure<org.antlr.stringtemplate.StringTemplate,?> parameterSetter)
                            throws IOException
Throws:
IOException