
// UseMathTool.java
// Rob Harrop, From "Pro Jakarta Velocity", Ch 3, Feb. 2004
// Modified by Andrew Davison, ad@coe.psu.ac.th, July 2023

import java.io.*;

import org.apache.velocity.*;
import org.apache.velocity.app.*;
import org.apache.velocity.tools.generic.*;

/* Using the MathTool
   https://velocity.apache.org/tools/3.1/tools-summary.html

   Usage:
    > compile UseMathTool.java
    > run UseMathTool
*/


public class UseMathTool 
{
  private static final String TEMPLATE_FNM = "mathTool.vm";


  public static void main(String[] args) throws Exception 
  {
    Velocity.init();
    System.out.println("Loading template: " + TEMPLATE_FNM);
    Template template = Velocity.getTemplate(TEMPLATE_FNM);
     
    VelocityContext vc = new VelocityContext();
    vc.put("math", new MathTool());  // load into Velocity
    vc.put("num", Double.valueOf(5.5));
    
    StringWriter sw = new StringWriter();
    template.merge(vc, sw);
    System.out.println(sw);
  }  // end of main()

} // end of UseMathTool class
