org.kuali.student.common.util
Class VelocityTemplateEngine

java.lang.Object
  extended by org.kuali.student.common.util.VelocityTemplateEngine

public class VelocityTemplateEngine
extends Object

Velocity template engine.

Velocity tools supported (See http://velocity.apache.org/tools/devel/generic.html}:

Examples:
 $dateTool:            $dateTool.get('yyyy-M-d H:m:s')                                 -> 2003-10-19 21:54:50
 
 $dateComparisonTool:  $dateComparisonTool.difference('2005-07-04','2007-02-15').abbr  -> 1 yr
 
 $mathTool:            $mathTool.toNumber($value)                                      -> Converts java.lang.String $value to a java.lang.Number
 
 $numberTool:          $numberTool.currency($myNumber)                                 -> $13.55
 
 $sortTool:            $sorter.sort($collection, "name:asc")                           -> Sorts $collection with property 'name' in ascending order
 


Field Summary
private  Map<String,Object> configMap
           
private  org.apache.velocity.VelocityContext defaultContext
           
private  org.apache.velocity.app.VelocityEngine velocityEngine
           
 
Constructor Summary
VelocityTemplateEngine()
          Constructs a velocity template engine.
VelocityTemplateEngine(Map<String,Object> config)
          Constructs a velocity template engine with velocity tools configurations.
 
Method Summary
 String evaluate(Map<String,Object> mapContext, Reader template)
          Evaluates a template with a map of objects.
 String evaluate(Map<String,Object> contextMap, String template)
          Evaluates a template with a map of objects.
private  void init()
          Initializes Velocity engine
 void setLogFile()
          Sets the Velocity Log File to the default location.
 void setLogFile(String logfile)
          Sets the Velocity Log File.
 void setLogging(boolean enableLogging)
          Sets logging on or off.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

velocityEngine

private final org.apache.velocity.app.VelocityEngine velocityEngine

defaultContext

private org.apache.velocity.VelocityContext defaultContext

configMap

private Map<String,Object> configMap
Constructor Detail

VelocityTemplateEngine

public VelocityTemplateEngine()
Constructs a velocity template engine.


VelocityTemplateEngine

public VelocityTemplateEngine(Map<String,Object> config)
Constructs a velocity template engine with velocity tools configurations.

Parameters:
config - Velocity tools configurations
Method Detail

init

private void init()
Initializes Velocity engine


setLogging

public void setLogging(boolean enableLogging)
Sets logging on or off.

Parameters:
enableLogging - True enables logging; false disables logging

setLogFile

public void setLogFile()
Sets the Velocity Log File to the default location. Either {catalina.base}/velocity.log or target/velocity.log.


setLogFile

public void setLogFile(String logfile)
Sets the Velocity Log File.

Parameters:
logFile - the path and filename for velocity logging

evaluate

public String evaluate(Map<String,Object> contextMap,
                       String template)
                throws org.apache.velocity.exception.VelocityException
Evaluates a template with a map of objects. contextMap can be null if no keys/tokens are referenced in the template

Parameters:
contextMap - Map of objects to be used in the template
template - Velocity Template
Returns:
Evaluated template
Throws:
org.apache.velocity.exception.VelocityException

evaluate

public String evaluate(Map<String,Object> mapContext,
                       Reader template)
                throws org.apache.velocity.exception.VelocityException
Evaluates a template with a map of objects.

Parameters:
mapContext - Map of Objects to be used in the template
template - Velocity Template
Returns:
Evaluated template
Throws:
org.apache.velocity.exception.VelocityException


Copyright © 2004-2012 The Kuali Foundation. All Rights Reserved.