1 17 package com.sun.syndication.io.impl; 18 19 import com.sun.syndication.feed.WireFeed; 20 import com.sun.syndication.feed.rss.Category; 21 import com.sun.syndication.feed.rss.Channel; 22 import com.sun.syndication.feed.rss.Cloud; 23 import com.sun.syndication.feed.rss.Description; 24 import com.sun.syndication.feed.rss.Enclosure; 25 import com.sun.syndication.feed.rss.Item; 26 import com.sun.syndication.feed.rss.Source; 27 import org.jdom.Element; 28 29 import java.util.ArrayList ; 30 import java.util.List ; 31 32 34 public class RSS092Parser extends RSS091UserlandParser { 35 36 public RSS092Parser() { 37 this("rss_0.92"); 38 } 39 40 protected RSS092Parser(String type) { 41 super(type); 42 } 43 44 protected String getRSSVersion() { 45 return "0.92"; 46 } 47 48 protected WireFeed parseChannel(Element rssRoot) { 49 Channel channel = (Channel) super.parseChannel(rssRoot); 50 51 Element eCloud = rssRoot.getChild("cloud",getRSSNamespace()); 52 if (eCloud!=null) { 53 Cloud cloud = new Cloud(); 54 String att = eCloud.getAttributeValue("domain"); if (att!=null) { 56 cloud.setDomain(att); 57 } 58 att = eCloud.getAttributeValue("port"); if (att!=null) { 60 cloud.setPort(Integer.parseInt(att)); 61 } 62 att = eCloud.getAttributeValue("registerProcedure"); if (att!=null) { 64 cloud.setRegisterProcedure(att); 65 } 66 att = eCloud.getAttributeValue("protocol"); if (att!=null) { 68 cloud.setProtocol(att); 69 } 70 } 71 return channel; 72 } 73 74 protected Item parseItem(Element rssRoot,Element eItem) { 75 Item item = super.parseItem(rssRoot,eItem); 76 77 Element e = eItem.getChild("source",getRSSNamespace()); 78 if (e!=null) { 79 Source source = new Source(); 80 String url = e.getAttributeValue("url"); source.setUrl(url); 82 source.setValue(e.getText()); 83 item.setSource(source); 84 } 85 86 List eEnclosures = eItem.getChildren("enclosure"); if (eEnclosures.size()>0) { 90 List enclosures = new ArrayList (); 91 for (int i=0;i<eEnclosures.size();i++) { 92 e = (Element) eEnclosures.get(i); 93 94 Enclosure enclosure = new Enclosure(); 95 String att = e.getAttributeValue("url"); if (att!=null) { 97 enclosure.setUrl(att); 98 } 99 att = e.getAttributeValue("length"); if (att!=null) { 101 enclosure.setLength(Long.parseLong(att)); 102 } 103 att = e.getAttributeValue("type"); if (att!=null) { 105 enclosure.setType(att); 106 } 107 enclosures.add(enclosure); 108 } 109 item.setEnclosures(enclosures); 110 } 111 112 List eCats = eItem.getChildren("category"); item.setCategories(parseCategories(eCats)); 114 115 return item; 116 } 117 118 protected List parseCategories(List eCats) { 119 List cats = null; 120 if (eCats.size()>0) { 121 cats = new ArrayList (); 122 for (int i=0;i<eCats.size();i++) { 123 Category cat = new Category(); 124 Element e = (Element) eCats.get(i); 125 String att = e.getAttributeValue("domain"); if (att!=null) { 127 cat.setDomain(att); 128 } 129 cat.setValue(e.getText()); 130 cats.add(cat); 131 } 132 } 133 return cats; 134 } 135 136 protected Description parseItemDescription(Element rssRoot,Element eDesc) { 137 Description desc = super.parseItemDescription(rssRoot,eDesc); 138 desc.setType("text/html"); 139 return desc; 140 } 141 142 } 143 | Popular Tags |