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