1 18 19 package cowsultants.itracker.web.actions; 20 21 import java.io.*; 22 import java.rmi.*; 23 import java.util.*; 24 import java.util.zip.*; 25 import javax.ejb.*; 26 import javax.rmi.*; 27 import javax.naming.*; 28 import javax.servlet.*; 29 import javax.servlet.http.*; 30 31 import org.apache.commons.beanutils.*; 32 import org.apache.struts.action.*; 33 import org.apache.struts.upload.*; 34 import org.apache.struts.util.*; 35 import org.apache.struts.validator.*; 36 37 import cowsultants.itracker.ejb.client.exceptions.*; 38 import cowsultants.itracker.ejb.client.interfaces.*; 39 import cowsultants.itracker.ejb.client.models.*; 40 import cowsultants.itracker.ejb.client.resources.*; 41 import cowsultants.itracker.ejb.client.util.*; 42 import cowsultants.itracker.web.util.*; 43 44 45 public class ExportReportAction extends ITrackerAction { 46 47 public ExportReportAction () { 48 } 49 50 public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { 51 ActionErrors errors = new ActionErrors(); 52 53 if(! isLoggedIn(request, response)) { 54 return mapping.findForward("login"); 55 } 56 57 if(! hasPermission(UserUtilities.PERMISSION_USER_ADMIN, request, response)) { 58 return mapping.findForward("unauthorized"); 59 } 60 61 try { 62 Integer reportId = (Integer ) PropertyUtils.getSimpleProperty(form, "id"); 63 if(reportId == null || reportId.intValue() < 0) { 64 errors.add(ActionErrors.GLOBAL_ERROR, new ActionError("itracker.web.error.invalidreport")); 65 } else { 66 InitialContext ic = new InitialContext(); 67 68 Object rhRef = ic.lookup("java:comp/env/" + ReportHandler.JNDI_NAME); 69 ReportHandlerHome rhHome = (ReportHandlerHome) PortableRemoteObject.narrow(rhRef, ReportHandlerHome.class); 70 ReportHandler rh = rhHome.create(); 71 72 ReportModel report = rh.getReport(reportId); 73 if(report != null) { 74 report.setFileData(rh.getReportFile(reportId)); 75 response.setContentType("application/x-itracker-report-export"); 76 response.setHeader("Content-Disposition", "attachment; filename=\"ITracker_report_" + report.getId() + ".itr\""); 77 ServletOutputStream out = response.getOutputStream(); 78 Logger.logDebug("Attempting export for: " + report); 79 out.println("# Exported ITracker report " + report.getName()); 80 out.println("id=" + report.getId()); 81 out.println("name=" + report.getName()); 82 out.println("namekey=" + report.getNameKey()); 83 out.println("dataType=" + report.getDataType()); 84 out.println("reportType=" + report.getReportType()); 85 if(report.getClassName() != null && ! report.getClassName().equals("")) { 86 out.println("className=" + report.getClassName()); 87 } 88 out.println("description=" + Base64.encodeObject(report.getDescription(), Base64.DONT_BREAK_LINES)); 89 out.println("definition=" + Base64.encodeBytes(report.getFileData(), Base64.DONT_BREAK_LINES)); 90 out.flush(); 91 out.close(); 92 return null; 93 } 94 Logger.logDebug("Unknown report " + reportId + " specified for export"); 95 errors.add(ActionErrors.GLOBAL_ERROR, new ActionError("itracker.web.error.invalidreport")); 96 } 97 } catch(Exception e) { 98 Logger.logError("Exception while exporting a report.", e); 99 errors.add(ActionErrors.GLOBAL_ERROR, new ActionError("itracker.web.error.system")); 100 } 101 if(! errors.isEmpty()) { 102 saveErrors(request, errors); 103 } 104 105 return mapping.findForward("error"); 106 } 107 108 } 109 | Popular Tags |