KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > infoglue > deliver > taglib > common > RSSFeedTag


1 /* ===============================================================================
2 *
3 * Part of the InfoGlue Content Management Platform (www.infoglue.org)
4 *
5 * ===============================================================================
6 *
7 * Copyright (C)
8 *
9 * This program is free software; you can redistribute it and/or modify it under
10 * the terms of the GNU General Public License version 2, as published by the
11 * Free Software Foundation. See the file LICENSE.html for more information.
12 *
13 * This program is distributed in the hope that it will be useful, but WITHOUT
14 * ANY WARRANTY, including the implied warranty of MERCHANTABILITY or FITNESS
15 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License along with
18 * this program; if not, write to the Free Software Foundation, Inc. / 59 Temple
19 * Place, Suite 330 / Boston, MA 02111-1307 / USA.
20 *
21 * ===============================================================================
22 */

23 package org.infoglue.deliver.taglib.common;
24
25 import java.util.ArrayList JavaDoc;
26 import java.util.List JavaDoc;
27
28 import javax.servlet.jsp.JspException JavaDoc;
29
30 import org.apache.log4j.Logger;
31 import org.infoglue.deliver.taglib.TemplateControllerTag;
32 import org.infoglue.deliver.util.rss.RssHelper;
33
34 import com.sun.syndication.feed.synd.SyndEntry;
35 import com.sun.syndication.feed.synd.SyndFeed;
36
37 /**
38  * This tag will get a cookie value
39  */

40
41 public class RSSFeedTag extends TemplateControllerTag
42 {
43     private final static Logger logger = Logger.getLogger(RSSFeedTag.class.getName());
44
45     /**
46      * The universal version identifier.
47      */

48     private static final long serialVersionUID = 8603406098980150888L;
49     
50     private String JavaDoc feedType = null;
51     private String JavaDoc title = null;
52     private String JavaDoc link = null;
53     private String JavaDoc description = null;
54     private String JavaDoc encoding = "UTF-8";
55     
56     private List JavaDoc entries = new ArrayList JavaDoc();
57     
58     /**
59      * Default constructor.
60      */

61     public RSSFeedTag()
62     {
63         super();
64     }
65     
66     /**
67      * Initializes the parameters to make it accessible for the children tags (if any).
68      *
69      * @return indication of whether to evaluate the body or not.
70      * @throws JspException if an error occurred while processing this tag.
71      */

72     public int doStartTag() throws JspException JavaDoc
73     {
74         return EVAL_BODY_INCLUDE;
75     }
76
77     /**
78      * Process the end tag. Sets a cookie.
79      *
80      * @return indication of whether to continue evaluating the JSP page.
81      * @throws JspException if an error occurred while processing this tag.
82      */

83     public int doEndTag() throws JspException JavaDoc
84     {
85         try
86         {
87             RssHelper rssHelper = new RssHelper();
88             SyndFeed feed = rssHelper.getFeed(this.feedType, this.title, this.link, this.description, this.encoding);
89
90             feed.setEntries(entries);
91             
92             String JavaDoc rss = rssHelper.render(feed);
93             setResultAttribute(rss);
94         }
95         catch(Exception JavaDoc e)
96         {
97             logger.error("An error occurred when generating RSS-feed:" + e.getMessage(), e);
98         }
99         finally
100         {
101             entries = new ArrayList JavaDoc();
102         }
103         
104         return EVAL_PAGE;
105     }
106
107     public void setFeedType(String JavaDoc feedType) throws JspException JavaDoc
108     {
109         this.feedType = evaluateString("RssFeed", "feedType", feedType);;
110     }
111     
112     public void setDescription(String JavaDoc description) throws JspException JavaDoc
113     {
114         this.description = evaluateString("RssFeed", "description", description);
115     }
116     
117     public void setLink(String JavaDoc link) throws JspException JavaDoc
118     {
119         this.link = evaluateString("RssFeed", "link", link);
120     }
121     
122     public void setTitle(String JavaDoc title) throws JspException JavaDoc
123     {
124         this.title = evaluateString("RssFeed", "title", title);
125     }
126     
127     /**
128      * Add syndentry to the list of entries that are to be rendered.
129      */

130     public void addFeedEntry(final SyndEntry entry)
131     {
132         this.entries.add(entry);
133     }
134
135     public void setEncoding(String JavaDoc encoding)
136     {
137         this.encoding = encoding;
138     }
139 }
140
Popular Tags