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.AbstractFeed;
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 RSS091Parser {
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 AbstractFeed 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");
55 if (att!=null) {
56 cloud.setDomain(att);
57 }
58 att = eCloud.getAttributeValue("port");
59 if (att!=null) {
60 cloud.setPort(Integer.parseInt(att));
61 }
62 att = eCloud.getAttributeValue("registerProcedure");
63 if (att!=null) {
64 cloud.setRegisterProcedure(att);
65 }
66 att = eCloud.getAttributeValue("protocol");
67 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");
81 source.setUrl(url);
82 source.setValue(e.getText());
83 item.setSource(source);
84 }
85
86
87
88 List eEnclosures = eItem.getChildren("enclosure");
89 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");
96 if (att!=null) {
97 enclosure.setUrl(att);
98 }
99 att = e.getAttributeValue("length");
100 if (att!=null) {
101 enclosure.setLength(Integer.parseInt(att));
102 }
103 att = e.getAttributeValue("type");
104 if (att!=null) {
105 enclosure.setUrl(att);
106 }
107 enclosures.add(enclosure);
108 }
109 item.setEnclosures(enclosures);
110 }
111
112 List eCats = eItem.getChildren("category");
113 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");
126 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 }