KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jresearch > gossip > actions > rss > ShowLastTopicsFeedAction


1 /*
2  * $$Id: ShowLastTopicsFeedAction.java,v 1.3 2005/06/07 12:32:32 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 Jul 13, 2003
27  *
28  */

29 package org.jresearch.gossip.actions.rss;
30
31 import java.sql.SQLException JavaDoc;
32 import java.util.Calendar JavaDoc;
33 import java.util.Date JavaDoc;
34 import java.util.List JavaDoc;
35
36 import javax.servlet.http.HttpServletRequest JavaDoc;
37 import javax.servlet.http.HttpServletResponse JavaDoc;
38 import javax.servlet.http.HttpSession JavaDoc;
39
40 import org.apache.struts.action.Action;
41 import org.apache.struts.action.ActionForm;
42 import org.apache.struts.action.ActionForward;
43 import org.apache.struts.action.ActionMapping;
44 import org.jresearch.gossip.IConst;
45 import org.jresearch.gossip.beans.forum.Forum;
46 import org.jresearch.gossip.beans.user.User;
47 import org.jresearch.gossip.configuration.Configurator;
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 Bel
56  */

57 public class ShowLastTopicsFeedAction extends Action {
58
59     public static StringBuffer JavaDoc siteUrl;
60
61     private User rssReader = new User();
62
63     /**
64      * DOCUMENT ME!
65      *
66      * @param mapping
67      * DOCUMENT ME!
68      * @param form
69      * DOCUMENT ME!
70      * @param request
71      * DOCUMENT ME!
72      * @param response
73      * DOCUMENT ME!
74      *
75      * @return DOCUMENT ME!
76      *
77      * @throws Exception
78      * DOCUMENT ME!
79      */

80     public ActionForward execute(ActionMapping mapping, ActionForm form,
81             HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response)
82             throws Exception JavaDoc {
83         HttpSession JavaDoc session = request.getSession();
84         String JavaDoc forward = "rss_main_page";
85
86         if (siteUrl == null) {
87             siteUrl = new StringBuffer JavaDoc();
88             siteUrl.append(request.getServerName());
89             siteUrl.append(":");
90             siteUrl.append(request.getServerPort());
91             siteUrl.append(request.getContextPath());
92             siteUrl.append(Configurator.getInstance().get(
93                     IConst.CONFIG.MODULE_PREFIX));
94             siteUrl.append("/");
95         }
96
97         request.setAttribute(IConst.REQUEST.SITE_URL, siteUrl.toString());
98
99         ForumDAO dao = ForumDAO.getInstance();
100
101         Calendar JavaDoc cl = Calendar.getInstance();
102         cl.setTime(new Date JavaDoc());
103         cl.add(Calendar.DATE, -1
104                 * Integer.parseInt(Configurator.getInstance().get(
105                         IConst.CONFIG.RSS_PERIOD)));
106         rssReader.setIntime(cl.getTime());
107         getServlet().log(
108                 "ShowLastThreadsAction: try to show LastThreads RSS Feed");
109
110         String JavaDoc fid = ((ProcessForumForm) form).getFid();
111
112         try {
113
114             List JavaDoc recordsData = null;
115
116             // TODO cache
117
if (fid == null || fid.equals("")) {
118                 recordsData = dao.getLastTopics(Integer.parseInt(Configurator
119                         .getInstance().get(IConst.CONFIG.RSS_MAX_ITEM_COUNT)),
120                         cl.getTime());
121             } else {
122                 int id = Integer.parseInt(fid);
123                 recordsData = dao.getLastTopics(id, Integer
124                         .parseInt(Configurator.getInstance().get(
125                                 IConst.CONFIG.RSS_MAX_ITEM_COUNT)), cl
126                         .getTime());
127
128                 Forum currForum = dao.getForumInfo(id);
129                 currForum.setForumid(id);
130                 request.setAttribute(IConst.REQUEST.CURR_FORUM, currForum);
131                 forward = "rss_forum_page";
132             }
133
134             // TODO - set pubDate
135
request.setAttribute(IConst.REQUEST.RSS_PUB_DATE, new Date JavaDoc());
136             getServlet().log(
137                     "ShowLastThreadsAction: " + recordsData.size()
138                             + " topic(s) since " + cl.getTime()
139                             + " has been found, fid=" + fid);
140             request.setAttribute(IConst.REQUEST.RECORDS_DATA, recordsData);
141         } catch (SQLException JavaDoc sqle) {
142             getServlet().log("Connection.process", sqle);
143             throw new SystemException(sqle);
144         }
145
146         return (mapping.findForward(forward));
147     }
148 }
149
Popular Tags