1 6 7 package org.contineo.actions.documan.transfer; 8 9 import java.io.ByteArrayOutputStream ; 10 import java.io.PrintWriter ; 11 12 import javax.servlet.http.HttpServletRequest ; 13 import javax.servlet.http.HttpServletResponse ; 14 import javax.servlet.http.HttpSession ; 15 import org.apache.log4j.Level; 16 import org.apache.log4j.Logger; 17 import org.apache.struts.action.Action; 18 import org.apache.struts.action.ActionForm; 19 import org.apache.struts.action.ActionForward; 20 import org.apache.struts.action.ActionMapping; 21 import org.contineo.core.LoggingManager; 22 import org.contineo.core.SessionManagement; 23 import org.contineo.core.transfer.FreemindExport; 24 29 public class FreemindExportAction extends Action { 30 31 35 private Logger logger; 36 37 38 public FreemindExportAction() { 39 logger = LoggingManager.getLogger(this.getClass()); 40 } 41 42 public ActionForward execute(ActionMapping mapping, 43 ActionForm form, HttpServletRequest request, 44 HttpServletResponse response) { 45 ActionForward actionForward = new ActionForward(); 46 HttpSession session = request.getSession(); 47 if (SessionManagement.isValid(session)) { 48 session.setAttribute("helppage", "showfoldercontent"); 49 try { 50 String username = (String )session.getAttribute("authuser"); 51 String menuid = request.getParameter("menuid"); 52 FreemindExport exporter = new FreemindExport(); 53 ByteArrayOutputStream bos = exporter.process(Integer.parseInt(menuid), username); 54 response.setContentType("application/octet-stream"); 55 response.setContentLength(bos.size()); 56 response.setHeader("Content-disposition", "attachment;filename=FreeMindExport.mm"); 57 PrintWriter pw = response.getWriter(); 58 pw.write(bos.toString()); 59 pw.flush(); 60 pw.close(); 61 62 actionForward = null; 64 } catch (Exception e) { 65 if (logger.isEnabledFor(Level.ERROR)) 66 logger.error(e.getMessage()); 67 actionForward = mapping.findForward("error"); 68 } 69 } else 70 actionForward = mapping.findForward("invalid"); 71 return actionForward; 72 } 73 } 74 | Popular Tags |