1 17 package com.sun.syndication.io.impl; 18 19 import com.sun.syndication.feed.WireFeed; 20 import com.sun.syndication.feed.rss.Channel; 21 import com.sun.syndication.feed.rss.Description; 22 import com.sun.syndication.feed.rss.Item; 23 import org.jdom.Document; 24 import org.jdom.Element; 25 import org.jdom.Namespace; 26 27 import java.util.List ; 28 29 31 public class RSS10Parser extends RSS090Parser { 32 33 private static final String RSS_URI = "http://purl.org/rss/1.0/"; 34 35 public RSS10Parser() { 36 this("rss_1.0"); 37 } 38 39 protected RSS10Parser(String type) { 40 super(type); 41 } 42 43 52 public boolean isMyType(Document document) { 53 boolean ok = false; 54 55 Element rssRoot = document.getRootElement(); 56 Namespace defaultNS = rssRoot.getNamespace(); 57 List additionalNSs = rssRoot.getAdditionalNamespaces(); 58 59 ok = defaultNS!=null && defaultNS.equals(getRDFNamespace()); 60 if (ok) { 61 if (additionalNSs==null) { 62 ok = false; 63 } 64 else { 65 ok = false; 66 for (int i=0;!ok && i<additionalNSs.size();i++) { 67 ok = getRSSNamespace().equals(additionalNSs.get(i)); 68 } 69 } 70 } 71 return ok; 72 } 73 74 80 protected Namespace getRSSNamespace() { 81 return Namespace.getNamespace(RSS_URI); 82 } 83 84 94 protected Item parseItem(Element rssRoot,Element eItem) { 95 Item item = super.parseItem(rssRoot,eItem); 96 Element e = eItem.getChild("description",getRSSNamespace()); 97 if (e!=null) { 98 item.setDescription(parseItemDescription(rssRoot,e)); 99 } 100 return item; 101 } 102 103 protected WireFeed parseChannel(Element rssRoot) { 104 Channel channel = (Channel) super.parseChannel(rssRoot); 105 106 Element eChannel = rssRoot.getChild("channel", getRSSNamespace()); 107 String uri = eChannel.getAttributeValue("about", getRDFNamespace()); 108 if (uri != null) { 109 channel.setUri(uri); 110 } 111 112 return channel; 113 } 114 115 protected Description parseItemDescription(Element rssRoot,Element eDesc) { 116 Description desc = new Description(); 117 desc.setType("text/plain"); 118 desc.setValue(eDesc.getText()); 119 return desc; 120 } 121 122 } 123 | Popular Tags |