View Javadoc
1   /*
2    * This software was designed and created by Jason Carroll.
3    * Copyright (c) 2002, 2003, 2004 Jason Carroll.
4    * The author can be reached at jcarroll@cowsultants.com
5    * ITracker website: http://www.cowsultants.com
6    * ITracker forums: http://www.cowsultants.com/phpBB/index.php
7    *
8    * This program is free software; you can redistribute it and/or modify
9    * it only under the terms of the GNU General Public License as published by
10   * the Free Software Foundation; either version 2 of the License, or
11   * (at your option) any later version.
12   *
13   * This program is distributed in the hope that it will be useful,
14   * but WITHOUT ANY WARRANTY; without even the implied warranty of
15   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16   * GNU General Public License for more details.
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