1 19 20 package org.efs.openreports.dispatcher; 21 22 import org.apache.log4j.Logger; 23 import org.apache.velocity.Template; 24 import org.apache.velocity.app.VelocityEngine; 25 import org.efs.openreports.actions.QueryReportResultAction; 26 import org.efs.openreports.objects.Report; 27 28 import com.opensymphony.webwork.config.Configuration; 29 import com.opensymphony.webwork.dispatcher.VelocityResult; 30 import com.opensymphony.xwork.Action; 31 import com.opensymphony.xwork.ActionInvocation; 32 import com.opensymphony.xwork.util.OgnlValueStack; 33 34 public class QueryReportResult extends VelocityResult 35 { 36 protected static Logger log = Logger.getLogger(QueryReportResult.class); 37 38 private VelocityEngine velocityEngine; 39 40 public QueryReportResult() 41 { 42 velocityEngine = new VelocityEngine(); 43 velocityEngine.setProperty(VelocityEngine.RESOURCE_LOADER, "file, wwclass"); 44 velocityEngine.setProperty(VelocityEngine.FILE_RESOURCE_LOADER_PATH, 45 Configuration.getString("webwork.multipart.saveDir").trim()); 46 velocityEngine.setProperty(VelocityEngine.FILE_RESOURCE_LOADER_CACHE, "true"); 47 velocityEngine.setProperty("file.resource.loader.modificationCheckInterval", "2"); 48 velocityEngine.setProperty("wwclass.resource.loader.modificationCheckInterval", "2"); 49 velocityEngine.setProperty("wwclass.resource.loader.description", 50 "Velocity Classpath Resource Loader"); 51 velocityEngine.setProperty("wwclass.resource.loader.class", 52 "com.opensymphony.webwork.views.velocity.WebWorkResourceLoader"); 53 velocityEngine.setProperty("wwclass.resource.loader.modificationCheckInterval", "2"); 54 velocityEngine.setProperty("wwclass.resource.loader.cache", "true"); 55 velocityEngine.setProperty(VelocityEngine.RUNTIME_LOG_LOGSYSTEM_CLASS, 56 "org.apache.velocity.runtime.log.NullLogSystem"); 57 58 String directives = "com.opensymphony.webwork.views.velocity.ParamDirective" + "," 59 + "com.opensymphony.webwork.views.velocity.TagDirective" + "," 60 + "com.opensymphony.webwork.views.velocity.BodyTagDirective"; 61 62 velocityEngine.setProperty("userdirective", directives); 63 64 try 65 { 66 velocityEngine.init(); 67 } 68 catch (Exception e) 69 { 70 log.error(e); 71 } 72 } 73 74 protected Template getTemplate(OgnlValueStack stack, VelocityEngine velocity, 75 ActionInvocation invocation, String location) throws Exception 76 { 77 Action action = invocation.getAction(); 78 if (action instanceof QueryReportResultAction) 79 { 80 QueryReportResultAction queryReportAction = (QueryReportResultAction) action; 81 82 Report report = queryReportAction.getReport(); 83 if (report.getFile() != null && report.getFile().endsWith(".vm")) 84 { 85 return velocityEngine.getTemplate(report.getFile()); 86 } 87 } 88 89 return super.getTemplate(stack, velocity, invocation, location); 90 } 91 } | Popular Tags |