|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjavax.servlet.GenericServlet
javax.servlet.http.HttpServlet
org.webmacro.servlet.WMServlet
This is an abstract base class which can be used to implement a kind of WebMacro servlet. You can either subclass from it directly, or make use of one of the generic subclasses provided.
It's primary function is to create a WebContext and manage a Broker. It also provides a couple of convenience functions that access the Broker and/or WebContext to make some commonly accessed services more readily available.
Broker
,
Serialized FormField Summary | |
protected Log |
_log
Log object used to write out messages |
Fields inherited from interface org.webmacro.WebMacro |
BUILD_DATE, VERSION |
Constructor Summary | |
WMServlet()
|
Method Summary | |
void |
destroy()
This method is called by the servlet runner--do not call it. |
void |
destroyContext(WebContext wc)
This method is called at the end of a request and is responsible for cleaning up the Context at the end of the request. |
protected void |
doGet(javax.servlet.http.HttpServletRequest req,
javax.servlet.http.HttpServletResponse resp)
Process an incoming GET request: Builds a WebContext up and then passes it to the handle() method. |
protected void |
doPost(javax.servlet.http.HttpServletRequest req,
javax.servlet.http.HttpServletResponse resp)
Behaves exactly like doGet() except that it reads data from POST before doing exactly the same thing. |
protected Template |
error(WebContext context,
java.lang.String error)
Create an error template using the built in error handler. |
protected void |
execute(Template tmpl,
WebContext c)
This method takes a populated context and a template and writes out the interpreted template to the context's output stream. |
Broker |
getBroker()
This object is used to access components that have been plugged into WebMacro; it is shared between all instances of this class and its subclasses. |
java.lang.String |
getConfig(java.lang.String key)
Retrieve configuration information from the "config" provider. |
java.lang.String |
getConfig(java.lang.String key,
java.lang.String defaultValue)
Retrieve configuration information from the "config" provider. |
Context |
getContext()
Create a new Context object |
Template |
getErrorTemplate()
Gets a template for displaying an error message. |
protected java.lang.String |
getErrorTemplateName()
|
protected java.lang.String |
getErrorVariableName()
Returns the name of the error variable, as per the config. |
FastWriter |
getFastWriter(java.io.OutputStream out,
java.lang.String enctype)
Deprecated. |
Log |
getLog(java.lang.String type)
Get a Log object which can be used to write to the log file. |
Log |
getLog(java.lang.String type,
java.lang.String description)
Get a Log object which can be used to write to the log file. |
Template |
getTemplate(java.lang.String key)
Retrieve a template from the "template" provider. |
java.lang.String |
getURL(java.lang.String url)
Retrieve a URL. |
WebContext |
getWebContext(javax.servlet.http.HttpServletRequest req,
javax.servlet.http.HttpServletResponse res)
Create a new WebContext object; can be overridden |
abstract Template |
handle(WebContext context)
This method is called to handle the processing of a request. |
void |
init()
This method is called by the servlet runner--do not call it. |
void |
init(javax.servlet.ServletConfig sc)
This is the old-style init method, it just calls init(), after handing the ServletConfig object to the superclass |
WebContext |
initWebContext()
Deprecated. |
WebMacro |
initWebMacro()
This method returns the WebMacro object which will be used to load, access, and manage the Broker. |
WebContext |
newContext(javax.servlet.http.HttpServletRequest req,
javax.servlet.http.HttpServletResponse resp)
This method is called at the beginning of a request and is responsible for providing a Context for the request. |
WebContext |
newWebContext(javax.servlet.http.HttpServletRequest req,
javax.servlet.http.HttpServletResponse resp)
|
protected void |
setLocale(javax.servlet.http.HttpServletResponse resp,
java.util.Locale locale)
Set the locale on the response. |
protected void |
start()
Override this method to implement any startup/init code you require. |
protected void |
stop()
Override this method to implement any shutdown code you require. |
void |
writeTemplate(java.lang.String templateName,
java.io.OutputStream out,
Context context)
Convenience method for writing a template to an OutputStream. |
void |
writeTemplate(java.lang.String templateName,
java.io.OutputStream out,
java.lang.String encoding,
Context context)
Convienence method for writing a template to an OutputStream. |
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, log, log |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
protected Log _log
Constructor Detail |
public WMServlet()
Method Detail |
public void init(javax.servlet.ServletConfig sc) throws javax.servlet.ServletException
init
in interface javax.servlet.Servlet
javax.servlet.ServletException
- if it failed to initializepublic void init()
public void destroy()
destroy
in interface WebMacro
WM.destroy()
protected void doGet(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp) throws javax.servlet.ServletException, java.io.IOException
req
- the request we gotresp
- the response we are generating
javax.servlet.ServletException
- if we can't get our configuration
java.io.IOException
- if we can't write to the output streamprotected void doPost(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp) throws javax.servlet.ServletException, java.io.IOException
req
- the request we gotresp
- the response we are generating
javax.servlet.ServletException
- if we can't get our configuration
java.io.IOException
- if we can't read/write to the streams we gotprotected Template error(WebContext context, java.lang.String error)
context
- will add error variable to context (see Config)error
- a string explaining what went wrongprotected java.lang.String getErrorVariableName()
Returns the name of the error variable, as per the config.
public Broker getBroker()
getBroker
in interface WebMacro
public Log getLog(java.lang.String type, java.lang.String description)
getLog
in interface WebMacro
public Log getLog(java.lang.String type)
getLog
in interface WebMacro
public Template getTemplate(java.lang.String key) throws ResourceException
getTemplate
in interface WebMacro
NotFoundException
- if the template was not found
ResourceException
- if the template coult not be loadedpublic java.lang.String getURL(java.lang.String url) throws ResourceException
getURL
in interface WebMacro
ResourceException
public java.lang.String getConfig(java.lang.String key) throws NotFoundException
getConfig
in interface WebMacro
NotFoundException
- could not locate requested informationpublic java.lang.String getConfig(java.lang.String key, java.lang.String defaultValue)
public Context getContext()
getContext
in interface WebMacro
public WebContext getWebContext(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse res)
getWebContext
in interface WebMacro
public void writeTemplate(java.lang.String templateName, java.io.OutputStream out, Context context) throws java.io.IOException, ResourceException, PropertyException
This method uses the default TemplateOutputEncoding
specified in
WebMacro.defaults or your custom WebMacro.properties.
writeTemplate
in interface WebMacro
templateName
- name of Template to write. Must be accessible
via TemplatePathout
- where the output of the template should gocontext
- The Context (can be a WebContext too) used
during the template evaluation phase
java.io.IOException
- if the template cannot be written to the
specified output stream
ResourceException
- if the template name specified cannot be found
PropertyException
- if a fatal error occured during the Template
evaluation phasepublic void writeTemplate(java.lang.String templateName, java.io.OutputStream out, java.lang.String encoding, Context context) throws java.io.IOException, ResourceException, PropertyException
writeTemplate
in interface WebMacro
templateName
- name of Template to write. Must be accessible
via TemplatePathout
- where the output of the template should goencoding
- character encoding to use when writing the template
if the encoding is null
, the default
TemplateOutputEncoding
is usedcontext
- The Context (can be a WebContext too) used
during the template evaluation phase
java.io.IOException
- if the template cannot be written to the
specified output stream
ResourceException
- if the template name specified cannot be found
PropertyException
- if a fatal error occured during the Template
evaluation phaseprotected void execute(Template tmpl, WebContext c) throws java.io.IOException
java.io.IOException
public WebContext newContext(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp) throws HandlerException
HandlerException
public abstract Template handle(WebContext context) throws HandlerException
context
- contains all relevant data structures, incl builtins.
HandlerException
- throw this to produce vanilla error messagespublic void destroyContext(WebContext wc) throws HandlerException
HandlerException
protected void start() throws javax.servlet.ServletException
javax.servlet.ServletException
- to indicate initialization failedprotected void stop()
public WebMacro initWebMacro() throws InitException
InitException
public final WebContext initWebContext() throws InitException
InitException
public WebContext newWebContext(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp)
protected void setLocale(javax.servlet.http.HttpServletResponse resp, java.util.Locale locale)
public FastWriter getFastWriter(java.io.OutputStream out, java.lang.String enctype) throws java.io.UnsupportedEncodingException
getFastWriter
in interface WebMacro
out
- The output stream the FastWriter should write to. Typically
this will be your ServletOutputStreamenctype
- the Encoding type to use
java.io.UnsupportedEncodingException
- if the encoding type
specified is not supported by your JVM.public Template getErrorTemplate()
protected java.lang.String getErrorTemplateName()
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |