1 7 package org.contineo.actions.communication; 8 9 import java.text.DateFormat ; 10 import java.util.ArrayList ; 11 import java.util.Collection ; 12 import java.util.Date ; 13 import javax.servlet.http.HttpServletRequest ; 14 import javax.servlet.http.HttpServletResponse ; 15 import javax.servlet.http.HttpSession ; 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.communication.dao.EMailAccountDAO; 23 import org.contineo.core.CryptBean; 24 import org.contineo.core.LoggingManager; 25 import org.contineo.core.SessionManagement; 26 import org.contineo.documan.DownloadTicket; 27 import org.contineo.documan.dao.DownloadTicketDAO; 28 import org.contineo.forms.EMailForm; 29 30 31 32 38 public class SendDownloadTicketAction extends Action { 39 40 44 private Logger logger; 45 46 49 public SendDownloadTicketAction() { 50 logger = LoggingManager.getLogger(this.getClass()); 51 } 52 53 public ActionForward execute(ActionMapping mapping, 54 ActionForm form, HttpServletRequest request, 55 HttpServletResponse response) { 56 ActionForward actionForward = new ActionForward(); 57 HttpSession session = request.getSession(); 58 if (SessionManagement.isValid(session)) { 59 try { 60 String username = (String )session.getAttribute("authuser"); 61 String menuid = request.getParameter("menuid"); 62 Collection attachments = new ArrayList (); 63 Date date = new Date (); 64 String temp = DateFormat.getDateInstance().format(date) + username; 65 String ticketid = CryptBean.cryptString(temp); 66 DownloadTicket ticket = new DownloadTicket(); 67 ticket.setTicketId(ticketid); 68 ticket.setMenuid(Integer.parseInt(menuid)); 69 ticket.setUsername(username); 70 DownloadTicketDAO ticketDao = new DownloadTicketDAO(); 71 ticketDao.store(ticket); 72 request.getRequestURL(); 73 String address = "http://"; 74 address += request.getServerName() + ":"; 75 address += request.getServerPort(); 76 address += request.getContextPath(); 77 address += "/DownloadDocument.do?id=" + ticketid; 78 EMailForm email = new EMailForm(); 79 email.setText("URL: " + address); 80 request.setAttribute("emailform", email); 81 request.setAttribute("attachments", attachments); 82 EMailAccountDAO accountDao = new EMailAccountDAO(); 83 Collection accounts = accountDao.findByUserName(username); 84 if (accounts.size() == 0) 85 actionForward.setPath("/AddAccount.do"); 86 else 87 actionForward = mapping.findForward("addemail"); 88 request.setAttribute("accounts", accounts); 89 } catch (Exception e) { 90 if (logger.isEnabledFor(Level.ERROR)) 91 logger.error(e.getMessage()); 92 actionForward = mapping.findForward("error"); 93 } 94 } else 95 actionForward = mapping.findForward("invalid"); 96 return actionForward; 97 } 98 } 99
| Popular Tags
|