temmental
Class Template

java.lang.Object
  extended by temmental.Template

public class Template
extends java.lang.Object

Read and manipulate a template file to write data on an output stream.

Many constructors are available:


When the template is created, you can call public methods to write a part of the file or the whole file on the
output stream. Tags are replaced by their value defined in the model Map.

For a better documentation: http://temmental.sourceforge.net/


Constructor Summary
Template(java.lang.String filepath, java.util.Map<java.lang.String,? extends ObjectFilter> filters, java.util.Locale locale, java.lang.Object... resourcesContainers)
           
Template(java.lang.String filepath, java.util.Map<java.lang.String,? extends ObjectFilter> filters, java.util.Properties properties)
          Create a template with the given parameters.
Template(java.lang.String filepath, java.util.Map<java.lang.String,? extends ObjectFilter> filters, java.util.Properties properties, java.util.Locale locale)
          Create a template with the given parameters.
Template(java.lang.String filepath, java.util.Map<java.lang.String,? extends ObjectFilter> filters, java.util.ResourceBundle bundle)
          Create a template with the given parameters.
Template(java.lang.String filepath, java.util.Map<java.lang.String,? extends ObjectFilter> filters, java.lang.String resourcePath)
          Create a template with the given parameters.
Template(java.lang.String filepath, java.util.Map<java.lang.String,? extends ObjectFilter> filters, java.lang.String resourcePath, java.util.Locale locale)
          Create a template with the given parameters.
 
Method Summary
 TemplateMessages getMessages()
           
 boolean hasSection(java.lang.String sectionName)
          Tests if the given section exists in the template
 void printFile(java.io.Writer out)
          Prints the whole file on the stream.
 void printFile(java.io.Writer out, java.util.Map<java.lang.String,? extends java.lang.Object> model)
          Prints the whole file on the stream.
 void printSection(java.io.Writer out, java.lang.String sectionName)
          Prints a section of the file on the stream.
 void printSection(java.io.Writer out, java.lang.String sectionName, java.util.Map<java.lang.String,? extends java.lang.Object> model)
          Prints a section of the file on the stream.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Template

public Template(java.lang.String filepath,
                java.util.Map<java.lang.String,? extends ObjectFilter> filters,
                java.util.Properties properties)
         throws java.io.IOException,
                TemplateException
Create a template with the given parameters. The default locale is used to retrieve localized messages and format messages (date, numbers...).

Parameters:
filepath - the path to the template file to parse
filters - the map of filters
properties - the messages
Throws:
java.io.IOException - if an I/O error occurs when reading the template file
TemplateException - if an other error occurs when reading the template file

Template

public Template(java.lang.String filepath,
                java.util.Map<java.lang.String,? extends ObjectFilter> filters,
                java.util.Locale locale,
                java.lang.Object... resourcesContainers)
         throws java.io.IOException,
                TemplateException
Throws:
java.io.IOException
TemplateException

Template

public Template(java.lang.String filepath,
                java.util.Map<java.lang.String,? extends ObjectFilter> filters,
                java.util.Properties properties,
                java.util.Locale locale)
         throws java.io.IOException,
                TemplateException
Create a template with the given parameters.

Parameters:
filepath - the path to the template file to parse
filters - the map of filters
properties - the messages
locale - locale to use to format messages (date, numbers...)
Throws:
java.io.IOException - if an I/O error occurs when reading the template file
TemplateException - if an other error occurs when reading the template file

Template

public Template(java.lang.String filepath,
                java.util.Map<java.lang.String,? extends ObjectFilter> filters,
                java.util.ResourceBundle bundle)
         throws java.io.IOException,
                TemplateException
Create a template with the given parameters.

Parameters:
filepath - the path to the template file to parse
filters - the map of filters
bundle - the messages
Throws:
java.io.IOException - if an I/O error occurs when reading the template file
TemplateException - if an other error occurs when reading the template file

Template

public Template(java.lang.String filepath,
                java.util.Map<java.lang.String,? extends ObjectFilter> filters,
                java.lang.String resourcePath)
         throws java.io.IOException,
                TemplateException
Create a template with the given parameters. The default locale is used to retrieve localized messages and format messages (date, numbers...).

Parameters:
filepath - the path to the template file to parse
filters - the map of filters
resourcePath - the messages (classpath:path.to.my.file or file:/path/to/my/file.properties)
Throws:
java.io.IOException - if an I/O error occurs when reading the template file
TemplateException - if an other error occurs when reading the template file

Template

public Template(java.lang.String filepath,
                java.util.Map<java.lang.String,? extends ObjectFilter> filters,
                java.lang.String resourcePath,
                java.util.Locale locale)
         throws java.io.IOException,
                TemplateException
Create a template with the given parameters.

Parameters:
filepath - the path to the template file to parse
filters - the map of filters
resourcePath - the messages (classpath:path.to.my.file or file:/path/to/my/file.properties)
locale - locale to retrieve localized messages and format messages (date, numbers...)
Throws:
java.io.IOException - if an I/O error occurs when reading the template file
TemplateException - if an other error occurs when reading the template file
Method Detail

hasSection

public boolean hasSection(java.lang.String sectionName)
Tests if the given section exists in the template

Parameters:
sectionName - the possible section name
Returns:
true if the section exists, false otherwise.

printFile

public void printFile(java.io.Writer out)
               throws TemplateException,
                      java.io.IOException
Prints the whole file on the stream.

Parameters:
out - the stream
Throws:
TemplateException - if an error is detected by the template engine
java.io.IOException - if an I/O error occurs

printFile

public void printFile(java.io.Writer out,
                      java.util.Map<java.lang.String,? extends java.lang.Object> model)
               throws TemplateException,
                      java.io.IOException
Prints the whole file on the stream.

Parameters:
out - the stream
model - the model
Throws:
TemplateException - if an error is detected by the template engine
java.io.IOException - if an I/O error occurs

printSection

public void printSection(java.io.Writer out,
                         java.lang.String sectionName,
                         java.util.Map<java.lang.String,? extends java.lang.Object> model)
                  throws TemplateException,
                         java.io.IOException
Prints a section of the file on the stream. The tags are replaced by the corresponding values in the model.

Parameters:
out - the stream
sectionName - the section to display
model - the model
Throws:
TemplateException - if an error is detected by the template engine
java.io.IOException - if an I/O error occurs

printSection

public void printSection(java.io.Writer out,
                         java.lang.String sectionName)
                  throws TemplateException,
                         java.io.IOException
Prints a section of the file on the stream.

Parameters:
out - the stream
sectionName - the section to display
Throws:
TemplateException - if an error is detected by the template engine
java.io.IOException - if an I/O error occurs

getMessages

public TemplateMessages getMessages()