KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * Created on 13.04.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 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.ActionError;
16 import org.apache.struts.action.ActionErrors;
17 import org.apache.struts.action.ActionForm;
18 import org.apache.struts.action.ActionForward;
19 import org.apache.struts.action.ActionMapping;
20 import org.apache.struts.action.ActionMessage;
21 import org.apache.struts.action.ActionMessages;
22 import org.contineo.communication.EMail;
23 import org.contineo.communication.dao.EMailDAO;
24 import org.contineo.core.FileBean;
25 import org.contineo.core.LoggingManager;
26 import org.contineo.core.SessionManagement;
27 import org.contineo.core.config.SettingConfigurator;
28
29 /**
30  * @author Michael Scholz
31  *
32  * To change the template for this generated type comment go to
33  * Window>Preferences>Java>Code Generation>Code and Comments
34  */

35 public class DeleteEMailAction extends Action {
36
37     /**
38      * @uml.property name="logger"
39      * @uml.associationEnd
40      */

41     private Logger logger;
42
43     
44     /**
45      *
46      */

47     public DeleteEMailAction() {
48         logger = LoggingManager.getLogger(this.getClass());
49     }
50
51     public ActionForward execute(ActionMapping mapping,
52                     ActionForm form, HttpServletRequest JavaDoc request,
53                     HttpServletResponse JavaDoc response) {
54         ActionForward actionForward = new ActionForward();
55                 ActionErrors errors = new ActionErrors();
56                 ActionMessages messages = new ActionMessages();
57         HttpSession JavaDoc session = request.getSession();
58         if (SessionManagement.isValid(session)) {
59                         String JavaDoc folder = "";
60             try {
61                 String JavaDoc messageid = request.getParameter("messageid");
62                 int messageId = Integer.parseInt(messageid);
63                 String JavaDoc username = (String JavaDoc)session.getAttribute("authuser");
64                 EMailDAO emailDao = new EMailDAO();
65                 EMail email = emailDao.findByPrimaryKey(messageId);
66                 if (email.getUserName().equals(username)) {
67                     SettingConfigurator conf = new SettingConfigurator();
68                     String JavaDoc dir = conf.getValue("userdir") + "/" + username + "/mails/" + String.valueOf(email.getMessageId());
69                     FileBean.deleteDir(dir);
70                                         folder = email.getFolder();
71                     boolean deleted = emailDao.delete(messageId);
72                                         if (deleted)
73                                             messages.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("msg.action.deleteemail"));
74                                         else
75                                             errors.add(ActionErrors.GLOBAL_ERROR, new ActionError("errors.action.deleteemail"));
76                     actionForward.setPath("/ShowEmails.do?folder=" + folder);
77                 } else {
78                     actionForward = mapping.findForward("noaccess");
79                 }
80             } catch (Exception JavaDoc e) {
81                             if (logger.isEnabledFor(Level.ERROR))
82                 logger.error(e.getMessage());
83                             errors.add(ActionErrors.GLOBAL_ERROR, new ActionError("errors.action.deleteemail"));
84                             actionForward = mapping.findForward("error");
85             }
86                         saveErrors(request, errors);
87                         saveMessages(request, messages);
88         } else
89             actionForward = mapping.findForward("invalid");
90         return actionForward;
91     }
92 }
93
Popular Tags