org.melati.template.velocity
Class VelocityTemplateEngine

Package class diagram package VelocityTemplateEngine
java.lang.Object
  extended by org.melati.template.AbstractTemplateEngine
      extended by org.melati.template.velocity.VelocityTemplateEngine
All Implemented Interfaces:
TemplateEngine
Direct Known Subclasses:
VelocityServletTemplateEngine

public class VelocityTemplateEngine
extends AbstractTemplateEngine
implements TemplateEngine

Wrapper for the Velocity Template Engine for use with Melati.


Field Summary
static String NAME
          The name of the engine.
 
Fields inherited from class org.melati.template.AbstractTemplateEngine
roots
 
Constructor Summary
VelocityTemplateEngine()
          Constructor.
 
Method Summary
 String expandedTemplate(Template template, TemplateContext templateContext)
          Expand the Template against the context to a String.
 void expandTemplate(MelatiWriter out, String templateName, TemplateContext templateContext)
          Get a Template by name and expand it against a context.
 void expandTemplate(MelatiWriter out, Template template, TemplateContext templateContext)
          Expand a Template against the context.
 Object getEngine()
          Get the underlying engine.
 String getName()
          The name of the template engine (used to find the templets).
 MelatiStringWriter getStringWriter()
          Return a MelatiStringWriter.
 TemplateContext getTemplateContext(Melati melati)
          Get the template context for Velocity.
 void init(MelatiConfig melatiConfig)
          Construct a new Engine.
protected  Properties loadConfiguration()
           
 Template template(String templateName)
          Get a template by name.
 String templateExtension()
           
 
Methods inherited from class org.melati.template.AbstractTemplateEngine
addRoot, getRoots, getTemplateName
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.melati.template.TemplateEngine
addRoot, getRoots, getTemplateName
 

Field Detail

NAME

public static final String NAME
The name of the engine.

See Also:
Constant Field Values
Constructor Detail

VelocityTemplateEngine

public VelocityTemplateEngine()
Constructor.

Method Detail

init

public void init(MelatiConfig melatiConfig)
          throws TemplateEngineException
Construct a new Engine.

Specified by:
init in interface TemplateEngine
Parameters:
melatiConfig - a MelatiConfig
Throws:
TemplateEngineException - if any problem occurs with the engine

loadConfiguration

protected Properties loadConfiguration()

getTemplateContext

public TemplateContext getTemplateContext(Melati melati)
Get the template context for Velocity.

Specified by:
getTemplateContext in interface TemplateEngine
Parameters:
melati - the Melati
Returns:
a TemplateContext

getName

public String getName()
The name of the template engine (used to find the templets).

Specified by:
getName in interface TemplateEngine
Returns:
the name of the current configured template engine

templateExtension

public String templateExtension()
Specified by:
templateExtension in interface TemplateEngine
Returns:
the extension of the templates used by Velocity, including the dot.

template

public Template template(String templateName)
                  throws NotFoundException
Get a template by name.

Specified by:
template in interface TemplateEngine
Parameters:
templateName - the name of the template to find
Returns:
a template
Throws:
NotFoundException - if template not found

expandTemplate

public void expandTemplate(MelatiWriter out,
                           String templateName,
                           TemplateContext templateContext)
                    throws NotFoundException
Get a Template by name and expand it against a context.

Specified by:
expandTemplate in interface TemplateEngine
Parameters:
out - a MelatiWriter to output on
templateName - the name of the template to expand
templateContext - the TemplateContext to expand the template against
Throws:
NotFoundException - if template not found

expandTemplate

public void expandTemplate(MelatiWriter out,
                           Template template,
                           TemplateContext templateContext)
Expand a Template against the context.

Specified by:
expandTemplate in interface TemplateEngine
Parameters:
out - a MelatiWriter to output on
template - the Template to expand
templateContext - the TemplateContext to expand the template against

expandedTemplate

public String expandedTemplate(Template template,
                               TemplateContext templateContext)
Expand the Template against the context to a String.

Specified by:
expandedTemplate in interface TemplateEngine
Parameters:
template - the Template to expand
templateContext - the TemplateContext to expand the template against
Returns:
the interpolated template as a String the interpolated template as a String
See Also:
TemplateEngine.expandedTemplate(org.melati.template.Template, org.melati.template.TemplateContext)

getStringWriter

public MelatiStringWriter getStringWriter()
Return a MelatiStringWriter.

Specified by:
getStringWriter in interface TemplateEngine
Returns:
a MelatiStringWriter a MelatiStringWriter.
See Also:
Melati.getStringWriter(), TemplateEngine.getStringWriter()

getEngine

public Object getEngine()
Get the underlying engine.

Specified by:
getEngine in interface TemplateEngine
Returns:
null - for velocity there is none.


Copyright © 2000-2010 PanEris. All Rights Reserved.