| 1 25 29 package org.jresearch.gossip.actions.rss; 30 31 import java.sql.SQLException ; 32 import java.util.Calendar ; 33 import java.util.Date ; 34 import java.util.List ; 35 36 import javax.servlet.http.HttpServletRequest ; 37 import javax.servlet.http.HttpServletResponse ; 38 import javax.servlet.http.HttpSession ; 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 57 public class ShowLastTopicsFeedAction extends Action { 58 59 public static StringBuffer siteUrl; 60 61 private User rssReader = new User(); 62 63 80 public ActionForward execute(ActionMapping mapping, ActionForm form, 81 HttpServletRequest request, HttpServletResponse response) 82 throws Exception { 83 HttpSession session = request.getSession(); 84 String forward = "rss_main_page"; 85 86 if (siteUrl == null) { 87 siteUrl = new StringBuffer (); 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 cl = Calendar.getInstance(); 102 cl.setTime(new Date ()); 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 fid = ((ProcessForumForm) form).getFid(); 111 112 try { 113 114 List recordsData = null; 115 116 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 request.setAttribute(IConst.REQUEST.RSS_PUB_DATE, new Date ()); 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 sqle) { 142 getServlet().log("Connection.process", sqle); 143 throw new SystemException(sqle); 144 } 145 146 return (mapping.findForward(forward)); 147 } 148 } 149 | Popular Tags |