|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--javax.servlet.GenericServlet | +--javax.servlet.http.HttpServlet | +--org.webmacro.servlet.WMServlet
This is the abstract base class used by all WebMacro servlets. 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.
org.webmacro.Handler
,
Broker
, Serialized FormFields inherited from interface org.webmacro.WebMacro |
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 |
FastWriter |
getFastWriter(java.io.OutputStream out,
java.lang.String enctype)
Retrieve a FastWriter from WebMacro's internal pool of FastWriters. |
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 |
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()
This method must return a cloneable WebContext which can be cloned for use in responding to individual requests. |
WebMacro |
initWebMacro()
This method returns the WebMacro object which will be used to load, access, and manage the Broker. |
boolean |
isDestroyed()
Check whether or not the broker we are using has been shut down |
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. |
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 |
Constructor Detail |
public WMServlet()
Method Detail |
public final void init(javax.servlet.ServletConfig sc) throws javax.servlet.ServletException
init
in class javax.servlet.GenericServlet
javax.servlet.ServletException
- if it failed to initializepublic final void init()
init
in class javax.servlet.GenericServlet
public final void destroy()
destroy
in interface WebMacro
destroy
in class javax.servlet.GenericServlet
public final boolean isDestroyed()
isDestroyed
in interface WebMacro
protected final void doGet(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp) throws javax.servlet.ServletException, java.io.IOException
doGet
in class javax.servlet.http.HttpServlet
req
- the request we gotresp
- the response we are generatingjavax.servlet.ServletException
- if we can't get our configurationjava.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
doPost
in class javax.servlet.http.HttpServlet
req
- the request we gotresp
- the response we are generatingjavax.servlet.ServletException
- if we can't get our configurationjava.io.IOException
- if we can't read/write to the streams we gotprotected final Template error(WebContext context, java.lang.String error)
context
- will add error variable to context (see Config)error
- a string explaining what went wrongpublic final Broker getBroker()
getBroker
in interface WebMacro
public final Log getLog(java.lang.String type, java.lang.String description)
getLog
in interface WebMacro
public final Log getLog(java.lang.String type)
getLog
in interface WebMacro
public final Template getTemplate(java.lang.String key) throws ResourceException
getTemplate
in interface WebMacro
NotFoundException
- if the template was not foundResourceException
- if the template coult not be loadedpublic final java.lang.String getURL(java.lang.String url) throws ResourceException
getURL
in interface WebMacro
public final java.lang.String getConfig(java.lang.String key) throws NotFoundException
getConfig
in interface WebMacro
NotFoundException
- could not locate requested informationpublic final java.lang.String getConfig(java.lang.String key, java.lang.String defaultValue)
public final Context getContext()
getContext
in interface WebMacro
public final 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 phasejava.io.IOException
- if the template cannot be written to the
specified output streamResourceException
- if the template name specified cannot be foundPropertyException
- 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 phasejava.io.IOException
- if the template cannot be written to the
specified output streamResourceException
- if the template name specified cannot be foundPropertyException
- if a fatal error occured during the Template
evaluation phaseprotected final void execute(Template tmpl, WebContext c) throws java.io.IOException
public WebContext newContext(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp) throws HandlerException
public abstract Template handle(WebContext context) throws HandlerException
context
- contains all relevant data structures, incl builtins.HandlerException
- throw this to produce vanilla error messagesgetTemplate
public void destroyContext(WebContext wc) throws HandlerException
protected void start() throws javax.servlet.ServletException
javax.servlet.ServletException
- to indicate initialization failedprotected void stop()
public WebMacro initWebMacro() throws InitException
public WebContext initWebContext() throws InitException
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
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |