001: /*
002: * Copyright (c) JForum Team
003: * All rights reserved.
004: *
005: * Redistribution and use in source and binary forms,
006: * with or without modification, are permitted provided
007: * that the following conditions are met:
008: *
009: * 1) Redistributions of source code must retain the above
010: * copyright notice, this list of conditions and the
011: * following disclaimer.
012: * 2) Redistributions in binary form must reproduce the
013: * above copyright notice, this list of conditions and
014: * the following disclaimer in the documentation and/or
015: * other materials provided with the distribution.
016: * 3) Neither the name of "Rafael Steil" nor
017: * the names of its contributors may be used to endorse
018: * or promote products derived from this software without
019: * specific prior written permission.
020: *
021: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT
022: * HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
023: * EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
024: * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
025: * MERCHANTABILITY AND FITNESS FOR A PARTICULAR
026: * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
027: * THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
028: * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
029: * EXEMPLARY, OR CONSEQUENTIAL DAMAGES
030: * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
031: * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
032: * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
033: * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
034: * IN CONTRACT, STRICT LIABILITY, OR TORT
035: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
036: * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
037: * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
038: *
039: * Created on 13/10/2004 23:47:06
040: * The JForum Project
041: * http://www.jforum.net
042: */
043: package net.jforum.view.forum;
044:
045: import java.util.List;
046:
047: import net.jforum.Command;
048: import net.jforum.JForumExecutionContext;
049: import net.jforum.SessionFacade;
050: import net.jforum.context.RequestContext;
051: import net.jforum.context.ResponseContext;
052: import net.jforum.dao.DataAccessDriver;
053: import net.jforum.dao.PostDAO;
054: import net.jforum.dao.TopicDAO;
055: import net.jforum.entities.Forum;
056: import net.jforum.entities.Topic;
057: import net.jforum.repository.ForumRepository;
058: import net.jforum.util.I18n;
059: import net.jforum.util.preferences.ConfigKeys;
060: import net.jforum.util.preferences.SystemGlobals;
061: import net.jforum.util.preferences.TemplateKeys;
062: import net.jforum.util.rss.RSSAware;
063: import net.jforum.util.rss.RecentTopicsRSS;
064: import net.jforum.util.rss.TopicPostsRSS;
065: import net.jforum.util.rss.TopicRSS;
066: import net.jforum.view.forum.common.TopicsCommon;
067: import freemarker.template.SimpleHash;
068: import freemarker.template.Template;
069:
070: /**
071: * @author Rafael Steil
072: * @version $Id: RSSAction.java,v 1.32 2007/09/02 14:30:48 rafaelsteil Exp $
073: */
074: public class RSSAction extends Command {
075: /**
076: * RSS for all N first topics for some given forum
077: */
078: public void forumTopics() {
079: int forumId = this .request.getIntParameter("forum_id");
080:
081: if (!TopicsCommon.isTopicAccessible(forumId)) {
082: JForumExecutionContext.requestBasicAuthentication();
083: return;
084: }
085:
086: List posts = DataAccessDriver
087: .getInstance()
088: .newPostDAO()
089: .selectLatestByForumForRSS(
090: forumId,
091: SystemGlobals
092: .getIntValue(ConfigKeys.TOPICS_PER_PAGE));
093:
094: Forum forum = ForumRepository.getForum(forumId);
095: String[] p = { forum.getName() };
096:
097: RSSAware rss = new TopicRSS(I18n.getMessage(
098: "RSS.ForumTopics.title", p), I18n.getMessage(
099: "RSS.ForumTopics.description", p), forumId, posts);
100:
101: this .context.put("rssContents", rss.createRSS());
102: }
103:
104: /**
105: * RSS for all N first posts for some given topic
106: */
107: public void topicPosts() {
108: int topicId = this .request.getIntParameter("topic_id");
109:
110: PostDAO pm = DataAccessDriver.getInstance().newPostDAO();
111: TopicDAO tm = DataAccessDriver.getInstance().newTopicDAO();
112:
113: Topic topic = tm.selectById(topicId);
114:
115: if (!TopicsCommon.isTopicAccessible(topic.getForumId())
116: || topic.getId() == 0) {
117: JForumExecutionContext.requestBasicAuthentication();
118: return;
119: }
120:
121: tm.incrementTotalViews(topic.getId());
122:
123: List posts = pm.selectAllByTopic(topicId);
124:
125: String[] p = { topic.getTitle() };
126:
127: String title = I18n.getMessage("RSS.TopicPosts.title", p);
128: String description = I18n.getMessage(
129: "RSS.TopicPosts.description", p);
130:
131: RSSAware rss = new TopicPostsRSS(title, description, topic
132: .getForumId(), posts);
133: this .context.put("rssContents", rss.createRSS());
134: }
135:
136: public void recentTopics() {
137: String title = I18n.getMessage("RSS.RecentTopics.title",
138: new Object[] { SystemGlobals
139: .getValue(ConfigKeys.FORUM_NAME) });
140: String description = I18n
141: .getMessage("RSS.RecentTopics.description");
142:
143: List posts = DataAccessDriver
144: .getInstance()
145: .newPostDAO()
146: .selectHotForRSS(
147: SystemGlobals
148: .getIntValue(ConfigKeys.POSTS_PER_PAGE));
149:
150: RSSAware rss = new RecentTopicsRSS(title, description, posts);
151: this .context.put("rssContents", rss.createRSS());
152: }
153:
154: /**
155: * @see net.jforum.Command#list()
156: */
157: public void list() {
158:
159: }
160:
161: /**
162: * @see net.jforum.Command#process(net.jforum.context.RequestContext, net.jforum.context.ResponseContext, freemarker.template.SimpleHash)
163: */
164: public Template process(RequestContext request,
165: ResponseContext response, SimpleHash context) {
166: if (!SessionFacade.isLogged()
167: && UserAction.hasBasicAuthentication(request)) {
168: new UserAction().validateLogin(request);
169: JForumExecutionContext.setRedirect(null);
170: }
171:
172: JForumExecutionContext.setContentType("text/xml");
173: super.setTemplateName(TemplateKeys.RSS);
174:
175: return super.process(request, response, context);
176: }
177:
178: }
|