org.melati.template
Interface TemplateEngine

Package class diagram package TemplateEngine
All Known Subinterfaces:
ServletTemplateEngine
All Known Implementing Classes:
AbstractTemplateEngine, NoTemplateEngine, VelocityServletTemplateEngine, VelocityTemplateEngine, WebmacroServletTemplateEngine, WebmacroTemplateEngine

public interface TemplateEngine

A TemplateEngine typically evaluates a template containing variables against a context containing values for those variables. The canonical java Template Engines are WebMacro and Velocity.

Author:
timp At paneris.org

Method Summary
 void addRoot(String root)
          Add a template root directory.
 String expandedTemplate(Template template, TemplateContext templateContext)
          Expand the Template against the context and return the expansion as a string.
 void expandTemplate(MelatiWriter out, String templateName, TemplateContext templateContext)
          Expand the Template against the context.
 void expandTemplate(MelatiWriter out, Template template, TemplateContext templateContext)
          Expand the Template against the context, unwrapping any Access Exceptions.
 Object getEngine()
          Get the underlying engine.
 String getName()
          The name of the template engine (used to find the templets).
 Enumeration<String> getRoots()
          A root should not end in a slash.
 MelatiStringWriter getStringWriter()
           
 TemplateContext getTemplateContext(Melati melati)
          Create a new Context for this engine.
 String getTemplateName(String key, String classifier)
          The name of a template which exists.
 void init(MelatiConfig melatiConfig)
          Initialise the Engine.
 Template template(String templateName)
          Get a template given it's full name.
 String templateExtension()
           
 

Method Detail

init

void init(MelatiConfig melatiConfig)
          throws TemplateEngineException
Initialise the Engine.

Parameters:
melatiConfig - a MelatiConfig
Throws:
TemplateEngineException - if any problem occurs with the engine

getTemplateContext

TemplateContext getTemplateContext(Melati melati)
                                   throws TemplateEngineException
Create a new Context for this engine.

Parameters:
melati - the Melati
Returns:
a TemplateContext
Throws:
TemplateEngineException - if any problem occurs with the engine

getName

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

Returns:
the name of the current configured template engine

templateExtension

String templateExtension()
Returns:
the extension of the templates used by this template engine, including the dot.

getRoots

Enumeration<String> getRoots()
A root should not end in a slash.

Returns:
an Enumeration of string roots, always at least the empty string

addRoot

void addRoot(String root)
Add a template root directory. NOTE A root should not start or end in a slash.

Parameters:
root - the root to add

template

Template template(String templateName)
                  throws NotFoundException
Get a template given it's full name.

Parameters:
templateName - the name of the template to find
Returns:
a template
Throws:
NotFoundException - if template not found

getTemplateName

String getTemplateName(String key,
                       String classifier)
The name of a template which exists.

Parameters:
key - short name, without path or extension
classifier - a purpose or database name or similar qualifier
Returns:
the name of a template, null if none found

expandTemplate

void expandTemplate(MelatiWriter out,
                    String templateName,
                    TemplateContext templateContext)
                    throws NotFoundException
Expand the Template against the context.

Parameters:
out - a MelatiWriter to output on
templateName - the name of the template to expand
templateContext - the ServletTemplateContext to expand the template against
Throws:
NotFoundException - if template not found

expandTemplate

void expandTemplate(MelatiWriter out,
                    Template template,
                    TemplateContext templateContext)
Expand the Template against the context, unwrapping any Access Exceptions.

Parameters:
out - a MelatiWriter to output on
template - the Template to expand
templateContext - the ServletTemplateContext to expand the template against

expandedTemplate

String expandedTemplate(Template template,
                        TemplateContext templateContext)
Expand the Template against the context and return the expansion as a string.

Parameters:
template - the Template to expand
templateContext - the ServletTemplateContext to expand the template against
Returns:
the interpolated template as a String

getStringWriter

MelatiStringWriter getStringWriter()
Returns:
a MelatiStringWriter.
See Also:
Melati.getStringWriter()

getEngine

Object getEngine()
Get the underlying engine.

Returns:
the configured template engine


Copyright © 2000-2010 PanEris. All Rights Reserved.