1 23 package org.infoglue.deliver.taglib.common; 24 25 import java.text.DateFormat ; 26 import java.text.SimpleDateFormat ; 27 import java.util.Date ; 28 29 import javax.servlet.jsp.JspException ; 30 import javax.servlet.jsp.JspTagException ; 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 44 45 public class RSSFeedEntryTag extends TemplateControllerTag 46 { 47 private final static Logger logger = Logger.getLogger(RSSFeedEntryTag.class.getName()); 48 49 52 private static final long serialVersionUID = 8603406098980150888L; 53 54 private String title = null; 55 private String link = null; 56 private Date publishedDate = null; 57 private String description = null; 58 private String descriptionContentType = "text/html"; 59 60 private static final String DATE_FORMAT = "yyyy-MM-dd"; 62 63 66 public RSSFeedEntryTag() 67 { 68 super(); 69 } 70 71 72 78 public int doEndTag() throws JspException  79 { 80 try 81 { 82 RssHelper rssHelper = new RssHelper(); 83 84 DateFormat dateParser = new SimpleDateFormat (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 e) 100 { 101 logger.error("An error occurred when generating RSS-feed:" + e.getMessage(), e); 102 } 103 104 return EVAL_PAGE; 105 } 106 107 112 protected void addEntry(SyndEntry entry) throws JspException  113 { 114 final RSSFeedTag parent = (RSSFeedTag) findAncestorWithClass(this, RSSFeedTag.class); 115 if(parent == null) 116 { 117 throw new JspTagException ("RSSFeedEntryTag must have a RSSFeedTag ancestor."); 118 } 119 120 ((RSSFeedTag) parent).addFeedEntry(entry); 121 } 122 123 124 public void setDescription(String description) throws JspException  125 { 126 this.description = evaluateString("RssFeedEntry", "description", description); 127 } 128 129 public void setLink(String link) throws JspException  130 { 131 this.link = evaluateString("RssFeedEntry", "link", link); 132 } 133 134 public void setTitle(String title) throws JspException  135 { 136 this.title = evaluateString("RssFeedEntry", "title", title); 137 } 138 139 public void setDescriptionContentType(String descriptionContentType) throws JspException  140 { 141 this.descriptionContentType = evaluateString("RssFeedEntry", "descriptionContentType", descriptionContentType); 142 } 143 144 public void setPublishedDate(String publishedDate) throws JspException  145 { 146 this.publishedDate = (Date )evaluate("RssFeedEntry", "publishedDate", publishedDate, Date .class); 147 } 148 } 149 | Popular Tags |