net.sourceforge.rtf.template
Class AbstractTemplateEngine

java.lang.Object
  extended by net.sourceforge.rtf.template.AbstractTemplateEngine
All Implemented Interfaces:
ITemplateEngine
Direct Known Subclasses:
FreemarkerTemplateEngineImpl, VelocityTemplateEngineImpl

public abstract class AbstractTemplateEngine
extends java.lang.Object
implements ITemplateEngine


Field Summary
protected  java.util.Map formats
          Formats to use for formatting of values.
protected  java.io.Reader template
          Reader that contains the template.
 
Constructor Summary
AbstractTemplateEngine()
           
 
Method Summary
protected  java.lang.Object escapeSpecialCharacters(java.lang.Object value)
          Escape special chracters { and } with \{ and \} otherwise, RTF document generated is not valid.
 IContext getContext()
           
 java.text.Format getDefaultFormat(java.lang.Class clazz)
          Get the default format for a given class.
 IContext initializeContext()
          Initialize context.
 void merge(java.io.File file)
          Merge.
 void merge(java.lang.String file)
          Merge.
 void merge(java.io.Writer writer)
          Merge.
protected abstract  void mergeWithTemplateEngine(java.io.Writer writer)
           
 boolean mustBeEscaped(java.lang.Object value)
          Return true if value must be escaped and false otherwise
 void put(java.lang.String key, java.lang.Object value)
          Put a value for the given key.
protected  void setContext(IContext context)
           
 void setDefaultFormat(java.lang.Class clazz, java.text.Format format)
          Set the default format for a given class.
 void setFormatMap(java.util.Map commonFormats)
          Use a pre-populated formats map as the map for this template
 void setGlobalContext(IContext globalContext)
          Use a pre-populated Context.
 void setTemplate(java.io.Reader template)
          Set the template to use
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface net.sourceforge.rtf.ITemplateEngine
newContext
 

Field Detail

formats

protected java.util.Map formats
Formats to use for formatting of values.


template

protected java.io.Reader template
Reader that contains the template.

Constructor Detail

AbstractTemplateEngine

public AbstractTemplateEngine()
Method Detail

put

public void put(java.lang.String key,
                java.lang.Object value)
Put a value for the given key.

Specified by:
put in interface ITemplateEngine
Parameters:
key -
value -

merge

public void merge(java.lang.String file)
           throws java.lang.Exception
Merge.

Specified by:
merge in interface ITemplateEngine
Parameters:
file - name of file to merge into
Throws:
java.lang.Exception

merge

public void merge(java.io.File file)
           throws java.lang.Exception
Merge.

Specified by:
merge in interface ITemplateEngine
Parameters:
file - file to merge into
Throws:
java.lang.Exception

merge

public void merge(java.io.Writer writer)
           throws java.lang.Exception
Description copied from interface: ITemplateEngine
Merge.

Specified by:
merge in interface ITemplateEngine
Parameters:
writer - writer to merge into
Throws:
java.lang.Exception

setFormatMap

public void setFormatMap(java.util.Map commonFormats)
Use a pre-populated formats map as the map for this template

Parameters:
commonFormats - a pre-built map of formats

setDefaultFormat

public void setDefaultFormat(java.lang.Class clazz,
                             java.text.Format format)
Set the default format for a given class.

Specified by:
setDefaultFormat in interface ITemplateEngine
Parameters:
clazz - class to set format for
format - format to use for instances of the given class

getDefaultFormat

public java.text.Format getDefaultFormat(java.lang.Class clazz)
Get the default format for a given class.

Parameters:
clazz - class to get default format for
Returns:
format

setContext

protected void setContext(IContext context)

getContext

public IContext getContext()
Specified by:
getContext in interface ITemplateEngine

setTemplate

public void setTemplate(java.io.Reader template)
Description copied from interface: ITemplateEngine
Set the template to use

Specified by:
setTemplate in interface ITemplateEngine

mustBeEscaped

public boolean mustBeEscaped(java.lang.Object value)
Return true if value must be escaped and false otherwise

Parameters:
value -
Returns:

escapeSpecialCharacters

protected java.lang.Object escapeSpecialCharacters(java.lang.Object value)
Escape special chracters { and } with \{ and \} otherwise, RTF document generated is not valid.

Parameters:
value -
Returns:

initializeContext

public IContext initializeContext()
Description copied from interface: ITemplateEngine
Initialize context. must be called if the same instance of template engine must be used for merge serveral RTF template model.

Specified by:
initializeContext in interface ITemplateEngine

setGlobalContext

public void setGlobalContext(IContext globalContext)
Use a pre-populated Context. This method treats any previously populated keys in the context kindly, so it won't act unpredictably if this is called late

Specified by:
setGlobalContext in interface ITemplateEngine
Parameters:
innerContext - a pre-populated Context object

mergeWithTemplateEngine

protected abstract void mergeWithTemplateEngine(java.io.Writer writer)
                                         throws java.lang.Exception
Throws:
java.lang.Exception


Copyright 2007 null. All Rights Reserved.