2004-01-28 10:19:56 -05:00
|
|
|
require "rss/parser"
|
2004-01-27 22:46:13 -05:00
|
|
|
|
|
|
|
module RSS
|
|
|
|
|
2004-10-16 00:51:15 -04:00
|
|
|
module RSS09
|
|
|
|
NSPOOL = {}
|
|
|
|
ELEMENTS = []
|
|
|
|
|
|
|
|
def self.append_features(klass)
|
|
|
|
super
|
2009-03-05 22:56:38 -05:00
|
|
|
|
2007-03-17 06:13:25 -04:00
|
|
|
klass.install_must_call_validator('', "")
|
2004-10-16 00:51:15 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
class Rss < Element
|
|
|
|
|
|
|
|
include RSS09
|
|
|
|
include RootElementMixin
|
|
|
|
|
2005-04-05 03:03:43 -04:00
|
|
|
%w(channel).each do |name|
|
2007-03-17 06:13:25 -04:00
|
|
|
install_have_child_element(name, "", nil)
|
2004-10-16 00:51:15 -04:00
|
|
|
end
|
|
|
|
|
2007-03-17 06:13:25 -04:00
|
|
|
attr_writer :feed_version
|
|
|
|
alias_method(:rss_version, :feed_version)
|
|
|
|
alias_method(:rss_version=, :feed_version=)
|
|
|
|
|
|
|
|
def initialize(feed_version, version=nil, encoding=nil, standalone=nil)
|
2004-10-16 00:51:15 -04:00
|
|
|
super
|
2007-03-17 06:13:25 -04:00
|
|
|
@feed_type = "rss"
|
2004-10-16 00:51:15 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def items
|
|
|
|
if @channel
|
|
|
|
@channel.items
|
|
|
|
else
|
|
|
|
[]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def image
|
|
|
|
if @channel
|
|
|
|
@channel.image
|
|
|
|
else
|
|
|
|
nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2004-11-03 01:43:18 -05:00
|
|
|
def textinput
|
|
|
|
if @channel
|
|
|
|
@channel.textInput
|
|
|
|
else
|
|
|
|
nil
|
|
|
|
end
|
|
|
|
end
|
2004-10-16 00:51:15 -04:00
|
|
|
|
2007-03-17 06:13:25 -04:00
|
|
|
def setup_maker_elements(maker)
|
|
|
|
super
|
|
|
|
items.each do |item|
|
|
|
|
item.setup_maker(maker.items)
|
2005-04-05 03:03:43 -04:00
|
|
|
end
|
2007-03-17 06:13:25 -04:00
|
|
|
image.setup_maker(maker) if image
|
|
|
|
textinput.setup_maker(maker) if textinput
|
2004-10-16 00:51:15 -04:00
|
|
|
end
|
|
|
|
|
2007-03-17 06:13:25 -04:00
|
|
|
private
|
2004-10-16 00:51:15 -04:00
|
|
|
def _attrs
|
|
|
|
[
|
2007-03-17 06:13:25 -04:00
|
|
|
["version", true, "feed_version"],
|
2004-10-16 00:51:15 -04:00
|
|
|
]
|
|
|
|
end
|
|
|
|
|
|
|
|
class Channel < Element
|
|
|
|
|
|
|
|
include RSS09
|
|
|
|
|
|
|
|
[
|
2007-03-17 06:13:25 -04:00
|
|
|
["title", nil, :text],
|
|
|
|
["link", nil, :text],
|
|
|
|
["description", nil, :text],
|
|
|
|
["language", nil, :text],
|
|
|
|
["copyright", "?", :text],
|
|
|
|
["managingEditor", "?", :text],
|
|
|
|
["webMaster", "?", :text],
|
|
|
|
["rating", "?", :text],
|
|
|
|
["pubDate", "?", :date, :rfc822],
|
|
|
|
["lastBuildDate", "?", :date, :rfc822],
|
|
|
|
["docs", "?", :text],
|
|
|
|
["cloud", "?", :have_attribute],
|
|
|
|
["skipDays", "?", :have_child],
|
|
|
|
["skipHours", "?", :have_child],
|
|
|
|
["image", nil, :have_child],
|
|
|
|
["item", "*", :have_children],
|
|
|
|
["textInput", "?", :have_child],
|
|
|
|
].each do |name, occurs, type, *args|
|
|
|
|
__send__("install_#{type}_element", name, "", occurs, name, *args)
|
2004-10-16 00:51:15 -04:00
|
|
|
end
|
2005-02-13 09:21:21 -05:00
|
|
|
alias date pubDate
|
|
|
|
alias date= pubDate=
|
2004-10-16 00:51:15 -04:00
|
|
|
|
|
|
|
private
|
2004-11-27 03:47:28 -05:00
|
|
|
def maker_target(maker)
|
|
|
|
maker.channel
|
|
|
|
end
|
|
|
|
|
|
|
|
def setup_maker_elements(channel)
|
|
|
|
super
|
|
|
|
[
|
|
|
|
[skipDays, "day"],
|
|
|
|
[skipHours, "hour"],
|
|
|
|
].each do |skip, key|
|
|
|
|
if skip
|
|
|
|
skip.__send__("#{key}s").each do |val|
|
|
|
|
target_skips = channel.__send__("skip#{key.capitalize}s")
|
|
|
|
new_target = target_skips.__send__("new_#{key}")
|
|
|
|
new_target.content = val.content
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2005-02-03 10:31:57 -05:00
|
|
|
def not_need_to_call_setup_maker_variables
|
|
|
|
%w(image textInput)
|
|
|
|
end
|
2009-03-05 22:56:38 -05:00
|
|
|
|
2004-11-19 03:25:25 -05:00
|
|
|
class SkipDays < Element
|
|
|
|
include RSS09
|
|
|
|
|
|
|
|
[
|
|
|
|
["day", "*"]
|
2005-04-05 03:03:43 -04:00
|
|
|
].each do |name, occurs|
|
2007-03-17 06:13:25 -04:00
|
|
|
install_have_children_element(name, "", occurs)
|
2004-11-19 03:25:25 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
class Day < Element
|
|
|
|
include RSS09
|
|
|
|
|
|
|
|
content_setup
|
|
|
|
|
2007-03-17 06:13:25 -04:00
|
|
|
def initialize(*args)
|
|
|
|
if Utils.element_initialize_arguments?(args)
|
|
|
|
super
|
|
|
|
else
|
|
|
|
super()
|
|
|
|
self.content = args[0]
|
|
|
|
end
|
2004-11-19 03:25:25 -05:00
|
|
|
end
|
2009-03-05 22:56:38 -05:00
|
|
|
|
2004-11-19 03:25:25 -05:00
|
|
|
end
|
2009-03-05 22:56:38 -05:00
|
|
|
|
2004-11-19 03:25:25 -05:00
|
|
|
end
|
2009-03-05 22:56:38 -05:00
|
|
|
|
2004-11-19 03:25:25 -05:00
|
|
|
class SkipHours < Element
|
|
|
|
include RSS09
|
|
|
|
|
|
|
|
[
|
|
|
|
["hour", "*"]
|
2005-04-05 03:03:43 -04:00
|
|
|
].each do |name, occurs|
|
2007-03-17 06:13:25 -04:00
|
|
|
install_have_children_element(name, "", occurs)
|
2004-11-19 03:25:25 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
class Hour < Element
|
|
|
|
include RSS09
|
|
|
|
|
2005-11-24 22:43:48 -05:00
|
|
|
content_setup(:integer)
|
2004-11-19 03:25:25 -05:00
|
|
|
|
2007-03-17 06:13:25 -04:00
|
|
|
def initialize(*args)
|
|
|
|
if Utils.element_initialize_arguments?(args)
|
|
|
|
super
|
|
|
|
else
|
|
|
|
super()
|
|
|
|
self.content = args[0]
|
|
|
|
end
|
2004-11-19 03:25:25 -05:00
|
|
|
end
|
|
|
|
end
|
2009-03-05 22:56:38 -05:00
|
|
|
|
2004-11-19 03:25:25 -05:00
|
|
|
end
|
2009-03-05 22:56:38 -05:00
|
|
|
|
2004-10-16 00:51:15 -04:00
|
|
|
class Image < Element
|
|
|
|
|
|
|
|
include RSS09
|
2009-03-05 22:56:38 -05:00
|
|
|
|
2005-04-05 03:03:43 -04:00
|
|
|
%w(url title link).each do |name|
|
2007-03-17 06:13:25 -04:00
|
|
|
install_text_element(name, "", nil)
|
2004-10-16 00:51:15 -04:00
|
|
|
end
|
2005-11-24 22:43:48 -05:00
|
|
|
[
|
|
|
|
["width", :integer],
|
|
|
|
["height", :integer],
|
|
|
|
["description"],
|
|
|
|
].each do |name, type|
|
2007-03-17 06:13:25 -04:00
|
|
|
install_text_element(name, "", "?", name, type)
|
2005-11-24 20:33:50 -05:00
|
|
|
end
|
|
|
|
|
2007-03-17 06:13:25 -04:00
|
|
|
def initialize(*args)
|
|
|
|
if Utils.element_initialize_arguments?(args)
|
|
|
|
super
|
|
|
|
else
|
|
|
|
super()
|
|
|
|
self.url = args[0]
|
|
|
|
self.title = args[1]
|
|
|
|
self.link = args[2]
|
|
|
|
self.width = args[3]
|
|
|
|
self.height = args[4]
|
|
|
|
self.description = args[5]
|
2004-11-19 03:25:25 -05:00
|
|
|
end
|
2004-10-16 00:51:15 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
2004-11-27 03:47:28 -05:00
|
|
|
def maker_target(maker)
|
|
|
|
maker.image
|
|
|
|
end
|
2004-10-16 00:51:15 -04:00
|
|
|
end
|
2004-11-19 03:25:25 -05:00
|
|
|
|
2004-10-16 00:51:15 -04:00
|
|
|
class Cloud < Element
|
|
|
|
|
|
|
|
include RSS09
|
2007-03-17 06:13:25 -04:00
|
|
|
|
2004-10-16 00:51:15 -04:00
|
|
|
[
|
2007-03-17 06:13:25 -04:00
|
|
|
["domain", "", true],
|
|
|
|
["port", "", true, :integer],
|
|
|
|
["path", "", true],
|
|
|
|
["registerProcedure", "", true],
|
|
|
|
["protocol", "", true],
|
2005-11-24 22:43:48 -05:00
|
|
|
].each do |name, uri, required, type|
|
|
|
|
install_get_attribute(name, uri, required, type)
|
2004-10-16 00:51:15 -04:00
|
|
|
end
|
|
|
|
|
2007-03-17 06:13:25 -04:00
|
|
|
def initialize(*args)
|
|
|
|
if Utils.element_initialize_arguments?(args)
|
|
|
|
super
|
|
|
|
else
|
|
|
|
super()
|
|
|
|
self.domain = args[0]
|
|
|
|
self.port = args[1]
|
|
|
|
self.path = args[2]
|
|
|
|
self.registerProcedure = args[3]
|
|
|
|
self.protocol = args[4]
|
2004-10-16 00:51:15 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2009-03-05 22:56:38 -05:00
|
|
|
|
2004-10-16 00:51:15 -04:00
|
|
|
class Item < Element
|
2009-03-05 22:56:38 -05:00
|
|
|
|
2004-10-16 00:51:15 -04:00
|
|
|
include RSS09
|
|
|
|
|
2004-11-19 03:25:25 -05:00
|
|
|
[
|
2007-03-17 06:13:25 -04:00
|
|
|
["title", '?', :text],
|
|
|
|
["link", '?', :text],
|
|
|
|
["description", '?', :text],
|
|
|
|
["category", '*', :have_children, "categories"],
|
|
|
|
["source", '?', :have_child],
|
|
|
|
["enclosure", '?', :have_child],
|
|
|
|
].each do |tag, occurs, type, *args|
|
|
|
|
__send__("install_#{type}_element", tag, "", occurs, tag, *args)
|
2004-10-16 00:51:15 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
2005-11-23 04:24:17 -05:00
|
|
|
def maker_target(items)
|
|
|
|
if items.respond_to?("items")
|
|
|
|
# For backward compatibility
|
|
|
|
items = items.items
|
|
|
|
end
|
|
|
|
items.new_item
|
2004-11-27 03:47:28 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def setup_maker_element(item)
|
|
|
|
super
|
|
|
|
@enclosure.setup_maker(item) if @enclosure
|
|
|
|
@source.setup_maker(item) if @source
|
|
|
|
end
|
2009-03-05 22:56:38 -05:00
|
|
|
|
2004-10-16 00:51:15 -04:00
|
|
|
class Source < Element
|
|
|
|
|
|
|
|
include RSS09
|
|
|
|
|
|
|
|
[
|
2007-03-17 06:13:25 -04:00
|
|
|
["url", "", true]
|
2004-10-16 00:51:15 -04:00
|
|
|
].each do |name, uri, required|
|
|
|
|
install_get_attribute(name, uri, required)
|
|
|
|
end
|
2009-03-05 22:56:38 -05:00
|
|
|
|
2004-10-16 00:51:15 -04:00
|
|
|
content_setup
|
|
|
|
|
2007-03-17 06:13:25 -04:00
|
|
|
def initialize(*args)
|
|
|
|
if Utils.element_initialize_arguments?(args)
|
|
|
|
super
|
|
|
|
else
|
|
|
|
super()
|
|
|
|
self.url = args[0]
|
|
|
|
self.content = args[1]
|
|
|
|
end
|
2004-10-16 00:51:15 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
2004-11-27 03:47:28 -05:00
|
|
|
def maker_target(item)
|
|
|
|
item.source
|
|
|
|
end
|
|
|
|
|
|
|
|
def setup_maker_attributes(source)
|
|
|
|
source.url = url
|
|
|
|
source.content = content
|
|
|
|
end
|
2004-10-16 00:51:15 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
class Enclosure < Element
|
|
|
|
|
|
|
|
include RSS09
|
|
|
|
|
|
|
|
[
|
2007-03-17 06:13:25 -04:00
|
|
|
["url", "", true],
|
|
|
|
["length", "", true, :integer],
|
|
|
|
["type", "", true],
|
2005-11-24 22:43:48 -05:00
|
|
|
].each do |name, uri, required, type|
|
|
|
|
install_get_attribute(name, uri, required, type)
|
2004-10-16 00:51:15 -04:00
|
|
|
end
|
|
|
|
|
2007-03-17 06:13:25 -04:00
|
|
|
def initialize(*args)
|
|
|
|
if Utils.element_initialize_arguments?(args)
|
|
|
|
super
|
|
|
|
else
|
|
|
|
super()
|
|
|
|
self.url = args[0]
|
|
|
|
self.length = args[1]
|
|
|
|
self.type = args[2]
|
|
|
|
end
|
2004-10-16 00:51:15 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
2004-11-27 03:47:28 -05:00
|
|
|
def maker_target(item)
|
|
|
|
item.enclosure
|
|
|
|
end
|
|
|
|
|
|
|
|
def setup_maker_attributes(enclosure)
|
|
|
|
enclosure.url = url
|
|
|
|
enclosure.length = length
|
|
|
|
enclosure.type = type
|
|
|
|
end
|
2004-10-16 00:51:15 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
class Category < Element
|
|
|
|
|
|
|
|
include RSS09
|
2009-03-05 22:56:38 -05:00
|
|
|
|
2004-10-16 00:51:15 -04:00
|
|
|
[
|
2007-03-17 06:13:25 -04:00
|
|
|
["domain", "", false]
|
2004-10-16 00:51:15 -04:00
|
|
|
].each do |name, uri, required|
|
|
|
|
install_get_attribute(name, uri, required)
|
|
|
|
end
|
|
|
|
|
|
|
|
content_setup
|
|
|
|
|
2007-03-17 06:13:25 -04:00
|
|
|
def initialize(*args)
|
|
|
|
if Utils.element_initialize_arguments?(args)
|
|
|
|
super
|
|
|
|
else
|
|
|
|
super()
|
|
|
|
self.domain = args[0]
|
|
|
|
self.content = args[1]
|
|
|
|
end
|
2004-10-16 00:51:15 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
2004-11-27 03:47:28 -05:00
|
|
|
def maker_target(item)
|
|
|
|
item.new_category
|
|
|
|
end
|
|
|
|
|
|
|
|
def setup_maker_attributes(category)
|
|
|
|
category.domain = domain
|
|
|
|
category.content = content
|
|
|
|
end
|
2009-03-05 22:56:38 -05:00
|
|
|
|
2004-10-16 00:51:15 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|
2009-03-05 22:56:38 -05:00
|
|
|
|
2004-10-16 00:51:15 -04:00
|
|
|
class TextInput < Element
|
2004-11-19 03:25:25 -05:00
|
|
|
|
2004-10-16 00:51:15 -04:00
|
|
|
include RSS09
|
|
|
|
|
2005-04-05 03:03:43 -04:00
|
|
|
%w(title description name link).each do |name|
|
2007-03-17 06:13:25 -04:00
|
|
|
install_text_element(name, "", nil)
|
2004-10-16 00:51:15 -04:00
|
|
|
end
|
|
|
|
|
2007-03-17 06:13:25 -04:00
|
|
|
def initialize(*args)
|
|
|
|
if Utils.element_initialize_arguments?(args)
|
|
|
|
super
|
|
|
|
else
|
|
|
|
super()
|
|
|
|
self.title = args[0]
|
|
|
|
self.description = args[1]
|
|
|
|
self.name = args[2]
|
|
|
|
self.link = args[3]
|
2004-11-19 03:25:25 -05:00
|
|
|
end
|
2004-10-16 00:51:15 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
2004-11-27 03:47:28 -05:00
|
|
|
def maker_target(maker)
|
|
|
|
maker.textinput
|
|
|
|
end
|
2004-10-16 00:51:15 -04:00
|
|
|
end
|
2009-03-05 22:56:38 -05:00
|
|
|
|
2004-10-16 00:51:15 -04:00
|
|
|
end
|
2009-03-05 22:56:38 -05:00
|
|
|
|
2004-10-16 00:51:15 -04:00
|
|
|
end
|
|
|
|
|
2005-04-05 03:03:43 -04:00
|
|
|
RSS09::ELEMENTS.each do |name|
|
2007-03-17 06:13:25 -04:00
|
|
|
BaseListener.install_get_text_element("", name, name)
|
2004-10-16 00:51:15 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
module ListenerMixin
|
|
|
|
private
|
2007-03-17 06:13:25 -04:00
|
|
|
def initial_start_rss(tag_name, prefix, attrs, ns)
|
|
|
|
check_ns(tag_name, prefix, ns, "")
|
2009-03-05 22:56:38 -05:00
|
|
|
|
2004-10-16 00:51:15 -04:00
|
|
|
@rss = Rss.new(attrs['version'], @version, @encoding, @standalone)
|
|
|
|
@rss.do_validate = @do_validate
|
|
|
|
@rss.xml_stylesheets = @xml_stylesheets
|
|
|
|
@last_element = @rss
|
2007-03-17 06:13:25 -04:00
|
|
|
pr = Proc.new do |text, tags|
|
|
|
|
@rss.validate_for_stream(tags, @ignore_unknown_element) if @do_validate
|
|
|
|
end
|
|
|
|
@proc_stack.push(pr)
|
2004-10-16 00:51:15 -04:00
|
|
|
end
|
2009-03-05 22:56:38 -05:00
|
|
|
|
2004-10-16 00:51:15 -04:00
|
|
|
end
|
2004-01-27 22:46:13 -05:00
|
|
|
|
|
|
|
end
|