KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * ChangePasswordAction.java
3  *
4  * Created on 16. Dezember 2003, 22:25
5  */

6
7 package org.contineo.actions.communication;
8
9 import javax.servlet.http.HttpServletRequest JavaDoc;
10 import javax.servlet.http.HttpServletResponse JavaDoc;
11 import javax.servlet.http.HttpSession JavaDoc;
12 import org.apache.log4j.Level;
13 import org.apache.log4j.Logger;
14 import org.apache.struts.action.Action;
15 import org.apache.struts.action.ActionForm;
16 import org.apache.struts.action.ActionForward;
17 import org.apache.struts.action.ActionMapping;
18 import org.contineo.communication.EMailAccount;
19 import org.contineo.communication.dao.EMailAccountDAO;
20 import org.contineo.core.LoggingManager;
21 import org.contineo.core.SessionManagement;
22
23 /**
24  *
25  * @author Michael Scholz
26  * @version 1.0
27  */

28 public class SelectAccountAction extends Action {
29
30     /**
31      * @uml.property name="logger"
32      * @uml.associationEnd
33      */

34     private Logger logger;
35
36     
37     /** Creates a new instance of ChangePasswordAction */
38     public SelectAccountAction() {
39         logger = LoggingManager.getLogger(this.getClass());
40     }
41     
42     public ActionForward execute(ActionMapping mapping,
43     ActionForm form, HttpServletRequest JavaDoc request,
44     HttpServletResponse JavaDoc response) {
45         ActionForward actionForward = new ActionForward();
46         HttpSession JavaDoc session = request.getSession();
47         if (SessionManagement.isValid(session)) {
48             try {
49                 String JavaDoc username = (String JavaDoc)session.getAttribute("authuser");
50                 String JavaDoc accountid = request.getParameter("accountid");
51                 int accountId = Integer.parseInt(accountid);
52                 EMailAccountDAO accountDao = new EMailAccountDAO();
53                 EMailAccount account = accountDao.findByPrimaryKey(accountId);
54                 if (username.equals(account.getUserName())) {
55                     request.setAttribute("account", account);
56                     actionForward = mapping.findForward("showaccount");
57                 } else
58                     actionForward = mapping.findForward("noaccess");
59             } catch (Exception JavaDoc e) {
60                 if (logger.isEnabledFor(Level.ERROR))
61                     logger.error(e.getMessage());
62                 actionForward = mapping.findForward("error");
63             }
64         } else
65             actionForward = mapping.findForward("invalid");
66         return actionForward;
67     }
68 }
69
Popular Tags