1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.itracker.web.actions.admin.report;
20
21 import org.apache.log4j.Logger;
22 import org.apache.struts.action.*;
23 import org.itracker.model.Report;
24 import org.itracker.services.ReportService;
25 import org.itracker.web.actions.base.ItrackerBaseAction;
26 import org.itracker.web.util.ServletContextUtils;
27
28 import javax.servlet.ServletException;
29 import javax.servlet.ServletOutputStream;
30 import javax.servlet.http.HttpServletRequest;
31 import javax.servlet.http.HttpServletResponse;
32 import java.io.IOException;
33
34
35 @Deprecated
36 public class ExportReportAction extends ItrackerBaseAction {
37 private static final Logger log = Logger.getLogger(ExportReportAction.class);
38
39 public ExportReportAction() {
40 }
41
42 public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
43 ActionMessages errors = new ActionMessages();
44
45 String pageTitleKey = "";
46 String pageTitleArg = "";
47
48 try {
49 Integer reportId = new Integer((request.getParameter("id") == null ? "-1" : request.getParameter("id")));
50 if (reportId == null || reportId.intValue() < 0) {
51 errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("itracker.web.error.invalidreport"));
52 } else {
53 ReportService reportService = ServletContextUtils.getItrackerServices().getReportService();
54
55 Report report = reportService.getReportDAO().findByPrimaryKey(reportId);
56 if (report != null) {
57 response.setContentType("application/x-itracker-report-export");
58 response.setHeader("Content-Disposition", "attachment; filename=\"ITracker_report_" + report.getId() + ".itr\"");
59 ServletOutputStream out = response.getOutputStream();
60 log.debug("Attempting export for: " + report);
61 out.println("# Exported ITracker report " + report.getName());
62 out.println("id=" + report.getId());
63 out.println("name=" + report.getName());
64 out.println("namekey=" + report.getNameKey());
65 if (report.getClassName() != null && !report.getClassName().equals("")) {
66 out.println("className=" + report.getClassName());
67 }
68 out.println("description=" + report.getDescription());
69 out.flush();
70 out.close();
71 return null;
72 }
73 log.debug("Unknown report " + reportId + " specified for export");
74 errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("itracker.web.error.invalidreport"));
75 }
76 } catch (RuntimeException e) {
77 pageTitleKey = "itracker.web.error.title";
78 request.setAttribute("pageTitleKey", pageTitleKey);
79 request.setAttribute("pageTitleArg", pageTitleArg);
80 log.error("Exception while exporting a report.", e);
81 errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("itracker.web.error.system"));
82 }
83 if (!errors.isEmpty()) {
84 saveErrors(request, errors);
85 }
86
87 return mapping.findForward("error");
88 }
89
90 }
91