KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jresearch > gossip > actions > subscription > UnsubscribeAction


1 /*
2  * $$Id: UnsubscribeAction.java,v 1.3 2005/06/07 12:32:32 bel70 Exp $$
3  *
4  * ***** BEGIN LICENSE BLOCK *****
5  *
6  * The contents of this file are subject to the
7  * Mozilla Public License Version 1.1 (the "License"); you may not use this file
8  * except in compliance with the License. You may obtain a copy of the License
9  * at http://www.mozilla.org/MPL/
10  *
11  * Software distributed under the License is distributed on an "AS IS" basis,
12  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
13  * the specific language governing rights and limitations under the License.
14  *
15  * The Original Code is JGossip forum code.
16  *
17  * The Initial Developer of the Original Code is the JResearch, Org. Portions
18  * created by the Initial Developer are Copyright (C) 2004 the Initial
19  * Developer. All Rights Reserved.
20  *
21  * Contributor(s): Dmitry Belov <bel@jresearch.org>
22  *
23  * ***** END LICENSE BLOCK *****
24  */

25 package org.jresearch.gossip.actions.subscription;
26
27 import java.sql.SQLException JavaDoc;
28
29 import javax.servlet.http.HttpServletRequest JavaDoc;
30 import javax.servlet.http.HttpServletResponse JavaDoc;
31 import javax.servlet.http.HttpSession JavaDoc;
32
33 import org.apache.struts.action.ActionForm;
34 import org.apache.struts.action.ActionForward;
35 import org.apache.struts.action.ActionMapping;
36 import org.apache.struts.action.ActionMessage;
37 import org.apache.struts.action.ActionMessages;
38 import org.apache.struts.util.MessageResources;
39 import org.jresearch.gossip.IConst;
40 import org.jresearch.gossip.actions.BaseAction;
41 import org.jresearch.gossip.beans.user.User;
42 import org.jresearch.gossip.dao.ForumDAO;
43 import org.jresearch.gossip.exception.SystemException;
44 import org.jresearch.gossip.forms.SubscribeForm;
45
46 /**
47  * DOCUMENT ME!
48  *
49  * @author dbelov
50  */

51 public class UnsubscribeAction extends BaseAction {
52     /*
53      * (non-Javadoc)
54      *
55      * @see org.jresearch.gossip.actions.BaseAction#process(org.apache.struts.action.ActionMapping,
56      * org.apache.struts.action.ActionForm,
57      * javax.servlet.http.HttpServletRequest,
58      * javax.servlet.http.HttpServletResponse)
59      */

60     public ActionForward process(ActionMapping mapping, ActionForm form,
61             HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response)
62             throws SystemException {
63         ForumDAO dao = ForumDAO.getInstance();
64         HttpSession JavaDoc session = request.getSession();
65         ActionMessages errors = new ActionMessages();
66         MessageResources messages = getResources(request);
67         SubscribeForm sForm = (SubscribeForm) form;
68         User user = (User) session.getAttribute(IConst.SESSION.USER_KEY);
69         String JavaDoc uname = null;
70         String JavaDoc inputForward = null;
71         String JavaDoc email = null;
72         if (user.getStatus() == 0) {
73             inputForward = "unsubscribe";
74             if ((sForm.getEmail() == null) || sForm.getEmail().equals("")) {
75                 errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage(
76                         "errors.required", new Object JavaDoc[] { messages
77                                 .getMessage("user.U_MAIL") }));
78                 saveErrors(request, errors);
79                 return (mapping.findForward(inputForward));
80             } else {
81                 email = sForm.getEmail();
82                 uname = "<%>";
83             }
84         } else {
85             inputForward = "subscriptions";
86             uname = user.getName();
87             email = user.getInfo().getEmail();
88         }
89         try {
90
91             if (dao.unsubscribe(email, uname, sForm.getTid())) {
92                 if (user.getStatus() == 0) {
93                     setStatusMessage(request, "mails.OK1");
94                 }
95             } else if (user.getStatus() == 0) {
96                 errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage(
97                         "mails.NOSUB2"));
98                 saveErrors(request, errors);
99             }
100         } catch (SQLException JavaDoc sqle) {
101             getServlet().log("Connection.process", sqle);
102             throw new SystemException(sqle);
103         }
104         return (mapping.findForward(inputForward));
105     }
106 }
Popular Tags