KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jresearch > gossip > actions > message > UpdateMessageAction


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

25 /*
26  * Created on Sep 20, 2003
27  *
28  */

29 package org.jresearch.gossip.actions.message;
30
31 import java.sql.SQLException JavaDoc;
32
33 import javax.servlet.http.HttpServletRequest JavaDoc;
34 import javax.servlet.http.HttpServletResponse JavaDoc;
35 import javax.servlet.http.HttpSession JavaDoc;
36
37 import org.apache.struts.action.ActionForm;
38 import org.apache.struts.action.ActionForward;
39 import org.apache.struts.action.ActionMapping;
40 import org.jresearch.gossip.IConst;
41 import org.jresearch.gossip.actions.BaseAction;
42 import org.jresearch.gossip.beans.forum.Forum;
43 import org.jresearch.gossip.beans.forum.Message;
44 import org.jresearch.gossip.beans.forum.Topic;
45 import org.jresearch.gossip.beans.user.User;
46 import org.jresearch.gossip.configuration.Configurator;
47 import org.jresearch.gossip.dao.ForumDAO;
48 import org.jresearch.gossip.exception.SystemException;
49 import org.jresearch.gossip.forms.MessageForm;
50
51 /**
52  * DOCUMENT ME!
53  *
54  * @author Bel
55  */

56 public class UpdateMessageAction extends BaseAction {
57     /**
58      * DOCUMENT ME!
59      *
60      * @param mapping
61      * DOCUMENT ME!
62      * @param form
63      * DOCUMENT ME!
64      * @param request
65      * DOCUMENT ME!
66      * @param response
67      * DOCUMENT ME!
68      *
69      * @return DOCUMENT ME!
70      */

71     public ActionForward process(ActionMapping mapping, ActionForm form,
72             HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response)
73             throws SystemException {
74         HttpSession JavaDoc session = request.getSession();
75         MessageForm messageForm = (MessageForm) form;
76         User user = (User) session.getAttribute(IConst.SESSION.USER_KEY);
77         ForumDAO dao = ForumDAO.getInstance();
78
79         try {
80
81             boolean isUserMod = dao.checkMod(Integer.parseInt(messageForm
82                     .getFid()), user);
83             Forum currForum = dao.getForumInfo(Integer.parseInt(messageForm
84                     .getFid()));
85
86             // check access rights if forum invisible
87
if ((currForum.getLocked() == IConst.Forum.STATUS_INVISIBLE)
88                     && (user.getStatus() < Integer.parseInt(Configurator
89                             .getInstance().get(IConst.CONFIG.INVADER1)))) {
90                 return (mapping.findForward(IConst.TOKEN.DENIED));
91             }
92
93             Topic currThread = dao.getThreadInfo(Integer.parseInt(messageForm
94                     .getTid()));
95
96             // check user access rights if current topic or completely forum is
97
// locked
98
if (((currThread.getLocked() == IConst.Topic.STATUS_LOCKED) || (currForum
99                     .getLocked() == IConst.Forum.STATUS_COMPLETELY_LOCKED))
100                     && (!isUserMod)) {
101                 return (mapping.findForward(IConst.TOKEN.DENIED));
102             }
103
104             Message mess = dao.getMessage(messageForm.getMid());
105             session.removeAttribute(IConst.REQUEST.CURR_THREAD);
106
107             if (mess == null) {
108                 return (new ActionForward("/ShowThread.do?fid="
109                         + messageForm.getFid() + "&tid=" + messageForm.getTid()
110                         + "&block=" + messageForm.getBlock(), true));
111             } else {
112                 // check user access rights
113
if (dao.checkMod(Integer.parseInt(messageForm.getFid()), user)
114                         || (user.getName().equals(mess.getSender()) && (currThread
115                                 .getLocked() == IConst.Topic.STATUS_UNLOCKED))) {
116                     dao.updateMessage(messageForm);
117
118                     // subscribe user to e-mail from this thread...
119
if (IConst.VALUES.TRUE.equals(messageForm.getSubscribe())) {
120                         dao.subscribe(messageForm.getTid(), user.getInfo()
121                                 .getEmail(), user.getName());
122                     }
123
124                     log(request, "logs.LOG28", " mid=" + messageForm.getMid()
125                             + " tid=" + messageForm.getTid() + " fid="
126                             + messageForm.getFid());
127                 } else {
128                     return (mapping.findForward(IConst.TOKEN.DENIED));
129                 }
130             }
131         } catch (SQLException JavaDoc sqle) {
132             getServlet().log("Connection.process", sqle);
133             throw new SystemException(sqle);
134         }
135
136         StringBuffer JavaDoc forward = new StringBuffer JavaDoc();
137         forward.append("/ShowMessage.do?fid=");
138         forward.append(messageForm.getFid());
139         forward.append("&tid=");
140         forward.append(messageForm.getTid());
141         forward.append("&mid=");
142         forward.append(messageForm.getMid());
143
144         return (new ActionForward(forward.toString(), true));
145     }
146 }
147
Popular Tags