KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > efs > openreports > actions > ChartReportAction


1 /*
2  * Copyright (C) 2006 Erik Swenson - erik@oreports.com
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.actions;
21
22 import java.util.Date JavaDoc;
23 import java.util.HashMap JavaDoc;
24 import java.util.Map JavaDoc;
25
26 import org.apache.log4j.Logger;
27 import org.efs.openreports.ORStatics;
28 import org.efs.openreports.engine.ChartReportEngine;
29 import org.efs.openreports.engine.input.ReportEngineInput;
30 import org.efs.openreports.engine.output.ChartEngineOutput;
31 import org.efs.openreports.objects.Report;
32 import org.efs.openreports.objects.ReportLog;
33 import org.efs.openreports.objects.ReportUser;
34 import org.efs.openreports.objects.chart.ChartValue;
35 import org.efs.openreports.util.LocalStrings;
36 import org.jfree.chart.imagemap.ImageMapUtilities;
37
38 import com.opensymphony.xwork.ActionContext;
39
40 public class ChartReportAction extends QueryReportAction
41 {
42     protected static Logger log = Logger.getLogger(ChartReportAction.class);
43     
44     private String JavaDoc imageMap;
45     private ChartValue[] chartValues;
46
47     public String JavaDoc execute()
48     {
49         ReportUser user = (ReportUser) ActionContext.getContext().getSession().get(
50                 ORStatics.REPORT_USER);
51
52         report = (Report) ActionContext.getContext().getSession().get(ORStatics.REPORT);
53
54         Map JavaDoc reportParameters = getReportParameterMap(user);
55
56         ReportLog reportLog = new ReportLog(user, report, new Date JavaDoc());
57
58         try
59         {
60             log.debug("Starting Chart Report: " + report.getName());
61
62             reportLogProvider.insertReportLog(reportLog);
63             
64             ChartReportEngine chartReportEngine = new ChartReportEngine(
65                     dataSourceProvider, directoryProvider, propertiesProvider);
66
67             ReportEngineInput input = new ReportEngineInput(report, reportParameters);
68
69             ChartEngineOutput chartOutput = (ChartEngineOutput) chartReportEngine
70                     .generateReport(input);
71             
72             chartValues = chartOutput.getChartValues();
73             if (chartValues.length == 0)
74             {
75                 addActionError(LocalStrings.getString(LocalStrings.ERROR_REPORT_EMPTY));
76             }
77             
78             imageMap = ImageMapUtilities.getImageMap("chart", chartOutput.getChartRenderingInfo());
79             
80             HashMap JavaDoc imagesMap = new HashMap JavaDoc();
81             imagesMap.put("ChartImage", chartOutput.getContent());
82             
83             ActionContext.getContext().getSession().put(ORStatics.IMAGES_MAP, imagesMap);
84                         
85             reportLog.setEndTime(new Date JavaDoc());
86             reportLog.setStatus(ReportLog.STATUS_SUCCESS);
87             reportLogProvider.updateReportLog(reportLog);
88
89             log.debug("Finished Chart Report: " + report.getName());
90         }
91         catch (Exception JavaDoc e)
92         {
93             addActionError(e.getMessage());
94
95             log.error(e.toString());
96
97             reportLog.setMessage(e.getMessage());
98             reportLog.setStatus(ReportLog.STATUS_FAILURE);
99
100             reportLog.setEndTime(new Date JavaDoc());
101
102             try
103             {
104                 reportLogProvider.updateReportLog(reportLog);
105             }
106             catch (Exception JavaDoc ex)
107             {
108                 log.error("Unable to create ReportLog: " + ex.getMessage());
109             }
110
111             return ERROR;
112         }
113
114         return SUCCESS;
115     }
116
117     public String JavaDoc getImageMap()
118     {
119         return imageMap;
120     }
121
122     public void setImageMap(String JavaDoc imageMap)
123     {
124         this.imageMap = imageMap;
125     }
126
127     public ChartValue[] getChartValues()
128     {
129         return chartValues;
130     }
131 }
Popular Tags