KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jresearch > gossip > actions > forum > MarkReadAction


1 /*
2  * $Id: MarkReadAction.java,v 1.3 2005/06/07 12:32:33 bel70 Exp $
3  *
4  * ***** BEGIN LICENSE BLOCK *****
5  *
6  * The contents of this file are subject to the Mozilla Public License
7  * Version 1.1 (the "License"); you may not use this file except in
8  * 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"
12  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
13  * the License for the specific language governing rights and
14  * limitations under the License.
15  *
16  * The Original Code is JGossip forum code.
17  *
18  * The Initial Developer of the Original Code is the JResearch, Org.
19  * Portions created by the Initial Developer are Copyright (C) 2004
20  * the Initial Developer. All Rights Reserved.
21  *
22  * Contributor(s):
23  * Dmitriy Belov <bel@jresearch.org>
24  * .
25  * * ***** END LICENSE BLOCK ***** */

26 /*
27  * Created on 01.05.2004
28  *
29  */

30 package org.jresearch.gossip.actions.forum;
31
32 import java.sql.SQLException JavaDoc;
33 import java.util.Date JavaDoc;
34 import java.util.HashMap JavaDoc;
35 import java.util.Iterator JavaDoc;
36 import java.util.List JavaDoc;
37
38 import javax.servlet.http.HttpServletRequest JavaDoc;
39 import javax.servlet.http.HttpServletResponse JavaDoc;
40 import javax.servlet.http.HttpSession JavaDoc;
41
42 import org.apache.struts.action.Action;
43 import org.apache.struts.action.ActionForm;
44 import org.apache.struts.action.ActionForward;
45 import org.apache.struts.action.ActionMapping;
46 import org.jresearch.gossip.IConst;
47 import org.jresearch.gossip.beans.user.User;
48 import org.jresearch.gossip.dao.ForumDAO;
49 import org.jresearch.gossip.exception.SystemException;
50 import org.jresearch.gossip.forms.ProcessForumForm;
51
52 /**
53  * DOCUMENT ME!
54  *
55  * @author Dmitry Belov
56  */

57 public class MarkReadAction extends Action {
58     /**
59      * DOCUMENT ME!
60      *
61      * @param mapping
62      * DOCUMENT ME!
63      * @param form
64      * DOCUMENT ME!
65      * @param request
66      * DOCUMENT ME!
67      * @param response
68      * DOCUMENT ME!
69      *
70      * @return DOCUMENT ME!
71      *
72      * @throws Exception
73      * DOCUMENT ME!
74      */

75     public ActionForward execute(ActionMapping mapping, ActionForm form,
76             HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response)
77             throws Exception JavaDoc {
78         ForumDAO dao = ForumDAO.getInstance();
79         HttpSession JavaDoc session = request.getSession();
80         User user = (User) session.getAttribute(IConst.SESSION.USER_KEY);
81         List JavaDoc updatedTopics = null;
82         ActionForward forward = null;
83         String JavaDoc fid = ((ProcessForumForm) form).getFid();
84
85         try {
86
87             if (fid == null || fid.equals("")) {
88                 updatedTopics = dao.getUpdatedTopics(user);
89                 forward = mapping.findForward(IConst.TOKEN.WELCOME);
90             } else {
91                 updatedTopics = dao.getUpdatedTopics(user, Integer
92                         .parseInt(fid));
93                 forward = new ActionForward("/ShowForum.do?fid=" + fid, true);
94             }
95
96             Iterator JavaDoc it = updatedTopics.iterator();
97
98             HashMap JavaDoc lastIntimeMap = (HashMap JavaDoc) session
99                     .getAttribute(IConst.SESSION.LAST_INTIME);
100             Date JavaDoc now = dao.now();
101
102             while (it.hasNext()) {
103                 updateLastVisitTime(lastIntimeMap, (String JavaDoc) it.next(), now);
104             }
105         } catch (SQLException JavaDoc sqle) {
106             getServlet().log("Connection.process", sqle);
107             throw new SystemException(sqle);
108         }
109
110         return (forward);
111     }
112
113     // set(update) last visit date for topic
114
private void updateLastVisitTime(HashMap JavaDoc last_intime, String JavaDoc tid, Date JavaDoc now) {
115         if (last_intime.containsKey(tid)) {
116             last_intime.remove(tid);
117         }
118
119         last_intime.put(tid, now);
120     }
121 }
122
Popular Tags