1 package org.campware.cream.modules.scheduledjobs; 2 3 import java.io.StringWriter ; 4 import org.apache.commons.logging.*; 5 import org.apache.velocity.context.Context; 6 import org.apache.velocity.exception.*; 7 import org.apache.velocity.app.Velocity; 8 9 16 17 public class ShedVelocityTool 18 { 19 static Log log = LogFactory.getLog( ShedVelocityTool.class ); 20 21 24 protected Context context; 25 26 29 public ShedVelocityTool() 30 { 31 } 32 33 37 public ShedVelocityTool( Context c ) 38 { 39 context = c; 40 } 41 42 46 public void setContext( Context context ) 47 { 48 this.context = context; 49 } 50 51 55 public Context getContext() 56 { 57 return context; 58 } 59 60 68 public String evaluate( String s ) 69 { 70 if ( s != null ) 71 { 72 log.debug( "evaluate: " + s ); 73 StringWriter stringWriter = new StringWriter ( s.length() ); 74 try 75 { 76 Velocity.evaluate( context, stringWriter, "ShedVelocityTool.evaluate", s ); 77 stringWriter.close(); 78 return stringWriter.toString(); 79 } 80 catch( ResourceNotFoundException rnfe ) 81 { 82 log.error( "ResourceNotFoundException: " + rnfe, rnfe ); 83 } 84 catch( ParseErrorException pee ) 85 { 86 log.error( "ParseErrorException: " + pee, pee ); 87 } 88 catch( Exception e ) 89 { 90 log.error( "Exception: " + e, e ); 91 } 92 } 93 94 return s; 95 } 96 97 protected void finalize() 98 throws Throwable 99 { 100 log.debug( "Finalizing Velocity Tool." ); 101 } 102 103 } | Popular Tags |