org.tigris.scarab.services.email
Class VelocityEmailService

java.lang.Object
  extended byorg.apache.fulcrum.BaseService
      extended byorg.apache.fulcrum.template.BaseTemplateEngineService
          extended byorg.tigris.scarab.services.email.VelocityEmailService
All Implemented Interfaces:
EmailService, org.apache.fulcrum.Service, org.apache.fulcrum.template.TemplateEngineService

public class VelocityEmailService
extends org.apache.fulcrum.template.BaseTemplateEngineService
implements EmailService

This is a Service that can process Velocity templates from within a Turbine Screen. Here's an example of how you might use it from a screen:

 Context context = new VelocityContext();
 context.put("message", "Hello from Turbine!");
 String results = TurbineVelocity.handleRequest(context,"HelloWorld.vm");
 
Character sets map codes to glyphs, while encodings map between chars/bytes and codes. bytes -> [encoding] -> charset -> [rendering] -> glyphs

This copy of TurbineVelocityService has been slightly modified from its original form to support toggling of Scarab's cross-site scripting filter.

Version:
$Id: VelocityEmailService.java 9104 2004-05-10 21:04:51Z dabbous $
Author:
Dave Bryson, Rafal Krzewski, Jason van Zyl, Sean Legassick, Daniel Rall, Jon S. Stevens, Martin Poeschl, James Taylor

Field Summary
 
Fields inherited from class org.apache.fulcrum.BaseService
isInitialized, name, serviceBroker
 
Fields inherited from interface org.tigris.scarab.services.email.EmailService
SERVICE_NAME
 
Fields inherited from interface org.apache.fulcrum.template.TemplateEngineService
DEFAULT_LAYOUT_TEMPLATE, DEFAULT_PAGE_TEMPLATE, DEFAULT_TEMPLATE_EXTENSION, TEMPLATE_EXTENSIONS
 
Constructor Summary
VelocityEmailService()
           
 
Method Summary
 java.lang.String handleRequest(org.apache.velocity.context.Context context, java.lang.String filename)
          Process the request and fill in the template using the values set in context.
 void handleRequest(org.apache.velocity.context.Context context, java.lang.String filename, java.io.OutputStream output)
          Process the request and fill in the template using the values set in context.
 void handleRequest(org.apache.velocity.context.Context context, java.lang.String filename, java.io.OutputStream output, java.lang.String charset, java.lang.String encoding)
          Process the request and fill in the template using the values set in context.
 java.lang.String handleRequest(org.apache.velocity.context.Context context, java.lang.String filename, java.lang.String charset, java.lang.String encoding)
          Process the request and fill in the template using the values set in context.
 void handleRequest(org.apache.velocity.context.Context context, java.lang.String filename, java.io.Writer writer)
          Process the request and fill in the template using the values set in context.
 void handleRequest(org.apache.velocity.context.Context context, java.lang.String filename, java.io.Writer writer, java.lang.String encoding)
          Process the request and fill in the template using the values set in context.
 java.lang.String handleRequest(org.apache.fulcrum.template.TemplateContext context, java.lang.String template)
           
 void handleRequest(org.apache.fulcrum.template.TemplateContext context, java.lang.String template, java.io.OutputStream outputStream)
           
 void handleRequest(org.apache.fulcrum.template.TemplateContext context, java.lang.String template, java.io.Writer writer)
           
 void init()
          Performs early initialization of this Turbine service.
 boolean templateExists(java.lang.String template)
          Find out if a given template exists.
 
Methods inherited from class org.apache.fulcrum.template.BaseTemplateEngineService
getAssociatedFileExtensions, getTemplateEngineServiceConfiguration, initConfiguration, registerConfiguration
 
Methods inherited from class org.apache.fulcrum.BaseService
getCategory, getConfiguration, getInit, getName, getRealPath, getServiceBroker, getServiceObject, getStatus, isInitialized, setInit, setName, setServiceBroker, shutdown
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.apache.fulcrum.Service
getCategory, getConfiguration, getRealPath, getStatus, isInitialized, setName, setServiceBroker, shutdown
 

Constructor Detail

VelocityEmailService

public VelocityEmailService()
Method Detail

init

public void init()
          throws org.apache.fulcrum.InitializationException
Performs early initialization of this Turbine service.

Specified by:
init in interface org.apache.fulcrum.Service
Throws:
org.apache.fulcrum.InitializationException

handleRequest

public java.lang.String handleRequest(org.apache.fulcrum.template.TemplateContext context,
                                      java.lang.String template)
                               throws org.apache.fulcrum.ServiceException
Specified by:
handleRequest in interface org.apache.fulcrum.template.TemplateEngineService
Throws:
org.apache.fulcrum.ServiceException
See Also:
VelocityService

handleRequest

public java.lang.String handleRequest(org.apache.velocity.context.Context context,
                                      java.lang.String filename)
                               throws org.apache.fulcrum.ServiceException
