KickJava   Java API By Example, From Geeks To Geeks.

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


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.text.DateFormat JavaDoc;
26 import java.text.SimpleDateFormat JavaDoc;
27 import java.util.Date JavaDoc;
28
29 import javax.servlet.jsp.JspException JavaDoc;
30 import javax.servlet.jsp.JspTagException JavaDoc;
31
32 import org.apache.log4j.Logger;
33 import org.infoglue.deliver.taglib.TemplateControllerTag;
34 import org.infoglue.deliver.util.rss.RssHelper;
35
36 import com.sun.syndication.feed.synd.SyndContent;
37 import com.sun.syndication.feed.synd.SyndContentImpl;
38 import com.sun.syndication.feed.synd.SyndEntry;
39 import com.sun.syndication.feed.synd.SyndEntryImpl;
40
41 /**
42  * This tag will generate a SyndEntry item to be used in a syndFeed.
43  */

44
45 public class RSSFeedEntryTag extends TemplateControllerTag
46 {
47     private final static Logger logger = Logger.getLogger(RSSFeedEntryTag.class.getName());
48
49     /**
50      * The universal version identifier.
51      */

52     private static final long serialVersionUID = 8603406098980150888L;
53     
54     private String JavaDoc title = null;
55     private String JavaDoc link = null;
56     private Date JavaDoc publishedDate = null;
57     private String JavaDoc description = null;
58     private String JavaDoc descriptionContentType = "text/html";
59     
60     //Lets use the iso date format
61
private static final String JavaDoc DATE_FORMAT = "yyyy-MM-dd";
62
63     /**
64      * Default constructor.
65      */

66     public RSSFeedEntryTag()
67     {
68         super();
69     }
70     
71
72     /**
73      * Process the end tag. Sets a cookie.
74      *
75      * @return indication of whether to continue evaluating the JSP page.
76      * @throws JspException if an error occurred while processing this tag.
77      */

78     public int doEndTag() throws JspException JavaDoc
79     {
80         try
81         {
82             RssHelper rssHelper = new RssHelper();
83             
84             DateFormat JavaDoc dateParser = new SimpleDateFormat JavaDoc(DATE_FORMAT);
85
86             SyndEntry entry = new SyndEntryImpl();
87             entry.setTitle(title);
88             entry.setLink(link);
89             entry.setPublishedDate(publishedDate);
90
91             SyndContent syndContent = new SyndContentImpl();
92             syndContent.setType(descriptionContentType);
93             syndContent.setValue(description);
94          
95             entry.setDescription(syndContent);
96             
97             addEntry(entry);
98         }
99         catch(Exception JavaDoc e)
100         {
101             logger.error("An error occurred when generating RSS-feed:" + e.getMessage(), e);
102         }
103         
104         return EVAL_PAGE;
105     }
106
107     /**
108      * Adds the parameter to the ancestor tag.
109      *
110      * @throws JspException if the ancestor tag isn't a url tag.
111      */

112     protected void addEntry(SyndEntry entry) throws JspException JavaDoc
113     {
114         final RSSFeedTag parent = (RSSFeedTag) findAncestorWithClass(this, RSSFeedTag.class);
115         if(parent == null)
116         {
117             throw new JspTagException JavaDoc("RSSFeedEntryTag must have a RSSFeedTag ancestor.");
118         }
119
120         ((RSSFeedTag) parent).addFeedEntry(entry);
121     }
122
123     
124     public void setDescription(String JavaDoc description) throws JspException JavaDoc
125     {
126         this.description = evaluateString("RssFeedEntry", "description", description);
127     }
128     
129     public void setLink(String JavaDoc link) throws JspException JavaDoc
130     {
131         this.link = evaluateString("RssFeedEntry", "link", link);
132     }
133     
134     public void setTitle(String JavaDoc title) throws JspException JavaDoc
135     {
136         this.title = evaluateString("RssFeedEntry", "title", title);
137     }
138     
139     public void setDescriptionContentType(String JavaDoc descriptionContentType) throws JspException JavaDoc
140     {
141         this.descriptionContentType = evaluateString("RssFeedEntry", "descriptionContentType", descriptionContentType);
142     }
143     
144     public void setPublishedDate(String JavaDoc publishedDate) throws JspException JavaDoc
145     {
146         this.publishedDate = (Date JavaDoc)evaluate("RssFeedEntry", "publishedDate", publishedDate, Date JavaDoc.class);
147     }
148 }
149
Popular Tags