KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jresearch > gossip > actions > topic > ShowTopicAction


1 /*
2  * $$Id: ShowTopicAction.java,v 1.5 2005/06/09 07:55:18 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 16, 2003
25  *
26  */

27 package org.jresearch.gossip.actions.topic;
28
29 import java.lang.reflect.InvocationTargetException JavaDoc;
30 import java.sql.SQLException JavaDoc;
31 import java.util.Date JavaDoc;
32 import java.util.HashMap JavaDoc;
33 import java.util.Iterator JavaDoc;
34
35 import javax.servlet.http.HttpServletRequest JavaDoc;
36 import javax.servlet.http.HttpServletResponse JavaDoc;
37 import javax.servlet.http.HttpSession JavaDoc;
38
39 import org.apache.struts.action.ActionForm;
40 import org.apache.struts.action.ActionForward;
41 import org.apache.struts.action.ActionMapping;
42 import org.jresearch.gossip.IConst;
43 import org.jresearch.gossip.actions.BaseAction;
44 import org.jresearch.gossip.beans.forum.Forum;
45 import org.jresearch.gossip.beans.forum.Message;
46 import org.jresearch.gossip.beans.forum.Topic;
47 import org.jresearch.gossip.beans.user.User;
48 import org.jresearch.gossip.configuration.Configurator;
49 import org.jresearch.gossip.dao.ForumDAO;
50 import org.jresearch.gossip.dao.UserDAO;
51 import org.jresearch.gossip.exception.SystemException;
52 import org.jresearch.gossip.forms.ProcessTopicForm;
53 import org.jresearch.gossip.list.RecordsData;
54
55 /**
56  * DOCUMENT ME!
57  *
58  * @author Bel
59  */

60 public class ShowTopicAction extends BaseAction {
61     /**
62      * DOCUMENT ME!
63      *
64      * @param mapping
65      * DOCUMENT ME!
66      * @param form
67      * DOCUMENT ME!
68      * @param request
69      * DOCUMENT ME!
70      * @param response
71      * DOCUMENT ME!
72      *
73      * @return DOCUMENT ME!
74      */

75     public ActionForward process(ActionMapping mapping, ActionForm form,
76             HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response)
77             throws SystemException {
78         ProcessTopicForm ptForm = (ProcessTopicForm) form;
79         ForumDAO dao = ForumDAO.getInstance();
80         UserDAO userdao = UserDAO.getInstance();
81         HttpSession JavaDoc session = request.getSession();
82         User user = (User) session.getAttribute(IConst.SESSION.USER_KEY);
83         int fid = Integer.parseInt(ptForm.getFid());
84         int tid = Integer.parseInt(ptForm.getTid());
85         try {
86
87             Forum currForum = dao.getForumInfo(fid);
88             // check access rights if forum invisible
89
if ((currForum.getLocked() == IConst.Forum.STATUS_INVISIBLE)
90                     && (user.getStatus() < Integer.parseInt(Configurator
91                             .getInstance().get(IConst.CONFIG.INVADER1)))) {
92                 return (mapping.findForward(IConst.TOKEN.DENIED));
93             }
94             request.setAttribute(IConst.REQUEST.CURR_FORUM, currForum);
95             session.setAttribute(IConst.SESSION.CURR_FORUM, currForum);
96             updateLastVisitTime((HashMap JavaDoc) session
97                     .getAttribute(IConst.SESSION.LAST_INTIME), ptForm.getTid(),
98                     dao.now());
99             RecordsData recordsData = new RecordsData();
100             Topic currThread = dao.getThreadInfo(tid);
101             dao.fillMessagesList(user, recordsData, ptForm);
102             Iterator JavaDoc it = recordsData.getRecords().iterator();
103             boolean attachEnabled = Configurator.getInstance().getBoolean(
104                     IConst.CONFIG.ENABLE_FILE_UPLOAD);
105             if (it.hasNext()) {
106                 Message mess = (Message) it.next();
107                 mess.setSenderInfo(userdao.getSenderInfo(mess.getSender()));
108                 if (attachEnabled) {
109                     mess.setAttachments(dao.getAttachmentsInfo(mess.getId()));
110                 }
111             } else {
112                 return (new ActionForward("/ShowForum.do?fid="
113                         + ptForm.getFid(), true));
114             }
115             while (it.hasNext()) {
116                 Message mess = (Message) it.next();
117                 mess.setSenderInfo(userdao.getSenderInfo(mess.getSender()));
118                 if (attachEnabled) {
119                     mess.setAttachments(dao.getAttachmentsInfo(mess.getId()));
120                 }
121             }
122
123             request.setAttribute(IConst.REQUEST.RECORDS_DATA, recordsData);
124             request.setAttribute(IConst.REQUEST.CURR_THREAD, currThread);
125             if (dao.checkMod(fid, user)) {
126                 request.setAttribute(IConst.REQUEST.MOD_FLAG,
127                         IConst.VALUES.TRUE);
128             }
129         } catch (SQLException JavaDoc sqle) {
130             getServlet().log("Connection.process", sqle);
131             throw new SystemException(sqle);
132         } catch (InstantiationException JavaDoc e) {
133             throw new SystemException(e);
134         } catch (IllegalAccessException JavaDoc e) {
135             throw new SystemException(e);
136         } catch (InvocationTargetException JavaDoc e) {
137             throw new SystemException(e);
138         } catch (NoSuchMethodException JavaDoc e) {
139             throw new SystemException(e);
140         }
141         return (mapping.findForward("showThread"));
142     }
143
144     // set(update) last visit date for topic
145
private void updateLastVisitTime(HashMap JavaDoc last_intime, String JavaDoc tid, Date JavaDoc now) {
146         if (last_intime.containsKey(tid)) {
147             last_intime.remove(tid);
148         }
149         last_intime.put(tid, now);
150     }
151 }
Popular Tags