toolbox.services.util
Class FreeMarkerTemplateServiceImpl

Package class diagram package FreeMarkerTemplateServiceImpl
java.lang.Object
  extended by toolbox.services.BaseService
      extended by toolbox.services.util.FreeMarkerTemplateServiceImpl
All Implemented Interfaces:
Service, TemplateService

public class FreeMarkerTemplateServiceImpl
extends BaseService
implements TemplateService

FreeMarker based implementation of the TemplateService interface.

This service must be configured with an XML configuration document similar to the following:

   <?xml version="1.0"?>
     <FreeMarkerTemplateServiceImpl>
       <config>
        <directories>
          <directory relative="true">
            /ftl
          </directory>
         <directory relative="false">
            /opt/foo/blah
          </directory>
        </directories>
      </config>
    </FreeMarkerTemplateServiceImpl>
 


Constructor Summary
FreeMarkerTemplateServiceImpl()
          Default constructor.
 
Method Summary
 void create(java.lang.String name, java.lang.String confHome, ServiceEnvironment env, XMLProperties xmlProps)
          Initialise the FreeMarker configuration.
 java.lang.String process(java.lang.String tmpl, java.util.Map data)
          Process the named template and return a String.
 void process(java.lang.String tmpl, java.util.Map data, java.io.OutputStream out)
          Process the named template and write the output to the given stream.
 
Methods inherited from class toolbox.services.BaseService
destroy, getConfigHome, getName, getProperties, getProperty, getXMLProperties, logConfig, logFine, logFiner, logFinest, logInfo, logSevere, logWarning
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FreeMarkerTemplateServiceImpl

public FreeMarkerTemplateServiceImpl()
Default constructor.

Method Detail

create

public void create(java.lang.String name,
                   java.lang.String confHome,
                   ServiceEnvironment env,
                   XMLProperties xmlProps)
            throws ServiceException
Initialise the FreeMarker configuration.

Specified by:
create in interface Service
Overrides:
create in class BaseService
Parameters:
name - The name of the service.
confHome - The path to the configuration home directory.
env - ServiceEnvironment of this service.
xmlProps - XML configuration properties.
Throws:
ServiceException - if the service cannot be created.

process

public java.lang.String process(java.lang.String tmpl,
                                java.util.Map data)
                         throws ServiceException
Process the named template and return a String.

Specified by:
process in interface TemplateService
Parameters:
tmpl - String containing the template path.
data - Map instance containing the data to merge with the template.
Returns:
String containing the generated content.
Throws:
ServiceException - if the template cannot be processed.

process

public void process(java.lang.String tmpl,
                    java.util.Map data,
                    java.io.OutputStream out)
             throws ServiceException
Process the named template and write the output to the given stream.

Specified by:
process in interface TemplateService
Parameters:
tmpl - String containing the template path.
data - Map instance containing the data to merge with the template.
out - OutputStream instance to write the output to.
Throws:
ServiceException - if the template cannot be processed.