org.melati.servlet
Class TemplateServlet

Package class diagram package TemplateServlet
java.lang.Object
  extended by javax.servlet.GenericServlet
      extended by javax.servlet.http.HttpServlet
          extended by org.melati.servlet.ConfigServlet
              extended by org.melati.servlet.PoemServlet
                  extended by org.melati.servlet.TemplateServlet
All Implemented Interfaces:
Serializable, javax.servlet.Servlet, javax.servlet.ServletConfig
Direct Known Subclasses:
Admin, CharsetTemplateServletTest, Copy, Display, EmailTemplateServletTest, Login, Logout, Status, TemplateServletTest, WebmacroMelatiServlet, WebmacroMelatiServletTest

public abstract class TemplateServlet
extends PoemServlet

Base class to use Melati with a Template Engine. To create your own servlet simply extend this class, overriding the doTemplateRequest method.

Author:
Tim Joyce $Revision: 1.55 $
See Also:
Serialized Form

Field Summary
protected  ServletTemplateEngine templateEngine
           
 
Fields inherited from class org.melati.servlet.ConfigServlet
melatiConfig, sysAdminEmail, sysAdminName
 
Constructor Summary
TemplateServlet()
           
 
Method Summary
protected  String addExtension(String templateName)
          The template extension is added in an overridable method to allow the application developer to specify their own template extensions.
protected  void doPoemRequest(Melati melati)
          Override this method to build up your own output.
protected abstract  String doTemplateRequest(Melati melati, ServletTemplateContext templateContext)
          Override this method to build up your own output.
 void error(Melati melati, Exception e)
          Send an error message.
 void init(javax.servlet.ServletConfig config)
          Inititialise the template engine.
protected  void prePoemSession(Melati melati)
          Set the ServletTemplateEngine and ServletTemplateContext in our Melati.
 
Methods inherited from class org.melati.servlet.PoemServlet
_handleException, destroy, doConfiguredRequest, getSysAdminEmail, getSysAdminName, handleException, poemContext, poemContextWithLDB
 
Methods inherited from class org.melati.servlet.ConfigServlet
doGet, doPost, httpStatusCode, melatiConfig, setSysAdminEmail, setSysAdminName, writeConnectionPendingException, writeError
 
Methods inherited from class javax.servlet.http.HttpServlet
doDelete, doHead, doOptions, doPut, doTrace, getLastModified, service, service
 
Methods inherited from class javax.servlet.GenericServlet
getInitParameter, getInitParameterNames, getServletConfig, getServletContext, getServletInfo, getServletName, init, log, log
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

templateEngine

protected ServletTemplateEngine templateEngine
Constructor Detail

TemplateServlet

public TemplateServlet()
Method Detail

init

public void init(javax.servlet.ServletConfig config)
          throws javax.servlet.ServletException
Inititialise the template engine.

Specified by:
init in interface javax.servlet.Servlet
Overrides:
init in class ConfigServlet
Parameters:
config - a ServletConfig
Throws:
javax.servlet.ServletException - if the ServletTemplateEngine has a problem

prePoemSession

protected void prePoemSession(Melati melati)
                       throws Exception
Set the ServletTemplateEngine and ServletTemplateContext in our Melati. This allows us to parse any uploaded files before we enter our PoemSession (so we don't hang on to transactions unnecessarily).

Overrides:
prePoemSession in class PoemServlet
Parameters:
melati - the current Melati
Throws:
Exception - if anything goes wrong

doPoemRequest

protected void doPoemRequest(Melati melati)
                      throws Exception
Description copied from class: PoemServlet
Override this method to build up your own output.

Specified by:
doPoemRequest in class PoemServlet
Throws:
Exception

addExtension

protected String addExtension(String templateName)
The template extension is added in an overridable method to allow the application developer to specify their own template extensions.

To obtain nice URLs one method is to call your templates foo.html.wm for example, your urls can then look like servlet/db/table/troid/method.html.


error

public void error(Melati melati,
                  Exception e)
Send an error message. Single call to the templet loader giving purpose (error) and Exception class. This will look in the purpose directory, the standard templet directory and the classpath, in that order, for a templet. This can no longer fail with NotFoundException, as the Object templet will always be found (or this is a broken installation).

Overrides:
error in class ConfigServlet
Parameters:
melati - the Melati
e - the Exception to report

doTemplateRequest

protected abstract String doTemplateRequest(Melati melati,
                                            ServletTemplateContext templateContext)
                                     throws Exception
Override this method to build up your own output.

Parameters:
melati - the current Melati
templateContext - the current ServletTemplateContext
Returns:
a Template name, possibly excluding extension.
Throws:
Exception


Copyright © 2000-2010 PanEris. All Rights Reserved.