1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
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 /***
33 */
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 eChannel = rssRoot.getChild("channel",getRSSNamespace());
52 Element eCloud = eChannel.getChild("cloud",getRSSNamespace());
53 if (eCloud!=null) {
54 Cloud cloud = new Cloud();
55 String att = eCloud.getAttributeValue("domain");
56 if (att!=null) {
57 cloud.setDomain(att);
58 }
59 att = eCloud.getAttributeValue("port");
60 if (att!=null) {
61 cloud.setPort(Integer.parseInt(att));
62 }
63 att = eCloud.getAttributeValue("path");
64 if (att!=null) {
65 cloud.setPath(att);
66 }
67 att = eCloud.getAttributeValue("registerProcedure");
68 if (att!=null) {
69 cloud.setRegisterProcedure(att);
70 }
71 att = eCloud.getAttributeValue("protocol");
72 if (att!=null) {
73 cloud.setProtocol(att);
74 }
75 channel.setCloud(cloud);
76 }
77 return channel;
78 }
79
80 protected Item parseItem(Element rssRoot,Element eItem) {
81 Item item = super.parseItem(rssRoot,eItem);
82
83 Element e = eItem.getChild("source",getRSSNamespace());
84 if (e!=null) {
85 Source source = new Source();
86 String url = e.getAttributeValue("url");
87 source.setUrl(url);
88 source.setValue(e.getText());
89 item.setSource(source);
90 }
91
92
93
94 List eEnclosures = eItem.getChildren("enclosure");
95 if (eEnclosures.size()>0) {
96 List enclosures = new ArrayList();
97 for (int i=0;i<eEnclosures.size();i++) {
98 e = (Element) eEnclosures.get(i);
99
100 Enclosure enclosure = new Enclosure();
101 String att = e.getAttributeValue("url");
102 if (att!=null) {
103 enclosure.setUrl(att);
104 }
105 att = e.getAttributeValue("length");
106 if (att!=null && att.trim().length()>0) {
107 enclosure.setLength(Long.parseLong(att.trim()));
108 }
109 att = e.getAttributeValue("type");
110 if (att!=null) {
111 enclosure.setType(att);
112 }
113 enclosures.add(enclosure);
114 }
115 item.setEnclosures(enclosures);
116 }
117
118 List eCats = eItem.getChildren("category");
119 item.setCategories(parseCategories(eCats));
120
121 return item;
122 }
123
124 protected List parseCategories(List eCats) {
125 List cats = null;
126 if (eCats.size()>0) {
127 cats = new ArrayList();
128 for (int i=0;i<eCats.size();i++) {
129 Category cat = new Category();
130 Element e = (Element) eCats.get(i);
131 String att = e.getAttributeValue("domain");
132 if (att!=null) {
133 cat.setDomain(att);
134 }
135 cat.setValue(e.getText());
136 cats.add(cat);
137 }
138 }
139 return cats;
140 }
141
142 protected Description parseItemDescription(Element rssRoot,Element eDesc) {
143 Description desc = super.parseItemDescription(rssRoot,eDesc);
144 desc.setType("text/html");
145 return desc;
146 }
147
148 }