KickJava   Java API By Example, From Geeks To Geeks.

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


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

23 /*
24  * Created on Sep 25, 2003
25  *
26  */

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

56 public abstract class GetMessageAction 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 = new MessageForm();
76         ProcessMessageForm pmForm = (ProcessMessageForm) form;
77         ForumDAO dao = ForumDAO.getInstance();
78         User user = (User) session.getAttribute(IConst.SESSION.USER_KEY);
79         try {
80
81             int fid = Integer.parseInt(pmForm.getFid());
82             boolean isUserMod = dao.checkMod(fid, user);
83             Forum currForum = dao.getForumInfo(fid);
84             // check access rights if forum invisible
85
getServlet().log("check access rights if forum invisible");
86             if ((currForum.getLocked() == IConst.Forum.STATUS_INVISIBLE)
87                     && (user.getStatus() < Integer.parseInt(Configurator
88                             .getInstance().get(IConst.CONFIG.INVADER1)))) {
89                 return (mapping.findForward(IConst.TOKEN.DENIED));
90             }
91             Topic currThread = dao.getThreadInfo(Integer.parseInt(pmForm
92                     .getTid()));
93             // check user access rights if current topic or completely forum is
94
// locked
95
getServlet()
96                     .log(
97                             "check user access rights if current topic or completely forum is 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             session.setAttribute(IConst.REQUEST.CURR_THREAD, currThread);
104             currThread.setSubject(dao.getThreadSubject(pmForm.getTid()));
105             Message mess = dao.getMessage(pmForm.getMid());
106             if (mess == null) {
107                 return (new ActionForward("/ShowThread.do?fid="
108                         + pmForm.getFid() + "&tid=" + pmForm.getTid()
109                         + "&block=" + pmForm.getBlock(), true));
110             } else {
111                 String JavaDoc fname = fillMessageForm(messageForm, mess, pmForm,
112                         request);
113                 request.setAttribute(fname, messageForm);
114             }
115         } catch (SQLException JavaDoc sqle) {
116             getServlet().log("Connection.process", sqle);
117             throw new SystemException(sqle);
118         }
119         return (mapping.findForward(IConst.TOKEN.PAGE));
120     }
121
122     /**
123      * Fill message form and specify it's name in request scope
124      *
125      * @param messageForm
126      * @param mess
127      * @param form
128      * @param request
129      *
130      * @return name of request attribute which will store messageForm
131      * @throws ConfiguratorException
132      */

133     abstract protected String JavaDoc fillMessageForm(MessageForm messageForm,
134             Message mess, ProcessMessageForm form, HttpServletRequest JavaDoc request)
135             throws ConfiguratorException;
136 }
Popular Tags