1 17 package com.sun.syndication.io.impl; 18 19 import com.sun.syndication.feed.rss.Channel; 20 import com.sun.syndication.feed.rss.Guid; 21 import com.sun.syndication.feed.rss.Item; 22 import com.sun.syndication.feed.rss.Category; 23 import org.jdom.Element; 24 25 import java.util.List ; 26 27 28 35 36 public class RSS20Generator extends RSS094Generator { 37 38 public RSS20Generator() { 39 this("rss_2.0","2.0"); 40 } 41 42 protected RSS20Generator(String feedType,String version) { 43 super(feedType,version); 44 } 45 46 protected void populateChannel(Channel channel,Element eChannel) { 47 super.populateChannel(channel,eChannel); 48 49 String generator = channel.getGenerator(); 50 if (generator != null) { 51 eChannel.addContent(generateSimpleElement("generator", generator)); 52 } 53 54 int ttl = channel.getTtl(); 55 if (ttl>-1) { 56 eChannel.addContent(generateSimpleElement("ttl", String.valueOf(ttl))); 57 } 58 59 List categories = channel.getCategories(); 60 for(int i = 0; i < categories.size(); i++) { 61 eChannel.addContent(generateCategoryElement((Category)categories.get(i))); 62 } 63 64 } 65 66 protected void populateItem(Item item, Element eItem, int index) { 67 super.populateItem(item,eItem, index); 68 69 Element eDescription = eItem.getChild("description",getFeedNamespace()); 70 eDescription.removeAttribute("type"); 72 73 String author = item.getAuthor(); 74 if (author != null) { 75 eItem.addContent(generateSimpleElement("author", author)); 76 } 77 78 String comments = item.getComments(); 79 if (comments != null) { 80 eItem.addContent(generateSimpleElement("comments", comments)); 81 } 82 83 Guid guid = item.getGuid(); 84 if (guid != null) { 85 Element eGuid = generateSimpleElement("guid",guid.getValue()); 86 if (!guid.isPermaLink()) { 87 eGuid.setAttribute("isPermaLink", "false"); 88 } 89 eItem.addContent(eGuid); 90 } 91 } 92 93 } 94 | Popular Tags |