Description copied from interface: EmailService
Process the request and fill in the template using the values set in context.

Specified by:
handleRequest in interface EmailService
Parameters:
context - A context to use when evaluating the specified template.
filename - The file name of the template.
Returns:
The processed template.
Throws:
org.apache.fulcrum.ServiceException
See Also:
VelocityService

handleRequest

public java.lang.String handleRequest(org.apache.velocity.context.Context context,
                                      java.lang.String filename,
                                      java.lang.String charset,
                                      java.lang.String encoding)
                               throws org.apache.fulcrum.ServiceException
Description copied from interface: EmailService
Process the request and fill in the template using the values set in context.

Specified by:
handleRequest in interface EmailService
Parameters:
context - A context to use when evaluating the specified template.
charset - The character set to use when writing the result.
encoding - The encoding to use when merging context and template.
Returns:
The processed template.
Throws:
org.apache.fulcrum.ServiceException
See Also:
VelocityService

handleRequest

public void handleRequest(org.apache.fulcrum.template.TemplateContext context,
                          java.lang.String template,
                          java.io.OutputStream outputStream)
                   throws org.apache.fulcrum.ServiceException
Specified by:
handleRequest in interface org.apache.fulcrum.template.TemplateEngineService
Throws:
org.apache.fulcrum.ServiceException
See Also:
TemplateEngineService

handleRequest

public void handleRequest(org.apache.velocity.context.Context context,
                          java.lang.String filename,
                          java.io.OutputStream output)
                   throws org.apache.fulcrum.ServiceException
Description copied from interface: EmailService
Process the request and fill in the template using the values set in context.

Specified by:
handleRequest in interface EmailService
Parameters:
context - A context to use when evaluating the specified template.
filename - The file name of the template.
output - The stream to which we will write the processed template as a String.
Throws:
org.apache.fulcrum.ServiceException - Any exception trown while processing will be wrapped into a ServiceException and rethrown.
See Also:
VelocityService

handleRequest

public void handleRequest(org.apache.velocity.context.Context context,
                          java.lang.String filename,
                          java.io.OutputStream output,
                          java.lang.String charset,
                          java.lang.String encoding)
                   throws org.apache.fulcrum.ServiceException
Description copied from interface: EmailService
Process the request and fill in the template using the values set in context.

Specified by:
handleRequest in interface EmailService
Parameters:
context - A context to use when evaluating the specified template.
filename - The file name of the template.
output - The stream to which we will write the processed template as a String.
charset - The character set to use when writing the result.
encoding - The encoding to use when merging context and template.
Throws:
org.apache.fulcrum.ServiceException - Any exception trown while processing will be wrapped into a ServiceException and rethrown.
See Also:
VelocityService

handleRequest

public void handleRequest(org.apache.fulcrum.template.TemplateContext context,
                          java.lang.String template,
                          java.io.Writer writer)
                   throws org.apache.fulcrum.ServiceException
Specified by:
handleRequest in interface org.apache.fulcrum.template.TemplateEngineService
Throws:
org.apache.fulcrum.ServiceException
See Also:
BaseTemplateEngineService.handleRequest(TemplateContext, String, Writer)

handleRequest

public void handleRequest(org.apache.velocity.context.Context context,
                          java.lang.String filename,
                          java.io.Writer writer)
                   throws org.apache.fulcrum.ServiceException
Description copied from interface: EmailService
Process the request and fill in the template using the values set in context.

Specified by:
handleRequest in interface EmailService
Parameters:
context - A context to use when evaluating the specified template.
filename - The file name of the template.
writer - The writer to which we will write the processed template.
Throws:
org.apache.fulcrum.ServiceException - Any exception trown while processing will be wrapped into a ServiceException and rethrown.
See Also:
handleRequest(Context, String, Writer)

handleRequest

public void handleRequest(org.apache.velocity.context.Context context,
                          java.lang.String filename,
                          java.io.Writer writer,
                          java.lang.String encoding)
                   throws org.apache.fulcrum.ServiceException
Description copied from interface: EmailService
Process the request and fill in the template using the values set in context.

Specified by:
handleRequest in interface EmailService
Parameters:
context - A context to use when evaluating the specified template.
filename - The file name of the template.
writer - The writer to which we will write the processed template.
encoding - The encoding to use when merging context and template.
Throws:
org.apache.fulcrum.ServiceException - Any exception trown while processing will be wrapped into a ServiceException and rethrown.
See Also:
handleRequest(Context, String, Writer, String)

templateExists

public boolean templateExists(java.lang.String template)
Find out if a given template exists. Velocity will do its own searching to determine whether a template exists or not.

Specified by:
templateExists in interface org.apache.fulcrum.template.TemplateEngineService
Returns:
boolean


Copyright © 2000-2004 Tigris.org. All Rights Reserved.