KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > contineo > actions > communication > SendDownloadTicketAction


1 /*
2  * Created on 29.08.2004
3  *
4  * To change the template for this generated file go to
5  * Window>Preferences>Java>Code Generation>Code and Comments
6  */

7 package org.contineo.actions.communication;
8
9 import java.text.DateFormat JavaDoc;
10 import java.util.ArrayList JavaDoc;
11 import java.util.Collection JavaDoc;
12 import java.util.Date JavaDoc;
13 import javax.servlet.http.HttpServletRequest JavaDoc;
14 import javax.servlet.http.HttpServletResponse JavaDoc;
15 import javax.servlet.http.HttpSession JavaDoc;
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 /**
33  * @author Michael Scholz
34  *
35  * To change the template for this generated type comment go to
36  * Window>Preferences>Java>Code Generation>Code and Comments
37  */

38 public class SendDownloadTicketAction extends Action {
39
40     /**
41      * @uml.property name="logger"
42      * @uml.associationEnd
43      */

44     private Logger logger;
45
46     /**
47      *
48      */

49     public SendDownloadTicketAction() {
50         logger = LoggingManager.getLogger(this.getClass());
51     }
52
53     public ActionForward execute(ActionMapping mapping,
54                     ActionForm form, HttpServletRequest JavaDoc request,
55                     HttpServletResponse JavaDoc response) {
56         ActionForward actionForward = new ActionForward();
57         HttpSession JavaDoc session = request.getSession();
58         if (SessionManagement.isValid(session)) {
59             try {
60                 String JavaDoc username = (String JavaDoc)session.getAttribute("authuser");
61                 String JavaDoc menuid = request.getParameter("menuid");
62                 Collection JavaDoc attachments = new ArrayList JavaDoc();
63                 Date JavaDoc date = new Date JavaDoc();
64                 String JavaDoc temp = DateFormat.getDateInstance().format(date) + username;
65                 String JavaDoc 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 JavaDoc 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 JavaDoc 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 JavaDoc 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