01: package com.technoetic.xplanner.actions;
02:
03: import com.technoetic.xplanner.export.ExportException;
04: import com.technoetic.xplanner.export.Exporter;
05: import net.sf.hibernate.Session;
06: import org.apache.struts.action.ActionForm;
07: import org.apache.struts.action.ActionForward;
08: import org.apache.struts.action.ActionMapping;
09:
10: import javax.servlet.http.HttpServletRequest;
11: import javax.servlet.http.HttpServletResponse;
12:
13: public class ExportAction extends AbstractAction {
14: private Exporter exporter;
15:
16: protected ActionForward doExecute(ActionMapping mapping,
17: ActionForm form, HttpServletRequest request,
18: HttpServletResponse response) throws Exception {
19: Session session = getSession(request);
20: try {
21: Class objectClass = getObjectType(mapping, request);
22: Object object = getRepository(objectClass).load(
23: Integer.parseInt(request.getParameter("oid")));
24: byte[] data = exporter.export(session, object);
25: exporter.initializeHeaders(response);
26: response.getOutputStream().write(data);
27: } catch (Exception ex) {
28: throw new ExportException(ex);
29: } finally {
30: session.connection().rollback();
31: }
32:
33: // Optional forward
34: return mapping.findForward("display");
35: }
36:
37: public void setExporter(Exporter exporter) {
38: this.exporter = exporter;
39: }
40: }
|