1 17 package com.sun.syndication.feed.synd.impl; 18 19 import com.sun.syndication.feed.WireFeed; 20 import com.sun.syndication.feed.module.impl.ModuleUtils; 21 import com.sun.syndication.feed.rss.Channel; 22 import com.sun.syndication.feed.rss.Image; 23 import com.sun.syndication.feed.rss.Item; 24 import com.sun.syndication.feed.synd.SyndFeed; 25 import com.sun.syndication.feed.synd.Converter; 26 import com.sun.syndication.feed.synd.SyndEntry; 27 import com.sun.syndication.feed.synd.SyndImage; 28 import com.sun.syndication.feed.synd.SyndImageImpl; 29 import com.sun.syndication.feed.synd.SyndEntryImpl; 30 31 import java.util.ArrayList ; 32 import java.util.List ; 33 34 36 public class ConverterForRSS090 implements Converter { 37 private String _type; 38 39 public ConverterForRSS090() { 40 this("rss_0.9"); 41 } 42 43 protected ConverterForRSS090(String type) { 44 _type = type; 45 } 46 47 public String getType() { 48 return _type; 49 } 50 51 public void copyInto(WireFeed feed,SyndFeed syndFeed) { 52 syndFeed.setModules(ModuleUtils.cloneModules(feed.getModules())); 53 54 syndFeed.setEncoding(feed.getEncoding()); 55 Channel channel = (Channel) feed; 56 syndFeed.setTitle(channel.getTitle()); 57 syndFeed.setLink(channel.getLink()); 58 syndFeed.setDescription(channel.getDescription()); 59 60 Image image = channel.getImage(); 61 if (image!=null) { 62 syndFeed.setImage(createSyndImage(image)); 63 } 64 65 List items = channel.getItems(); 66 if (items!=null) { 67 syndFeed.setEntries(createSyndEntries(items)); 68 } 69 } 70 71 protected SyndImage createSyndImage(Image rssImage) { 72 SyndImage syndImage = new SyndImageImpl(); 73 syndImage.setTitle(rssImage.getTitle()); 74 syndImage.setUrl(rssImage.getUrl()); 75 syndImage.setLink(rssImage.getLink()); 76 return syndImage; 77 } 78 79 protected List createSyndEntries(List rssItems) { 80 List syndEntries = new ArrayList (); 81 for (int i=0;i<rssItems.size();i++) { 82 syndEntries.add(createSyndEntry((Item) rssItems.get(i))); 83 } 84 return syndEntries; 85 } 86 87 protected SyndEntry createSyndEntry(Item item) { 88 SyndEntry syndEntry = new SyndEntryImpl(); 89 90 syndEntry.setModules(ModuleUtils.cloneModules(item.getModules())); 91 92 syndEntry.setUri(item.getLink()); 93 syndEntry.setTitle(item.getTitle()); 94 syndEntry.setLink(item.getLink()); 95 return syndEntry; 96 } 97 98 public WireFeed createRealFeed(SyndFeed syndFeed) { 99 return createRealFeed(getType(),syndFeed); 100 } 101 102 protected WireFeed createRealFeed(String type,SyndFeed syndFeed) { 103 Channel channel = new Channel(type); 104 channel.setModules(ModuleUtils.cloneModules(syndFeed.getModules())); 105 106 channel.setEncoding(syndFeed.getEncoding()); 107 108 channel.setTitle(syndFeed.getTitle()); 109 channel.setLink(syndFeed.getLink()); 110 channel.setDescription(syndFeed.getDescription()); 111 SyndImage sImage = syndFeed.getImage(); 112 if (sImage!=null) { 113 channel.setImage(createRSSImage(sImage)); 114 } 115 116 List sEntries = syndFeed.getEntries(); 117 if (sEntries!=null) { 118 channel.setItems(createRSSItems(sEntries)); 119 } 120 return channel; 121 } 122 123 protected Image createRSSImage(SyndImage sImage) { 124 Image image = new Image(); 125 image.setTitle(sImage.getTitle()); 126 image.setUrl(sImage.getUrl()); 127 image.setLink(sImage.getLink()); 128 return image; 129 } 130 131 protected List createRSSItems(List sEntries) { 132 List list = new ArrayList (); 133 for (int i=0;i<sEntries.size();i++) { 134 list.add(createRSSItem((SyndEntry)sEntries.get(i))); 135 } 136 return list; 137 } 138 139 protected Item createRSSItem(SyndEntry sEntry) { 140 Item item = new Item(); 141 item.setModules(ModuleUtils.cloneModules(sEntry.getModules())); 142 item.setTitle(sEntry.getTitle()); 143 item.setLink(sEntry.getLink()); 144 return item; 145 } 146 147 } 148 | Popular Tags |