public abstract class AbstractTemplate extends AbstractModule implements Template
A base implementation for templates. Performs common actions to most templates. Among these, parses from the initialisation parameters values for many of the template variables, these are defined in variables named templateKey, templateVersion, templateMimeType and templateEncoding. Also templateCaching and templateFile which are not in the Template interface but are common template features.
A default template context can also be specified in the initialisation parameters using the parameter name prefix "context.". The rest of parameter name is used as the variable name in the context.
This base implementation automatically registers the template to a TemplateManager at module start, as all templates should do to be usable.
Modifier and Type | Field and Description |
---|---|
protected boolean |
templateCaching |
protected java.util.HashMap<java.lang.String,java.lang.Object> |
templateContext |
protected java.lang.String |
templateEncoding |
protected java.lang.String |
templateFile |
protected java.lang.String |
templateKey |
protected TemplateManager |
templateManager |
protected java.lang.String |
templateMime |
protected java.lang.String |
templateVersion |
autoStart, isInitialized, isRunning, logging, loggingModule, moduleManager
Constructor and Description |
---|
AbstractTemplate() |
Modifier and Type | Method and Description |
---|---|
java.util.Collection<Module> |
getDependencies(ModuleManager manager)
Returns all the modules this module depends on.
|
java.lang.String |
getEncoding()
Returns the character encoding used by the returned content.
|
protected java.lang.String |
getFullTemplatePath() |
java.lang.String |
getKey()
Returns the template key.
|
java.lang.String |
getMimeType()
Returns the mime type of the content from this template.
|
java.util.HashMap<java.lang.String,java.lang.Object> |
getTemplateContext()
Returns the default context for this template.
|
java.lang.String |
getVersion()
Returns the template version.
|
void |
init(ModuleManager manager,
java.util.HashMap<java.lang.String,java.lang.Object> settings)
Initialises the module.
|
abstract void |
process(java.util.HashMap<java.lang.String,java.lang.Object> params,
java.io.OutputStream output)
Processes the template with the given context and writes the resulting
content in the output stream.
|
void |
start(ModuleManager manager)
Starts the module.
|
void |
stop(ModuleManager manager)
Stops the module.
|
isInitialized, isRunning, requireLogging, toString
protected TemplateManager templateManager
protected java.lang.String templateKey
protected java.lang.String templateVersion
protected java.lang.String templateMime
protected java.lang.String templateEncoding
protected boolean templateCaching
protected java.lang.String templateFile
protected java.util.HashMap<java.lang.String,java.lang.Object> templateContext
public void init(ModuleManager manager, java.util.HashMap<java.lang.String,java.lang.Object> settings) throws ModuleException
Module
Initialises the module. After constructor, this is the first method called in the life cycle of a module. It should not perform anything time consuming or anything with notable outside side effects. It should only read the parameters and initialise the module so that it can later be started. Note that a module being initialised doesn't mean that it necessarily will ever be started.
A ModuleException may be thrown if something vital is missing from the parameters or they are not sensible. In some cases you may not want to throw an exception even if vital initialisation information is missing. If, for example, it is possible that the module is initialised in some other way between the init and the start method calls. A ModuleException may also be thrown at the start method if the module is still not initialised.
init
in interface Module
init
in class AbstractModule
manager
- The module manager handling this module. You may keep a
reference to it if needed.ModuleException
public java.util.HashMap<java.lang.String,java.lang.Object> getTemplateContext()
Template
getTemplateContext
in interface Template
protected java.lang.String getFullTemplatePath()
public java.util.Collection<Module> getDependencies(ModuleManager manager) throws ModuleException
Module
getDependencies
in interface Module
getDependencies
in class AbstractModule
manager
- The module manager handling this module.ModuleException
public void start(ModuleManager manager) throws ModuleException
Module
start
in interface Module
start
in class AbstractModule
manager
- The module manager handling this module.ModuleException
public void stop(ModuleManager manager)
Module
stop
in interface Module
stop
in class AbstractModule
manager
- The module manager handling this module.public java.lang.String getKey()
Template
public java.lang.String getVersion()
Template
getVersion
in interface Template
public java.lang.String getMimeType()
Template
getMimeType
in interface Template
public java.lang.String getEncoding()
Template
getEncoding
in interface Template
public abstract void process(java.util.HashMap<java.lang.String,java.lang.Object> params, java.io.OutputStream output)
Template
Copyright 2004-2015 Wandora Team