com.acsinet_solutions.util.text
Class TextTemplate

java.lang.Object
  extended by com.acsinet_solutions.util.text.TextTemplate

public final class TextTemplate
extends java.lang.Object

Class that obtains a customized text from a resource. Velocity template framework is used internally to provide templating facilities. See Apache Velocity web site and documentation for more information on templating using that engine.

Author:
Santiago Arriaga

Constructor Summary
TextTemplate(java.lang.String template)
          Public constructor, from a template.
 
Method Summary
 java.lang.String apply(java.util.Map params)
          Apply the given parameter map to the template and generate a string value as a result
 void apply(java.util.Map params, java.io.Writer writer)
          Apply the given parameter map to the template and write the output to the provided writer
static TextTemplate createTemplateFromInputStream(java.io.InputStream istream)
          Create a text template from an input stream
static TextTemplate createTemplateFromResource(java.lang.String resource)
          Create a text template from a named resource
static java.io.Reader transform(java.io.InputStream sourceStream, java.io.InputStream propertiesStream)
          In this method sourceStream represents the template source, and propertiesStream represents a properties file that holds the values of the variables that will be passed as the parameter map to the template to perform the substitution.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TextTemplate

public TextTemplate(java.lang.String template)
Public constructor, from a template.

Method Detail

createTemplateFromResource

public static final TextTemplate createTemplateFromResource(java.lang.String resource)
                                                     throws java.io.IOException
Create a text template from a named resource

Parameters:
resource - The not-null valid resource name
Returns:
A not-null TextTemplateInstance
Throws:
java.io.IOException

createTemplateFromInputStream

public static final TextTemplate createTemplateFromInputStream(java.io.InputStream istream)
                                                        throws java.io.IOException
Create a text template from an input stream

Parameters:
istream - A not-null valid InputStream instance
Returns:
A not-null TextTemplateInstance
Throws:
java.io.IOException

transform

public static final java.io.Reader transform(java.io.InputStream sourceStream,
                                             java.io.InputStream propertiesStream)
                                      throws java.io.IOException,
                                             EvaluationException
In this method sourceStream represents the template source, and propertiesStream represents a properties file that holds the values of the variables that will be passed as the parameter map to the template to perform the substitution. The result will be returned by the current method. This is a very practical way to perform a transformation without creating explicit TextTemplate instances.

Throws:
java.io.IOException
EvaluationException

apply

public final java.lang.String apply(java.util.Map params)
                             throws EvaluationException
Apply the given parameter map to the template and generate a string value as a result

Parameters:
Map - a named map of values
Returns:
A not-null String value
Throws:
EvaluationException

apply

public final void apply(java.util.Map params,
                        java.io.Writer writer)
                 throws EvaluationException
Apply the given parameter map to the template and write the output to the provided writer

Throws:
EvaluationException