1 43 package net.jforum.view.forum; 44 45 import java.util.List ; 46 47 import javax.servlet.http.HttpServletResponse ; 48 49 import net.jforum.ActionServletRequest; 50 import net.jforum.Command; 51 import net.jforum.JForumExecutionContext; 52 import net.jforum.SessionFacade; 53 import net.jforum.dao.DataAccessDriver; 54 import net.jforum.dao.PostDAO; 55 import net.jforum.dao.TopicDAO; 56 import net.jforum.dao.UserDAO; 57 import net.jforum.entities.Forum; 58 import net.jforum.entities.Topic; 59 import net.jforum.entities.User; 60 import net.jforum.repository.ForumRepository; 61 import net.jforum.util.I18n; 62 import net.jforum.util.preferences.ConfigKeys; 63 import net.jforum.util.preferences.SystemGlobals; 64 import net.jforum.util.preferences.TemplateKeys; 65 import net.jforum.util.rss.ForumRSS; 66 import net.jforum.util.rss.RSSAware; 67 import net.jforum.util.rss.RecentTopicsRSS; 68 import net.jforum.util.rss.TopicPostsRSS; 69 import net.jforum.util.rss.TopicRSS; 70 import net.jforum.util.rss.UserPostsRSS; 71 import net.jforum.util.rss.UserTopicsRSS; 72 import net.jforum.view.forum.common.ForumCommon; 73 import net.jforum.view.forum.common.TopicsCommon; 74 import freemarker.template.SimpleHash; 75 import freemarker.template.Template; 76 77 81 public class RSSAction extends Command 82 { 83 89 public void forums() throws Exception 90 { 91 String title = I18n.getMessage("RSS.Forums.title"); 92 String description = I18n.getMessage("RSS.Forums.description"); 93 94 RSSAware rss = new ForumRSS(title, description, ForumCommon.getAllCategoriesAndForums(false)); 95 this.context.put("rssContents", rss.createRSS()); 96 } 97 98 102 public void forumTopics() throws Exception 103 { 104 int forumId = this.request.getIntParameter("forum_id"); 105 if (!TopicsCommon.isTopicAccessible(forumId)) { 106 JForumExecutionContext.requestBasicAuthentication(); 107 return; 108 } 109 110 List topics = TopicsCommon.topicsByForum(forumId, 0); 111 Forum forum = ForumRepository.getForum(forumId); 112 113 String [] p = { forum.getName() }; 114 115 RSSAware rss = new TopicRSS(I18n.getMessage("RSS.ForumTopics.title", p), 116 I18n.getMessage("RSS.ForumTopics.description", p), 117 forumId, 118 topics); 119 this.context.put("rssContents", rss.createRSS()); 120 } 121 122 126 public void topicPosts() throws Exception 127 { 128 int topicId = this.request.getIntParameter("topic_id"); 129 130 PostDAO pm = DataAccessDriver.getInstance().newPostDAO(); 131 TopicDAO tm = DataAccessDriver.getInstance().newTopicDAO(); 132 133 Topic topic = tm.selectById(topicId); 134 135 if (!TopicsCommon.isTopicAccessible(topic.getForumId()) || topic.getId() == 0) { 136 JForumExecutionContext.requestBasicAuthentication(); 137 return; 138 } 139 140 tm.incrementTotalViews(topic.getId()); 141 142 List posts = pm.selectAllByTopic(topicId); 143 144 String [] p = { topic.getTitle() }; 145 146 String title = I18n.getMessage("RSS.TopicPosts.title", p); 147 String description = I18n.getMessage("RSS.TopicPosts.description", p); 148 149 RSSAware rss = new TopicPostsRSS(title, description, topic.getForumId(), posts); 150 this.context.put("rssContents", rss.createRSS()); 151 } 152 153 public void recentTopics() throws Exception 154 { 155 String title = I18n.getMessage("RSS.RecentTopics.title", 156 new Object [] { SystemGlobals.getValue(ConfigKeys.FORUM_NAME) }); 157 String description = I18n.getMessage("RSS.RecentTopics.description"); 158 159 RSSAware rss = new RecentTopicsRSS(title, description, 160 new RecentTopicsAction().topics()); 161 this.context.put("rssContents", rss.createRSS()); 162 } 163 164 public void showTopicsByUser() throws Exception 165 { 166 int uid = this.request.getIntParameter("user_id"); 167 168 UserDAO um = DataAccessDriver.getInstance().newUserDAO(); 169 User u = um.selectById(uid); 170 171 if (u == null || u.getId() == 0) { 172 return; 173 } 174 175 List topics = DataAccessDriver.getInstance().newTopicDAO().selectByUserByLimit(u.getId(), 176 0, 177 SystemGlobals.getIntValue(ConfigKeys.TOPICS_PER_PAGE)); 178 179 String [] p = { u.getUsername() }; 180 181 String title = I18n.getMessage("RSS.TopicsByUser.title", p); 182 String description = I18n.getMessage("RSS.TopicsByUser.description", p); 183 184 RSSAware rss = new UserTopicsRSS(title, description, u.getId(), topics); 185 this.context.put("rssContents", rss.createRSS()); 186 } 187 188 public void showPostsByUser() throws Exception 189 { 190 int uid = this.request.getIntParameter("user_id"); 191 192 UserDAO um = DataAccessDriver.getInstance().newUserDAO(); 193 User u = um.selectById(uid); 194 195 if (u == null || u.getId() == 0) { 196 return; 197 } 198 199 List topics = DataAccessDriver.getInstance().newPostDAO().selectByUserByLimit(u.getId(), 200 0, 201 SystemGlobals.getIntValue(ConfigKeys.POST_PER_PAGE)); 202 203 String [] p = { u.getUsername() }; 204 205 String title = I18n.getMessage("RSS.PostsByPosts.title", p); 206 String description = I18n.getMessage("RSS.PostsByPosts.description", p); 207 208 RSSAware rss = new UserPostsRSS(title, description, u.getId(), topics); 209 this.context.put("rssContents", rss.createRSS()); 210 } 211 212 215 public void list() throws Exception 216 { 217 this.forums(); 218 } 219 220 223 public Template process(ActionServletRequest request, 224 HttpServletResponse response, 225 SimpleHash context) throws Exception 226 { 227 if (!SessionFacade.isLogged() && UserAction.hasBasicAuthentication(request)) { 228 new UserAction().validateLogin(request); 229 JForumExecutionContext.setRedirect(null); 230 } 231 232 JForumExecutionContext.setContentType("text/xml"); 233 super.setTemplateName(TemplateKeys.RSS); 234 235 return super.process(request, response, context); 236 } 237 238 } 239 | Popular Tags |