2004-01-28 18:19:56 +03:00
|
|
|
require "rss/parser"
|
2004-01-28 06:46:13 +03:00
|
|
|
|
|
|
|
module RSS
|
|
|
|
|
2004-10-16 08:51:15 +04:00
|
|
|
module RSS10
|
|
|
|
NSPOOL = {}
|
|
|
|
ELEMENTS = []
|
2004-07-06 21:43:05 +04:00
|
|
|
|
2004-10-16 08:51:15 +04:00
|
|
|
def self.append_features(klass)
|
|
|
|
super
|
2009-03-06 06:56:38 +03:00
|
|
|
|
2004-10-16 08:51:15 +04:00
|
|
|
klass.install_must_call_validator('', ::RSS::URI)
|
|
|
|
end
|
2004-07-06 21:43:05 +04:00
|
|
|
|
2004-10-16 08:51:15 +04:00
|
|
|
end
|
2004-01-28 06:46:13 +03:00
|
|
|
|
2004-10-16 08:51:15 +04:00
|
|
|
class RDF < Element
|
2004-01-28 06:46:13 +03:00
|
|
|
|
2004-10-16 08:51:15 +04:00
|
|
|
include RSS10
|
|
|
|
include RootElementMixin
|
2004-01-28 06:46:13 +03:00
|
|
|
|
2004-10-16 08:51:15 +04:00
|
|
|
class << self
|
2004-01-28 06:46:13 +03:00
|
|
|
|
2004-10-16 08:51:15 +04:00
|
|
|
def required_uri
|
|
|
|
URI
|
|
|
|
end
|
2004-01-28 06:46:13 +03:00
|
|
|
|
2004-10-16 08:51:15 +04:00
|
|
|
end
|
2004-01-28 06:46:13 +03:00
|
|
|
|
2004-10-16 08:51:15 +04:00
|
|
|
@tag_name = 'RDF'
|
2004-01-28 06:46:13 +03:00
|
|
|
|
2004-10-16 08:51:15 +04:00
|
|
|
PREFIX = 'rdf'
|
|
|
|
URI = "http://www.w3.org/1999/02/22-rdf-syntax-ns#"
|
2004-01-28 06:46:13 +03:00
|
|
|
|
2004-10-16 08:51:15 +04:00
|
|
|
install_ns('', ::RSS::URI)
|
|
|
|
install_ns(PREFIX, URI)
|
2004-01-28 06:46:13 +03:00
|
|
|
|
2004-10-16 08:51:15 +04:00
|
|
|
[
|
|
|
|
["channel", nil],
|
|
|
|
["image", "?"],
|
2007-03-17 13:13:25 +03:00
|
|
|
["item", "+", :children],
|
2004-10-16 08:51:15 +04:00
|
|
|
["textinput", "?"],
|
2007-03-17 13:13:25 +03:00
|
|
|
].each do |tag, occurs, type|
|
|
|
|
type ||= :child
|
|
|
|
__send__("install_have_#{type}_element", tag, ::RSS::URI, occurs)
|
2004-10-16 08:51:15 +04:00
|
|
|
end
|
2004-01-28 06:46:13 +03:00
|
|
|
|
2007-03-17 13:13:25 +03:00
|
|
|
alias_method(:rss_version, :feed_version)
|
2004-10-16 08:51:15 +04:00
|
|
|
def initialize(version=nil, encoding=nil, standalone=nil)
|
|
|
|
super('1.0', version, encoding, standalone)
|
2007-03-17 13:13:25 +03:00
|
|
|
@feed_type = "rss"
|
2004-10-16 08:51:15 +04:00
|
|
|
end
|
2004-01-28 06:46:13 +03:00
|
|
|
|
2004-11-19 11:25:25 +03:00
|
|
|
def full_name
|
|
|
|
tag_name_with_prefix(PREFIX)
|
|
|
|
end
|
2004-10-16 08:51:15 +04:00
|
|
|
|
2005-11-17 11:42:13 +03:00
|
|
|
class Li < Element
|
|
|
|
|
|
|
|
include RSS10
|
|
|
|
|
|
|
|
class << self
|
|
|
|
def required_uri
|
|
|
|
URI
|
|
|
|
end
|
|
|
|
end
|
2009-03-06 06:56:38 +03:00
|
|
|
|
2005-11-17 11:42:13 +03:00
|
|
|
[
|
2007-03-17 13:13:25 +03:00
|
|
|
["resource", [URI, ""], true]
|
2005-11-17 11:42:13 +03:00
|
|
|
].each do |name, uri, required|
|
|
|
|
install_get_attribute(name, uri, required)
|
|
|
|
end
|
2009-03-06 06:56:38 +03:00
|
|
|
|
2007-03-17 13:13:25 +03:00
|
|
|
def initialize(*args)
|
|
|
|
if Utils.element_initialize_arguments?(args)
|
|
|
|
super
|
|
|
|
else
|
|
|
|
super()
|
|
|
|
self.resource = args[0]
|
|
|
|
end
|
2005-11-17 11:42:13 +03:00
|
|
|
end
|
|
|
|
|
|
|
|
def full_name
|
|
|
|
tag_name_with_prefix(PREFIX)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2004-10-16 08:51:15 +04:00
|
|
|
class Seq < Element
|
|
|
|
|
|
|
|
include RSS10
|
|
|
|
|
2005-11-17 11:42:13 +03:00
|
|
|
Li = ::RSS::RDF::Li
|
|
|
|
|
2004-10-16 08:51:15 +04:00
|
|
|
class << self
|
|
|
|
def required_uri
|
|
|
|
URI
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
@tag_name = 'Seq'
|
2009-03-06 06:56:38 +03:00
|
|
|
|
2007-03-17 13:13:25 +03:00
|
|
|
install_have_children_element("li", URI, "*")
|
2004-10-16 08:51:15 +04:00
|
|
|
install_must_call_validator('rdf', ::RSS::RDF::URI)
|
2009-03-06 06:56:38 +03:00
|
|
|
|
2007-03-17 13:13:25 +03:00
|
|
|
def initialize(*args)
|
|
|
|
if Utils.element_initialize_arguments?(args)
|
|
|
|
super
|
|
|
|
else
|
|
|
|
super()
|
|
|
|
@li = args[0] if args[0]
|
2004-11-19 11:25:25 +03:00
|
|
|
end
|
2004-10-16 08:51:15 +04:00
|
|
|
end
|
2004-01-28 06:46:13 +03:00
|
|
|
|
2004-11-19 11:25:25 +03:00
|
|
|
def full_name
|
|
|
|
tag_name_with_prefix(PREFIX)
|
|
|
|
end
|
2009-03-06 06:56:38 +03:00
|
|
|
|
2005-11-23 12:24:17 +03:00
|
|
|
def setup_maker(target)
|
|
|
|
lis.each do |li|
|
|
|
|
target << li.resource
|
|
|
|
end
|
|
|
|
end
|
2004-10-16 08:51:15 +04:00
|
|
|
end
|
|
|
|
|
2005-11-17 11:42:13 +03:00
|
|
|
class Bag < Element
|
2004-10-16 08:51:15 +04:00
|
|
|
|
|
|
|
include RSS10
|
|
|
|
|
2005-11-17 11:42:13 +03:00
|
|
|
Li = ::RSS::RDF::Li
|
|
|
|
|
2004-10-16 08:51:15 +04:00
|
|
|
class << self
|
|
|
|
def required_uri
|
|
|
|
URI
|
|
|
|
end
|
|
|
|
end
|
2005-11-17 11:42:13 +03:00
|
|
|
|
|
|
|
@tag_name = 'Bag'
|
2009-03-06 06:56:38 +03:00
|
|
|
|
2007-03-17 13:13:25 +03:00
|
|
|
install_have_children_element("li", URI, "*")
|
|
|
|
install_must_call_validator('rdf', URI)
|
2009-03-06 06:56:38 +03:00
|
|
|
|
2007-03-17 13:13:25 +03:00
|
|
|
def initialize(*args)
|
|
|
|
if Utils.element_initialize_arguments?(args)
|
|
|
|
super
|
|
|
|
else
|
|
|
|
super()
|
|
|
|
@li = args[0] if args[0]
|
2005-11-17 11:42:13 +03:00
|
|
|
end
|
2004-10-16 08:51:15 +04:00
|
|
|
end
|
2004-11-19 11:25:25 +03:00
|
|
|
|
|
|
|
def full_name
|
|
|
|
tag_name_with_prefix(PREFIX)
|
|
|
|
end
|
2009-03-06 06:56:38 +03:00
|
|
|
|
2005-11-23 12:24:17 +03:00
|
|
|
def setup_maker(target)
|
|
|
|
lis.each do |li|
|
|
|
|
target << li.resource
|
|
|
|
end
|
|
|
|
end
|
2004-10-16 08:51:15 +04:00
|
|
|
end
|
|
|
|
|
|
|
|
class Channel < Element
|
|
|
|
|
|
|
|
include RSS10
|
2009-03-06 06:56:38 +03:00
|
|
|
|
2004-10-16 08:51:15 +04:00
|
|
|
class << self
|
|
|
|
|
|
|
|
def required_uri
|
|
|
|
::RSS::URI
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
2004-01-28 06:46:13 +03:00
|
|
|
|
2005-02-02 16:00:31 +03:00
|
|
|
[
|
2004-10-16 08:51:15 +04:00
|
|
|
["about", URI, true]
|
|
|
|
].each do |name, uri, required|
|
2007-03-17 13:13:25 +03:00
|
|
|
install_get_attribute(name, uri, required, nil, nil,
|
|
|
|
"#{PREFIX}:#{name}")
|
2004-10-16 08:51:15 +04:00
|
|
|
end
|
|
|
|
|
|
|
|
[
|
2007-03-17 13:13:25 +03:00
|
|
|
['title', nil, :text],
|
|
|
|
['link', nil, :text],
|
|
|
|
['description', nil, :text],
|
|
|
|
['image', '?', :have_child],
|
|
|
|
['items', nil, :have_child],
|
|
|
|
['textinput', '?', :have_child],
|
|
|
|
].each do |tag, occurs, type|
|
|
|
|
__send__("install_#{type}_element", tag, ::RSS::URI, occurs)
|
|
|
|
end
|
|
|
|
|
|
|
|
def initialize(*args)
|
|
|
|
if Utils.element_initialize_arguments?(args)
|
|
|
|
super
|
|
|
|
else
|
|
|
|
super()
|
|
|
|
self.about = args[0]
|
2004-11-19 11:25:25 +03:00
|
|
|
end
|
2004-10-16 08:51:15 +04:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
2004-11-27 11:47:28 +03:00
|
|
|
def maker_target(maker)
|
|
|
|
maker.channel
|
|
|
|
end
|
2009-03-06 06:56:38 +03:00
|
|
|
|
2004-11-27 11:47:28 +03:00
|
|
|
def setup_maker_attributes(channel)
|
2005-08-11 08:08:05 +04:00
|
|
|
channel.about = about
|
2004-11-27 11:47:28 +03:00
|
|
|
end
|
|
|
|
|
2004-10-16 08:51:15 +04:00
|
|
|
class Image < Element
|
2009-03-06 06:56:38 +03:00
|
|
|
|
2004-10-16 08:51:15 +04:00
|
|
|
include RSS10
|
|
|
|
|
|
|
|
class << self
|
2009-03-06 06:56:38 +03:00
|
|
|
|
2004-10-16 08:51:15 +04:00
|
|
|
def required_uri
|
|
|
|
::RSS::URI
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
[
|
|
|
|
["resource", URI, true]
|
|
|
|
].each do |name, uri, required|
|
2007-03-17 13:13:25 +03:00
|
|
|
install_get_attribute(name, uri, required, nil, nil,
|
|
|
|
"#{PREFIX}:#{name}")
|
2004-10-16 08:51:15 +04:00
|
|
|
end
|
2009-03-06 06:56:38 +03:00
|
|
|
|
2007-03-17 13:13:25 +03:00
|
|
|
def initialize(*args)
|
|
|
|
if Utils.element_initialize_arguments?(args)
|
|
|
|
super
|
|
|
|
else
|
|
|
|
super()
|
|
|
|
self.resource = args[0]
|
|
|
|
end
|
2004-10-16 08:51:15 +04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
class Textinput < Element
|
2009-03-06 06:56:38 +03:00
|
|
|
|
2004-10-16 08:51:15 +04:00
|
|
|
include RSS10
|
|
|
|
|
|
|
|
class << self
|
2009-03-06 06:56:38 +03:00
|
|
|
|
2004-10-16 08:51:15 +04:00
|
|
|
def required_uri
|
|
|
|
::RSS::URI
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
[
|
|
|
|
["resource", URI, true]
|
|
|
|
].each do |name, uri, required|
|
2007-03-17 13:13:25 +03:00
|
|
|
install_get_attribute(name, uri, required, nil, nil,
|
|
|
|
"#{PREFIX}:#{name}")
|
2004-10-16 08:51:15 +04:00
|
|
|
end
|
2009-03-06 06:56:38 +03:00
|
|
|
|
2007-03-17 13:13:25 +03:00
|
|
|
def initialize(*args)
|
|
|
|
if Utils.element_initialize_arguments?(args)
|
|
|
|
super
|
|
|
|
else
|
|
|
|
super()
|
|
|
|
self.resource = args[0]
|
|
|
|
end
|
2004-10-16 08:51:15 +04:00
|
|
|
end
|
|
|
|
end
|
2009-03-06 06:56:38 +03:00
|
|
|
|
2004-10-16 08:51:15 +04:00
|
|
|
class Items < Element
|
|
|
|
|
|
|
|
include RSS10
|
|
|
|
|
|
|
|
Seq = ::RSS::RDF::Seq
|
|
|
|
|
|
|
|
class << self
|
2009-03-06 06:56:38 +03:00
|
|
|
|
2004-10-16 08:51:15 +04:00
|
|
|
def required_uri
|
|
|
|
::RSS::URI
|
|
|
|
end
|
2009-03-06 06:56:38 +03:00
|
|
|
|
2004-10-16 08:51:15 +04:00
|
|
|
end
|
|
|
|
|
2007-03-17 13:13:25 +03:00
|
|
|
install_have_child_element("Seq", URI, nil)
|
|
|
|
install_must_call_validator('rdf', URI)
|
2009-03-06 06:56:38 +03:00
|
|
|
|
2007-03-17 13:13:25 +03:00
|
|
|
def initialize(*args)
|
|
|
|
if Utils.element_initialize_arguments?(args)
|
|
|
|
super
|
|
|
|
else
|
|
|
|
super()
|
|
|
|
self.Seq = args[0]
|
2004-11-19 11:25:25 +03:00
|
|
|
end
|
2007-03-17 13:13:25 +03:00
|
|
|
self.Seq ||= Seq.new
|
2004-10-16 08:51:15 +04:00
|
|
|
end
|
|
|
|
|
2005-11-17 12:01:22 +03:00
|
|
|
def resources
|
|
|
|
if @Seq
|
|
|
|
@Seq.lis.collect do |li|
|
|
|
|
li.resource
|
|
|
|
end
|
|
|
|
else
|
|
|
|
[]
|
|
|
|
end
|
|
|
|
end
|
2004-10-16 08:51:15 +04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
class Image < Element
|
|
|
|
|
|
|
|
include RSS10
|
|
|
|
|
|
|
|
class << self
|
2009-03-06 06:56:38 +03:00
|
|
|
|
2004-10-16 08:51:15 +04:00
|
|
|
def required_uri
|
|
|
|
::RSS::URI
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
2007-03-17 13:13:25 +03:00
|
|
|
|
2004-10-16 08:51:15 +04:00
|
|
|
[
|
|
|
|
["about", URI, true]
|
|
|
|
].each do |name, uri, required|
|
2007-03-17 13:13:25 +03:00
|
|
|
install_get_attribute(name, uri, required, nil, nil,
|
|
|
|
"#{PREFIX}:#{name}")
|
2004-10-16 08:51:15 +04:00
|
|
|
end
|
|
|
|
|
2005-04-05 11:03:43 +04:00
|
|
|
%w(title url link).each do |name|
|
2007-03-17 13:13:25 +03:00
|
|
|
install_text_element(name, ::RSS::URI, nil)
|
2004-10-16 08:51:15 +04:00
|
|
|
end
|
|
|
|
|
2007-03-17 13:13:25 +03:00
|
|
|
def initialize(*args)
|
|
|
|
if Utils.element_initialize_arguments?(args)
|
|
|
|
super
|
|
|
|
else
|
|
|
|
super()
|
|
|
|
self.about = args[0]
|
2004-11-19 11:25:25 +03:00
|
|
|
end
|
2004-10-16 08:51:15 +04:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
2004-11-27 11:47:28 +03:00
|
|
|
def maker_target(maker)
|
|
|
|
maker.image
|
|
|
|
end
|
2004-10-16 08:51:15 +04:00
|
|
|
end
|
|
|
|
|
|
|
|
class Item < Element
|
|
|
|
|
|
|
|
include RSS10
|
|
|
|
|
|
|
|
class << self
|
|
|
|
|
|
|
|
def required_uri
|
|
|
|
::RSS::URI
|
|
|
|
end
|
2009-03-06 06:56:38 +03:00
|
|
|
|
2004-10-16 08:51:15 +04:00
|
|
|
end
|
|
|
|
|
2007-03-17 13:13:25 +03:00
|
|
|
|
2004-10-16 08:51:15 +04:00
|
|
|
[
|
|
|
|
["about", URI, true]
|
|
|
|
].each do |name, uri, required|
|
2007-03-17 13:13:25 +03:00
|
|
|
install_get_attribute(name, uri, required, nil, nil,
|
|
|
|
"#{PREFIX}:#{name}")
|
2004-10-16 08:51:15 +04:00
|
|
|
end
|
|
|
|
|
|
|
|
[
|
|
|
|
["title", nil],
|
|
|
|
["link", nil],
|
|
|
|
["description", "?"],
|
|
|
|
].each do |tag, occurs|
|
2007-03-17 13:13:25 +03:00
|
|
|
install_text_element(tag, ::RSS::URI, occurs)
|
2004-10-16 08:51:15 +04:00
|
|
|
end
|
|
|
|
|
2007-03-17 13:13:25 +03:00
|
|
|
def initialize(*args)
|
|
|
|
if Utils.element_initialize_arguments?(args)
|
|
|
|
super
|
|
|
|
else
|
|
|
|
super()
|
|
|
|
self.about = args[0]
|
2004-10-16 08:51:15 +04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2007-03-17 13:13:25 +03:00
|
|
|
private
|
2005-11-23 12:24:17 +03:00
|
|
|
def maker_target(items)
|
|
|
|
if items.respond_to?("items")
|
|
|
|
# For backward compatibility
|
|
|
|
items = items.items
|
|
|
|
end
|
|
|
|
items.new_item
|
2004-11-27 11:47:28 +03:00
|
|
|
end
|
2004-10-16 08:51:15 +04:00
|
|
|
end
|
|
|
|
|
|
|
|
class Textinput < Element
|
|
|
|
|
|
|
|
include RSS10
|
|
|
|
|
|
|
|
class << self
|
|
|
|
|
|
|
|
def required_uri
|
|
|
|
::RSS::URI
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
[
|
|
|
|
["about", URI, true]
|
|
|
|
].each do |name, uri, required|
|
2007-03-17 13:13:25 +03:00
|
|
|
install_get_attribute(name, uri, required, nil, nil,
|
|
|
|
"#{PREFIX}:#{name}")
|
2004-10-16 08:51:15 +04:00
|
|
|
end
|
|
|
|
|
2005-04-05 11:03:43 +04:00
|
|
|
%w(title description name link).each do |name|
|
2007-03-17 13:13:25 +03:00
|
|
|
install_text_element(name, ::RSS::URI, nil)
|
2004-10-16 08:51:15 +04:00
|
|
|
end
|
|
|
|
|
2007-03-17 13:13:25 +03:00
|
|
|
def initialize(*args)
|
|
|
|
if Utils.element_initialize_arguments?(args)
|
|
|
|
super
|
|
|
|
else
|
|
|
|
super()
|
|
|
|
self.about = args[0]
|
2004-11-19 11:25:25 +03:00
|
|
|
end
|
2004-10-16 08:51:15 +04:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
2004-11-27 11:47:28 +03:00
|
|
|
def maker_target(maker)
|
|
|
|
maker.textinput
|
|
|
|
end
|
2004-10-16 08:51:15 +04:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
2005-04-05 11:03:43 +04:00
|
|
|
RSS10::ELEMENTS.each do |name|
|
2007-03-17 13:13:25 +03:00
|
|
|
BaseListener.install_get_text_element(URI, name, name)
|
2004-10-16 08:51:15 +04:00
|
|
|
end
|
|
|
|
|
|
|
|
module ListenerMixin
|
|
|
|
private
|
2007-03-17 13:13:25 +03:00
|
|
|
def initial_start_RDF(tag_name, prefix, attrs, ns)
|
2009-05-16 13:25:59 +04:00
|
|
|
check_ns(tag_name, prefix, ns, RDF::URI, false)
|
2004-10-16 08:51:15 +04:00
|
|
|
|
|
|
|
@rss = RDF.new(@version, @encoding, @standalone)
|
|
|
|
@rss.do_validate = @do_validate
|
|
|
|
@rss.xml_stylesheets = @xml_stylesheets
|
|
|
|
@last_element = @rss
|
2007-03-17 13:13:25 +03: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 08:51:15 +04:00
|
|
|
end
|
|
|
|
end
|
2004-03-21 12:20:47 +03:00
|
|
|
|
2004-01-28 06:46:13 +03:00
|
|
|
end
|