It's not that complicated to create and use a VelocityEngine. Look in the manual under
http://jakarta.apache.org/velocity/developer-guide.html#Using%20Velocity%20In%20General%20Applications


See the below example (abridged) for something basic.

public void init(ServletContext ctx)
{
VelocityEngine ve = new VelocityEngine();

ve.setProperty("file.resource.loader.path",ctx.getRealPath("WEB-INF/email_templates")); ve.setProperty(RuntimeConstants.RUNTIME_LOG_LOGSYSTEM_CLASS,"org.apache.velocity.runtime.log.SimpleLog4JLogSystem"); 
ve.setProperty("runtime.log.logsystem.log4j.category","org.apache.velocity.tenant"); ve.init(); ctx.setAttribute(V_ATTRIBUTE,ve);}/** * Send an email to the specified address using the appropriate Velocitytemplate. * @param toAddress * @param BaseFileName indicates the velocity templates to use. 
*      The HTML template is the BaseFileName with ".html" appended and thetext template is the BaseFileName with ".txt" appended. */public void sendTemplateEmail (ServletContext ctx, Map ViewParams,UsertoContact, User ccContact, String subject, String BaseFileName) throwsAppException { 
VelocityEngine ve = (VelocityEngine) ctx.getAttribute(V_ATTRIBUTE); Context c = new VelocityContext(ViewParams); String htmlFile = BaseFileName + ".htm"; String txtFile = BaseFileName + ".txt"; String htmlMsg = null; String txtMsg = null; try {  if (ve.templateExists(htmlFile)) {   Template t1 = 
ve.getTemplate(htmlFile);   StringWriter writer = new StringWriter();   t1.merge(c,writer);   htmlMsg = writer.toString();  } } catch (ParseErrorException E ) {  throw new AppException("Error in template file.",E); } catch (MethodInvocationException E ) {  throw new AppException("Error in template 
file.",E); } catch (ResourceNotFoundException E ) {  throw new AppException("Error in template file.",E); } catch (Exception E ) {  throw new AppException("Error in template file.",E); } try {  if (ve.templateExists(txtFile)) {   Template t1 = ve.getTemplate(txtFile);   StringWriter writer 
= new StringWriter();   t1.merge(c,writer);   txtMsg = writer.toString();  } } catch (ParseErrorException E ) {  throw new AppException("Error in template file.",E); } catch (MethodInvocationException E ) {  throw new AppException("Error in template file.",E); } catch (ResourceNotFoundException 
E ) {  throw new AppException("Error in template file.",E); } catch (Exception E ) {  throw new AppException("Error in template file.",E); } sendEmail(toContact,ccContact,subject,htmlMsg,txtMsg);}----- Original Message -----From: <[EMAIL PROTECTED]>To: "Velocity Users List" 
<velocity-user@jakarta.apache.org>Sent: Friday, April 15, 2005 5:01 PMSubject: Re: Problem with decimal in most recent snapshot>> Exactly.>> But the real hard part is that though it is good the seperation, mostusers will still likely be web app people like me.>> I am not seeing a good 
solution for getting a web app to do String (email)templating easily.>> JohnE>>>> ---------------------------------------------------------------------> To unsubscribe, e-mail: [EMAIL PROTECTED]> For additional commands, e-mail: [EMAIL PROTECTED]>

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to