| 1 6 7 package org.contineo.actions.documan.util; 8 9 import javax.servlet.http.HttpServletRequest ; 10 import javax.servlet.http.HttpServletResponse ; 11 import javax.servlet.http.HttpSession ; 12 13 import org.apache.log4j.Level; 14 import org.apache.log4j.Logger; 15 import org.apache.struts.action.Action; 16 import org.apache.struts.action.ActionForm; 17 import org.apache.struts.action.ActionForward; 18 import org.apache.struts.action.ActionMapping; 19 import org.contineo.admin.dao.MenuDAO; 20 import org.contineo.core.LoggingManager; 21 import org.contineo.core.SessionManagement; 22 23 28 public class DownloadAction extends Action { 29 30 34 private Logger logger; 35 36 37 38 public DownloadAction() { 39 logger = LoggingManager.getLogger(this.getClass()); 40 } 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 try { 50 String menuIdStr = request.getParameter("menuid"); 52 if (menuIdStr == null || menuIdStr.equalsIgnoreCase("")) 53 throw new Exception ("menuid not set in session"); 54 String username = (String )session.getAttribute("authuser"); 55 if (username == null || username.equalsIgnoreCase("")) 56 throw new Exception ("username not set in session"); 57 58 MenuDAO mdao = new MenuDAO(); 60 int menuIdInt = Integer.parseInt(menuIdStr); 61 if (mdao.isReadEnable(menuIdInt, username)) { 62 DownloadDocUtil.downloadDocument(response, menuIdStr, null); 63 64 DownloadDocUtil.addToRecentFiles(username, menuIdInt); 66 67 actionForward = null; 69 } else { 70 actionForward = mapping.findForward("noaccess"); 71 } 72 } catch (Exception e) { 73 if (logger.isEnabledFor(Level.ERROR)) 74 logger.error(e.getMessage()); 75 actionForward = mapping.findForward("error"); 76 } 77 } else 78 actionForward = mapping.findForward("invalid"); 79 80 return actionForward; 81 } 82 } | Popular Tags |