KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > efs > openreports > dispatcher > QueryReportResult


1 /*
2  * Copyright (C) 2005 Erik Swenson - eswenson@opensourcesoft.net
3  *
4  * This program is free software; you can redistribute it and/or modify it under
5  * the terms of the GNU General Public License as published by the Free Software
6  * Foundation; either version 2 of the License, or (at your option) any later
7  * version.
8  *
9  * This program is distributed in the hope that it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11  * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
12  * details.
13  *
14  * You should have received a copy of the GNU General Public License along with
15  * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
16  * Place - Suite 330, Boston, MA 02111-1307, USA.
17  *
18  */

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 JavaDoc 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 JavaDoc e)
69         {
70             log.error(e);
71         }
72     }
73
74     protected Template getTemplate(OgnlValueStack stack, VelocityEngine velocity,
75             ActionInvocation invocation, String JavaDoc location) throws Exception JavaDoc
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