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.Channel;
21 import com.sun.syndication.feed.rss.Content;
22 import com.sun.syndication.feed.rss.Description;
23 import com.sun.syndication.feed.rss.Image;
24 import com.sun.syndication.feed.rss.Item;
25 import org.jdom.Attribute;
26 import org.jdom.Document;
27 import org.jdom.Element;
28 import org.jdom.Namespace;
29
30 import java.util.*;
31
32
33
34 public class RSS091UserlandParser extends RSS090Parser {
35
36 public RSS091UserlandParser() {
37 this("rss_0.91U");
38 }
39
40 protected RSS091UserlandParser(String type) {
41 super(type);
42 }
43
44 public boolean isMyType(Document document) {
45 boolean ok;
46 Element rssRoot = document.getRootElement();
47 ok = rssRoot.getName().equals("rss");
48 if (ok) {
49 ok = false;
50 Attribute version = rssRoot.getAttribute("version");
51 if (version!=null) {
52 ok = version.getValue().equals(getRSSVersion());
53 }
54 }
55 return ok;
56 }
57
58 protected String getRSSVersion() {
59 return "0.91";
60 }
61
62 protected Namespace getRSSNamespace() {
63 return Namespace.getNamespace("");
64 }
65
66
67
68
69 protected boolean isHourFormat24(Element rssRoot) {
70 return true;
71 }
72
73
74
75
76
77
78
79
80
81
82
83 protected WireFeed parseChannel(Element rssRoot) {
84 Channel channel = (Channel) super.parseChannel(rssRoot);
85
86 Element eChannel = rssRoot.getChild("channel",getRSSNamespace());
87
88 Element e = eChannel.getChild("language",getRSSNamespace());
89 if (e!=null) {
90 channel.setLanguage(e.getText());
91 }
92 e = eChannel.getChild("rating",getRSSNamespace());
93 if (e!=null) {
94 channel.setRating(e.getText());
95 }
96 e = eChannel.getChild("copyright",getRSSNamespace());
97 if (e!=null) {
98 channel.setCopyright(e.getText());
99 }
100 e = eChannel.getChild("pubDate",getRSSNamespace());
101 if (e!=null) {
102 channel.setPubDate(DateParser.parseDate(e.getText()));
103 }
104 e = eChannel.getChild("lastBuildDate",getRSSNamespace());
105 if (e!=null) {
106 channel.setLastBuildDate(DateParser.parseDate(e.getText()));
107 }
108 e = eChannel.getChild("docs",getRSSNamespace());
109 if (e!=null) {
110 channel.setDocs(e.getText());
111 }
112 e = eChannel.getChild("docs",getRSSNamespace());
113 if (e!=null) {
114 channel.setDocs(e.getText());
115 }
116 e = eChannel.getChild("managingEditor",getRSSNamespace());
117 if (e!=null) {
118 channel.setManagingEditor(e.getText());
119 }
120 e = eChannel.getChild("webMaster",getRSSNamespace());
121 if (e!=null) {
122 channel.setWebMaster(e.getText());
123 }
124 e = eChannel.getChild("skipHours");
125 if (e!=null) {
126 List skipHours = new ArrayList();
127 List eHours = e.getChildren("hour",getRSSNamespace());
128 for (int i=0;i<eHours.size();i++) {
129 Element eHour = (Element) eHours.get(i);
130 skipHours.add(new Integer(eHour.getText().trim()));
131 }
132 channel.setSkipHours(skipHours);
133 }
134
135 e = eChannel.getChild("skipDays");
136 if (e!=null) {
137 List skipDays = new ArrayList();
138 List eDays = e.getChildren("day",getRSSNamespace());
139 for (int i=0;i<eDays.size();i++) {
140 Element eDay = (Element) eDays.get(i);
141 skipDays.add(eDay.getText().trim());
142 }
143 channel.setSkipDays(skipDays);
144 }
145 return channel;
146 }
147
148
149
150
151
152
153
154
155
156
157
158 protected Image parseImage(Element rssRoot) {
159 Image image = super.parseImage(rssRoot);
160 if (image!=null) {
161 Element eImage = getImage(rssRoot);
162 Element e = eImage.getChild("width",getRSSNamespace());
163 if (e!=null) {
164 image.setWidth(Integer.parseInt(e.getText().trim()));
165 }
166 e = eImage.getChild("height",getRSSNamespace());
167 if (e!=null) {
168 image.setHeight(Integer.parseInt(e.getText().trim()));
169 }
170 e = eImage.getChild("description",getRSSNamespace());
171 if (e!=null) {
172 image.setDescription(e.getText());
173 }
174 }
175 return image;
176 }
177
178
179
180
181
182 protected List getItems(Element rssRoot) {
183 Element eChannel = rssRoot.getChild("channel",getRSSNamespace());
184 return (eChannel!=null) ? eChannel.getChildren("item",getRSSNamespace()) : Collections.EMPTY_LIST;
185 }
186
187
188
189
190 protected Element getImage(Element rssRoot) {
191 Element eChannel = rssRoot.getChild("channel",getRSSNamespace());
192 return (eChannel!=null) ? eChannel.getChild("image",getRSSNamespace()) : null;
193 }
194
195
196
197
198 protected String getTextInputLabel() {
199 return "textInput";
200 }
201
202
203
204
205 protected Element getTextInput(Element rssRoot) {
206 String elementName = getTextInputLabel();
207 Element eChannel = rssRoot.getChild("channel",getRSSNamespace());
208 return (eChannel!=null) ? eChannel.getChild(elementName,getRSSNamespace()) : null;
209 }
210
211
212
213
214
215
216
217
218
219
220
221 protected Item parseItem(Element rssRoot, Element eItem) {
222 Item item = super.parseItem(rssRoot,eItem);
223 Element e = eItem.getChild("description", getRSSNamespace());
224 if (e!=null) {
225 item.setDescription(parseItemDescription(rssRoot,e));
226 }
227 Element ce = eItem.getChild("encoded", getContentNamespace());
228 if (ce != null) {
229 Content content = new Content();
230 content.setType(Content.HTML);
231 content.setValue(ce.getText());
232 item.setContent(content);
233 }
234 return item;
235 }
236
237 protected Description parseItemDescription(Element rssRoot,Element eDesc) {
238 Description desc = new Description();
239 desc.setType("text/plain");
240 desc.setValue(eDesc.getText());
241 return desc;
242 }
243
244 }