1 23 package org.infoglue.deliver.util.rss; 24 25 import java.io.IOException ; 26 import java.text.DateFormat ; 27 import java.text.SimpleDateFormat ; 28 import java.util.ArrayList ; 29 import java.util.Date ; 30 import java.util.List ; 31 32 import org.apache.log4j.Logger; 33 34 import com.sun.syndication.feed.synd.SyndContent; 35 import com.sun.syndication.feed.synd.SyndContentImpl; 36 import com.sun.syndication.feed.synd.SyndEntry; 37 import com.sun.syndication.feed.synd.SyndEntryImpl; 38 import com.sun.syndication.feed.synd.SyndFeed; 39 import com.sun.syndication.feed.synd.SyndFeedImpl; 40 import com.sun.syndication.io.FeedException; 41 import com.sun.syndication.io.SyndFeedOutput; 42 43 48 49 public class RssHelper 50 { 51 private final static Logger logger = Logger.getLogger(RssHelper.class.getName()); 52 53 private static final String COULD_NOT_GENERATE_FEED_ERROR = "Could not generate feed"; 55 56 private static final String DATE_FORMAT = "yyyy-MM-dd"; 58 59 private String defaultFeedType = "atom_0.3"; 60 61 66 67 public String render(SyndFeed feed) 68 { 69 String output = null; 70 71 try 72 { 73 SyndFeedOutput out = new SyndFeedOutput(); 75 output = out.outputString(feed); 76 } 77 catch (FeedException fe) 78 { 79 String msg = COULD_NOT_GENERATE_FEED_ERROR; 80 logger.error(msg, fe); 81 } 83 84 return output; 85 } 86 96 97 public SyndFeed getFeed(String feedType, String title, String link, String description, String encoding) throws IOException ,FeedException 98 { 99 100 SyndFeed feed = new SyndFeedImpl(); 101 102 feedType = (feedType!=null) ? feedType : defaultFeedType; 103 feed.setFeedType(feedType); 104 105 feed.setTitle(title); 106 feed.setLink(link); 107 feed.setDescription(description); 108 feed.setEncoding(encoding); 109 110 List entries = new ArrayList (); 111 112 feed.setEntries(entries); 113 114 return feed; 115 } 116 117 129 130 public void addEntry(SyndFeed feed, String title, String link, Date publishedDate, String description, String descriptionContentType) throws IOException ,FeedException 131 { 132 DateFormat dateParser = new SimpleDateFormat (DATE_FORMAT); 133 134 SyndEntry entry = new SyndEntryImpl(); 135 entry.setTitle(title); 136 entry.setLink(link); 137 entry.setPublishedDate(publishedDate); 138 139 SyndContent syndContent = new SyndContentImpl(); 140 syndContent.setType(descriptionContentType); 141 syndContent.setValue(description); 142 143 entry.setDescription(syndContent); 144 145 feed.getEntries().add(entry); 146 } 147 148 } 149 | Popular Tags |