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 21/10/2004 00:10:00
040: * The JForum Project
041: * http://www.jforum.net
042: */
043: package net.jforum.util.rss;
044:
045: import java.util.Iterator;
046: import java.util.List;
047:
048: import net.jforum.entities.Post;
049: import net.jforum.util.preferences.ConfigKeys;
050: import net.jforum.util.preferences.SystemGlobals;
051: import net.jforum.view.forum.common.PostCommon;
052: import net.jforum.view.forum.common.ViewCommon;
053:
054: /**
055: * @author Rafael Steil
056: * @version $Id: TopicRSS.java,v 1.18 2007/08/20 19:35:52 rafaelsteil Exp $
057: */
058: public class TopicRSS extends GenericRSS {
059: protected List posts;
060: protected RSS rss;
061: protected String forumLink;
062:
063: TopicRSS() {
064: }
065:
066: public TopicRSS(String title, String description, int forumId,
067: List posts) {
068: this .posts = posts;
069: this .forumLink = ViewCommon.getForumLink();
070:
071: this .rss = new RSS(title, description, SystemGlobals
072: .getValue(ConfigKeys.ENCODING), this .forumLink
073: + "forums/show/" + forumId
074: + SystemGlobals.getValue(ConfigKeys.SERVLET_EXTENSION));
075:
076: this .prepareRSS();
077: }
078:
079: protected void prepareRSS() {
080: for (Iterator iter = posts.iterator(); iter.hasNext();) {
081: Post post = (Post) iter.next();
082:
083: post.setBbCodeEnabled(false);
084: post.setSmiliesEnabled(false);
085:
086: RSSItem item = new RSSItem();
087:
088: item.setAuthor(post.getPostUsername());
089: item.setPublishDate(RSSUtils.formatDate(post.getTime()));
090: item.setLink(this .forumLink
091: + "posts/preList/"
092: + post.getTopicId()
093: + "/"
094: + post.getId()
095: + SystemGlobals
096: .getValue(ConfigKeys.SERVLET_EXTENSION));
097: item.setTitle(post.getSubject());
098: item.setContentType(RSSAware.CONTENT_HTML);
099: item.setDescription(PostCommon.preparePostForDisplay(post)
100: .getText());
101:
102: this.rss.addItem(item);
103: }
104:
105: super.setRSS(this.rss);
106: }
107: }
|