RSSAction.java
Upload User: gdxydsw
Upload Date: 2019-01-29
Package Size: 16721k
Code Size: 5k
Category:

Java Develop

Development Platform:

Java

  1. /*
  2.  * Copyright (c) JForum Team
  3.  * All rights reserved.
  4.  * 
  5.  * Redistribution and use in source and binary forms, 
  6.  * with or without modification, are permitted provided 
  7.  * that the following conditions are met:
  8.  * 
  9.  * 1) Redistributions of source code must retain the above 
  10.  * copyright notice, this list of conditions and the 
  11.  * following  disclaimer.
  12.  * 2)  Redistributions in binary form must reproduce the 
  13.  * above copyright notice, this list of conditions and 
  14.  * the following disclaimer in the documentation and/or 
  15.  * other materials provided with the distribution.
  16.  * 3) Neither the name of "Rafael Steil" nor 
  17.  * the names of its contributors may be used to endorse 
  18.  * or promote products derived from this software without 
  19.  * specific prior written permission.
  20.  * 
  21.  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT 
  22.  * HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 
  23.  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, 
  24.  * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 
  25.  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR 
  26.  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 
  27.  * THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE 
  28.  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 
  29.  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES 
  30.  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
  31.  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, 
  32.  * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 
  33.  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER 
  34.  * IN CONTRACT, STRICT LIABILITY, OR TORT 
  35.  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 
  36.  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 
  37.  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
  38.  * 
  39.  * Created on 13/10/2004 23:47:06
  40.  * The JForum Project
  41.  * http://www.jforum.net
  42.  */
  43. package net.jforum.view.forum;
  44. import java.util.List;
  45. import net.jforum.Command;
  46. import net.jforum.JForumExecutionContext;
  47. import net.jforum.SessionFacade;
  48. import net.jforum.context.RequestContext;
  49. import net.jforum.context.ResponseContext;
  50. import net.jforum.dao.DataAccessDriver;
  51. import net.jforum.dao.PostDAO;
  52. import net.jforum.dao.TopicDAO;
  53. import net.jforum.entities.Forum;
  54. import net.jforum.entities.Topic;
  55. import net.jforum.repository.ForumRepository;
  56. import net.jforum.util.I18n;
  57. import net.jforum.util.preferences.ConfigKeys;
  58. import net.jforum.util.preferences.SystemGlobals;
  59. import net.jforum.util.preferences.TemplateKeys;
  60. import net.jforum.util.rss.RSSAware;
  61. import net.jforum.util.rss.RecentTopicsRSS;
  62. import net.jforum.util.rss.TopicPostsRSS;
  63. import net.jforum.util.rss.TopicRSS;
  64. import net.jforum.view.forum.common.TopicsCommon;
  65. import freemarker.template.SimpleHash;
  66. import freemarker.template.Template;
  67. /**
  68.  * @author Rafael Steil
  69.  * @version $Id: RSSAction.java,v 1.32 2007/09/02 14:30:48 rafaelsteil Exp $
  70.  */
  71. public class RSSAction extends Command 
  72. {
  73. /**
  74.  * RSS for all N first topics for some given forum
  75.  */
  76. public void forumTopics()
  77. {
  78. int forumId = this.request.getIntParameter("forum_id"); 
  79. if (!TopicsCommon.isTopicAccessible(forumId)) {
  80. JForumExecutionContext.requestBasicAuthentication();
  81.             return;
  82. }
  83. List posts = DataAccessDriver.getInstance().newPostDAO().selectLatestByForumForRSS(
  84. forumId, SystemGlobals.getIntValue(ConfigKeys.TOPICS_PER_PAGE));
  85. Forum forum = ForumRepository.getForum(forumId);
  86. String[] p = { forum.getName() };
  87. RSSAware rss = new TopicRSS(I18n.getMessage("RSS.ForumTopics.title", p),
  88. I18n.getMessage("RSS.ForumTopics.description", p),
  89. forumId, 
  90. posts);
  91. this.context.put("rssContents", rss.createRSS());
  92. }
  93. /**
  94.  * RSS for all N first posts for some given topic
  95.  */
  96. public void topicPosts()
  97. {
  98. int topicId = this.request.getIntParameter("topic_id");
  99. PostDAO pm = DataAccessDriver.getInstance().newPostDAO();
  100. TopicDAO tm = DataAccessDriver.getInstance().newTopicDAO();
  101. Topic topic = tm.selectById(topicId);
  102. if (!TopicsCommon.isTopicAccessible(topic.getForumId()) || topic.getId() == 0) {
  103. JForumExecutionContext.requestBasicAuthentication(); 
  104.             return;
  105. }
  106. tm.incrementTotalViews(topic.getId());
  107. List posts = pm.selectAllByTopic(topicId);
  108. String[] p = { topic.getTitle() };
  109. String title = I18n.getMessage("RSS.TopicPosts.title", p);
  110. String description = I18n.getMessage("RSS.TopicPosts.description", p);
  111. RSSAware rss = new TopicPostsRSS(title, description, topic.getForumId(), posts);
  112. this.context.put("rssContents", rss.createRSS());
  113. }
  114. public void recentTopics()
  115. {
  116. String title = I18n.getMessage("RSS.RecentTopics.title", 
  117. new Object[] { SystemGlobals.getValue(ConfigKeys.FORUM_NAME) });
  118. String description = I18n.getMessage("RSS.RecentTopics.description");
  119. List posts = DataAccessDriver.getInstance().newPostDAO().selectHotForRSS(
  120. SystemGlobals.getIntValue(ConfigKeys.POSTS_PER_PAGE));
  121. RSSAware rss = new RecentTopicsRSS(title, description, posts);
  122. this.context.put("rssContents", rss.createRSS());
  123. }
  124. /** 
  125.  * @see net.jforum.Command#list()
  126.  */
  127. public void list()
  128. {
  129. }
  130. /** 
  131.  * @see net.jforum.Command#process(net.jforum.context.RequestContext, net.jforum.context.ResponseContext, freemarker.template.SimpleHash) 
  132.  */
  133. public Template process(RequestContext request,
  134. ResponseContext response,
  135. SimpleHash context)
  136. {
  137.         if (!SessionFacade.isLogged() && UserAction.hasBasicAuthentication(request)) {
  138.             new UserAction().validateLogin(request);
  139.             JForumExecutionContext.setRedirect(null);
  140.         }
  141.         JForumExecutionContext.setContentType("text/xml");
  142. super.setTemplateName(TemplateKeys.RSS);
  143. return super.process(request, response, context);
  144. }
  145. }