1 | require "rss/parser"
|
---|
2 |
|
---|
3 | module RSS
|
---|
4 |
|
---|
5 | module RSS10
|
---|
6 | NSPOOL = {}
|
---|
7 | ELEMENTS = []
|
---|
8 |
|
---|
9 | def self.append_features(klass)
|
---|
10 | super
|
---|
11 |
|
---|
12 | klass.install_must_call_validator('', ::RSS::URI)
|
---|
13 | end
|
---|
14 |
|
---|
15 | end
|
---|
16 |
|
---|
17 | class RDF < Element
|
---|
18 |
|
---|
19 | include RSS10
|
---|
20 | include RootElementMixin
|
---|
21 |
|
---|
22 | class << self
|
---|
23 |
|
---|
24 | def required_uri
|
---|
25 | URI
|
---|
26 | end
|
---|
27 |
|
---|
28 | end
|
---|
29 |
|
---|
30 | @tag_name = 'RDF'
|
---|
31 |
|
---|
32 | PREFIX = 'rdf'
|
---|
33 | URI = "http://www.w3.org/1999/02/22-rdf-syntax-ns#"
|
---|
34 |
|
---|
35 | install_ns('', ::RSS::URI)
|
---|
36 | install_ns(PREFIX, URI)
|
---|
37 |
|
---|
38 | [
|
---|
39 | ["channel", nil],
|
---|
40 | ["image", "?"],
|
---|
41 | ["item", "+", :children],
|
---|
42 | ["textinput", "?"],
|
---|
43 | ].each do |tag, occurs, type|
|
---|
44 | type ||= :child
|
---|
45 | __send__("install_have_#{type}_element", tag, ::RSS::URI, occurs)
|
---|
46 | end
|
---|
47 |
|
---|
48 | attr_accessor :rss_version, :version, :encoding, :standalone
|
---|
49 |
|
---|
50 | def initialize(version=nil, encoding=nil, standalone=nil)
|
---|
51 | super('1.0', version, encoding, standalone)
|
---|
52 | end
|
---|
53 |
|
---|
54 | def full_name
|
---|
55 | tag_name_with_prefix(PREFIX)
|
---|
56 | end
|
---|
57 |
|
---|
58 | class Li < Element
|
---|
59 |
|
---|
60 | include RSS10
|
---|
61 |
|
---|
62 | class << self
|
---|
63 | def required_uri
|
---|
64 | URI
|
---|
65 | end
|
---|
66 | end
|
---|
67 |
|
---|
68 | [
|
---|
69 | ["resource", [URI, ""], true]
|
---|
70 | ].each do |name, uri, required|
|
---|
71 | install_get_attribute(name, uri, required)
|
---|
72 | end
|
---|
73 |
|
---|
74 | def initialize(*args)
|
---|
75 | if Utils.element_initialize_arguments?(args)
|
---|
76 | super
|
---|
77 | else
|
---|
78 | super()
|
---|
79 | self.resource = args[0]
|
---|
80 | end
|
---|
81 | end
|
---|
82 |
|
---|
83 | def full_name
|
---|
84 | tag_name_with_prefix(PREFIX)
|
---|
85 | end
|
---|
86 | end
|
---|
87 |
|
---|
88 | class Seq < Element
|
---|
89 |
|
---|
90 | include RSS10
|
---|
91 |
|
---|
92 | Li = ::RSS::RDF::Li
|
---|
93 |
|
---|
94 | class << self
|
---|
95 | def required_uri
|
---|
96 | URI
|
---|
97 | end
|
---|
98 | end
|
---|
99 |
|
---|
100 | @tag_name = 'Seq'
|
---|
101 |
|
---|
102 | install_have_children_element("li", URI, "*")
|
---|
103 | install_must_call_validator('rdf', ::RSS::RDF::URI)
|
---|
104 |
|
---|
105 | def initialize(*args)
|
---|
106 | if Utils.element_initialize_arguments?(args)
|
---|
107 | super
|
---|
108 | else
|
---|
109 | super()
|
---|
110 | @li = args[0] if args[0]
|
---|
111 | end
|
---|
112 | end
|
---|
113 |
|
---|
114 | def full_name
|
---|
115 | tag_name_with_prefix(PREFIX)
|
---|
116 | end
|
---|
117 |
|
---|
118 | def setup_maker(target)
|
---|
119 | lis.each do |li|
|
---|
120 | target << li.resource
|
---|
121 | end
|
---|
122 | end
|
---|
123 | end
|
---|
124 |
|
---|
125 | class Bag < Element
|
---|
126 |
|
---|
127 | include RSS10
|
---|
128 |
|
---|
129 | Li = ::RSS::RDF::Li
|
---|
130 |
|
---|
131 | class << self
|
---|
132 | def required_uri
|
---|
133 | URI
|
---|
134 | end
|
---|
135 | end
|
---|
136 |
|
---|
137 | @tag_name = 'Bag'
|
---|
138 |
|
---|
139 | install_have_children_element("li", URI, "*")
|
---|
140 | install_must_call_validator('rdf', URI)
|
---|
141 |
|
---|
142 | def initialize(*args)
|
---|
143 | if Utils.element_initialize_arguments?(args)
|
---|
144 | super
|
---|
145 | else
|
---|
146 | super()
|
---|
147 | @li = args[0] if args[0]
|
---|
148 | end
|
---|
149 | end
|
---|
150 |
|
---|
151 | def full_name
|
---|
152 | tag_name_with_prefix(PREFIX)
|
---|
153 | end
|
---|
154 |
|
---|
155 | def setup_maker(target)
|
---|
156 | lis.each do |li|
|
---|
157 | target << li.resource
|
---|
158 | end
|
---|
159 | end
|
---|
160 | end
|
---|
161 |
|
---|
162 | class Channel < Element
|
---|
163 |
|
---|
164 | include RSS10
|
---|
165 |
|
---|
166 | class << self
|
---|
167 |
|
---|
168 | def required_uri
|
---|
169 | ::RSS::URI
|
---|
170 | end
|
---|
171 |
|
---|
172 | end
|
---|
173 |
|
---|
174 | [
|
---|
175 | ["about", URI, true]
|
---|
176 | ].each do |name, uri, required|
|
---|
177 | install_get_attribute(name, uri, required, nil, nil,
|
---|
178 | "#{PREFIX}:#{name}")
|
---|
179 | end
|
---|
180 |
|
---|
181 | [
|
---|
182 | ['title', nil, :text],
|
---|
183 | ['link', nil, :text],
|
---|
184 | ['description', nil, :text],
|
---|
185 | ['image', '?', :have_child],
|
---|
186 | ['items', nil, :have_child],
|
---|
187 | ['textinput', '?', :have_child],
|
---|
188 | ].each do |tag, occurs, type|
|
---|
189 | __send__("install_#{type}_element", tag, ::RSS::URI, occurs)
|
---|
190 | end
|
---|
191 |
|
---|
192 | def initialize(*args)
|
---|
193 | if Utils.element_initialize_arguments?(args)
|
---|
194 | super
|
---|
195 | else
|
---|
196 | super()
|
---|
197 | self.about = args[0]
|
---|
198 | end
|
---|
199 | end
|
---|
200 |
|
---|
201 | private
|
---|
202 | def maker_target(maker)
|
---|
203 | maker.channel
|
---|
204 | end
|
---|
205 |
|
---|
206 | def setup_maker_attributes(channel)
|
---|
207 | channel.about = about
|
---|
208 | end
|
---|
209 |
|
---|
210 | class Image < Element
|
---|
211 |
|
---|
212 | include RSS10
|
---|
213 |
|
---|
214 | class << self
|
---|
215 |
|
---|
216 | def required_uri
|
---|
217 | ::RSS::URI
|
---|
218 | end
|
---|
219 |
|
---|
220 | end
|
---|
221 |
|
---|
222 | [
|
---|
223 | ["resource", URI, true]
|
---|
224 | ].each do |name, uri, required|
|
---|
225 | install_get_attribute(name, uri, required, nil, nil,
|
---|
226 | "#{PREFIX}:#{name}")
|
---|
227 | end
|
---|
228 |
|
---|
229 | def initialize(*args)
|
---|
230 | if Utils.element_initialize_arguments?(args)
|
---|
231 | super
|
---|
232 | else
|
---|
233 | super()
|
---|
234 | self.resource = args[0]
|
---|
235 | end
|
---|
236 | end
|
---|
237 | end
|
---|
238 |
|
---|
239 | class Textinput < Element
|
---|
240 |
|
---|
241 | include RSS10
|
---|
242 |
|
---|
243 | class << self
|
---|
244 |
|
---|
245 | def required_uri
|
---|
246 | ::RSS::URI
|
---|
247 | end
|
---|
248 |
|
---|
249 | end
|
---|
250 |
|
---|
251 | [
|
---|
252 | ["resource", URI, true]
|
---|
253 | ].each do |name, uri, required|
|
---|
254 | install_get_attribute(name, uri, required, nil, nil,
|
---|
255 | "#{PREFIX}:#{name}")
|
---|
256 | end
|
---|
257 |
|
---|
258 | def initialize(*args)
|
---|
259 | if Utils.element_initialize_arguments?(args)
|
---|
260 | super
|
---|
261 | else
|
---|
262 | super()
|
---|
263 | self.resource = args[0]
|
---|
264 | end
|
---|
265 | end
|
---|
266 | end
|
---|
267 |
|
---|
268 | class Items < Element
|
---|
269 |
|
---|
270 | include RSS10
|
---|
271 |
|
---|
272 | Seq = ::RSS::RDF::Seq
|
---|
273 |
|
---|
274 | class << self
|
---|
275 |
|
---|
276 | def required_uri
|
---|
277 | ::RSS::URI
|
---|
278 | end
|
---|
279 |
|
---|
280 | end
|
---|
281 |
|
---|
282 | install_have_child_element("Seq", URI, nil)
|
---|
283 | install_must_call_validator('rdf', URI)
|
---|
284 |
|
---|
285 | def initialize(*args)
|
---|
286 | if Utils.element_initialize_arguments?(args)
|
---|
287 | super
|
---|
288 | else
|
---|
289 | super()
|
---|
290 | self.Seq = args[0]
|
---|
291 | end
|
---|
292 | self.Seq ||= Seq.new
|
---|
293 | end
|
---|
294 |
|
---|
295 | def resources
|
---|
296 | if @Seq
|
---|
297 | @Seq.lis.collect do |li|
|
---|
298 | li.resource
|
---|
299 | end
|
---|
300 | else
|
---|
301 | []
|
---|
302 | end
|
---|
303 | end
|
---|
304 | end
|
---|
305 | end
|
---|
306 |
|
---|
307 | class Image < Element
|
---|
308 |
|
---|
309 | include RSS10
|
---|
310 |
|
---|
311 | class << self
|
---|
312 |
|
---|
313 | def required_uri
|
---|
314 | ::RSS::URI
|
---|
315 | end
|
---|
316 |
|
---|
317 | end
|
---|
318 |
|
---|
319 | [
|
---|
320 | ["about", URI, true]
|
---|
321 | ].each do |name, uri, required|
|
---|
322 | install_get_attribute(name, uri, required, nil, nil,
|
---|
323 | "#{PREFIX}:#{name}")
|
---|
324 | end
|
---|
325 |
|
---|
326 | %w(title url link).each do |name|
|
---|
327 | install_text_element(name, ::RSS::URI, nil)
|
---|
328 | end
|
---|
329 |
|
---|
330 | def initialize(*args)
|
---|
331 | if Utils.element_initialize_arguments?(args)
|
---|
332 | super
|
---|
333 | else
|
---|
334 | super()
|
---|
335 | self.about = args[0]
|
---|
336 | end
|
---|
337 | end
|
---|
338 |
|
---|
339 | private
|
---|
340 | def maker_target(maker)
|
---|
341 | maker.image
|
---|
342 | end
|
---|
343 | end
|
---|
344 |
|
---|
345 | class Item < Element
|
---|
346 |
|
---|
347 | include RSS10
|
---|
348 |
|
---|
349 | class << self
|
---|
350 |
|
---|
351 | def required_uri
|
---|
352 | ::RSS::URI
|
---|
353 | end
|
---|
354 |
|
---|
355 | end
|
---|
356 |
|
---|
357 |
|
---|
358 | [
|
---|
359 | ["about", URI, true]
|
---|
360 | ].each do |name, uri, required|
|
---|
361 | install_get_attribute(name, uri, required, nil, nil,
|
---|
362 | "#{PREFIX}:#{name}")
|
---|
363 | end
|
---|
364 |
|
---|
365 | [
|
---|
366 | ["title", nil],
|
---|
367 | ["link", nil],
|
---|
368 | ["description", "?"],
|
---|
369 | ].each do |tag, occurs|
|
---|
370 | install_text_element(tag, ::RSS::URI, occurs)
|
---|
371 | end
|
---|
372 |
|
---|
373 | def initialize(*args)
|
---|
374 | if Utils.element_initialize_arguments?(args)
|
---|
375 | super
|
---|
376 | else
|
---|
377 | super()
|
---|
378 | self.about = args[0]
|
---|
379 | end
|
---|
380 | end
|
---|
381 |
|
---|
382 | private
|
---|
383 | def maker_target(items)
|
---|
384 | if items.respond_to?("items")
|
---|
385 | # For backward compatibility
|
---|
386 | items = items.items
|
---|
387 | end
|
---|
388 | items.new_item
|
---|
389 | end
|
---|
390 | end
|
---|
391 |
|
---|
392 | class Textinput < Element
|
---|
393 |
|
---|
394 | include RSS10
|
---|
395 |
|
---|
396 | class << self
|
---|
397 |
|
---|
398 | def required_uri
|
---|
399 | ::RSS::URI
|
---|
400 | end
|
---|
401 |
|
---|
402 | end
|
---|
403 |
|
---|
404 | [
|
---|
405 | ["about", URI, true]
|
---|
406 | ].each do |name, uri, required|
|
---|
407 | install_get_attribute(name, uri, required, nil, nil,
|
---|
408 | "#{PREFIX}:#{name}")
|
---|
409 | end
|
---|
410 |
|
---|
411 | %w(title description name link).each do |name|
|
---|
412 | install_text_element(name, ::RSS::URI, nil)
|
---|
413 | end
|
---|
414 |
|
---|
415 | def initialize(*args)
|
---|
416 | if Utils.element_initialize_arguments?(args)
|
---|
417 | super
|
---|
418 | else
|
---|
419 | super()
|
---|
420 | self.about = args[0]
|
---|
421 | end
|
---|
422 | end
|
---|
423 |
|
---|
424 | private
|
---|
425 | def maker_target(maker)
|
---|
426 | maker.textinput
|
---|
427 | end
|
---|
428 | end
|
---|
429 |
|
---|
430 | end
|
---|
431 |
|
---|
432 | RSS10::ELEMENTS.each do |name|
|
---|
433 | BaseListener.install_get_text_element(URI, name, "#{name}=")
|
---|
434 | end
|
---|
435 |
|
---|
436 | module ListenerMixin
|
---|
437 | private
|
---|
438 | def start_RDF(tag_name, prefix, attrs, ns)
|
---|
439 | check_ns(tag_name, prefix, ns, RDF::URI)
|
---|
440 |
|
---|
441 | @rss = RDF.new(@version, @encoding, @standalone)
|
---|
442 | @rss.do_validate = @do_validate
|
---|
443 | @rss.xml_stylesheets = @xml_stylesheets
|
---|
444 | @last_element = @rss
|
---|
445 | @proc_stack.push Proc.new { |text, tags|
|
---|
446 | @rss.validate_for_stream(tags, @ignore_unknown_element) if @do_validate
|
---|
447 | }
|
---|
448 | end
|
---|
449 | end
|
---|
450 |
|
---|
451 | end
|
---|