From 8dfa6fb0a80d633d71987f06462823ca13b67be8 Mon Sep 17 00:00:00 2001 From: kou Date: Wed, 7 Apr 2004 03:36:38 +0000 Subject: * lib/rss/parser.rb, lib/rss/1.0.rb: accepted rdf:resource or resource attribute in rdf:li. * test/rss/test_parser.rb: added test for above change. * lib/rss/dublincore.rb: reverted style. * lib/rss/xmlparser.rb: normalized XMLParser class hierarchy. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@6115 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- lib/rss/1.0.rb | 2 +- lib/rss/dublincore.rb | 10 +++++----- lib/rss/parser.rb | 23 +++++++++++++---------- lib/rss/rss.rb | 17 ++++++----------- lib/rss/xmlparser.rb | 8 ++++++++ 5 files changed, 33 insertions(+), 27 deletions(-) (limited to 'lib/rss') diff --git a/lib/rss/1.0.rb b/lib/rss/1.0.rb index 6c33f1695d..696b492ada 100644 --- a/lib/rss/1.0.rb +++ b/lib/rss/1.0.rb @@ -150,7 +150,7 @@ EOT end [ - ["resource", nil, true] + ["resource", [URI, nil], true] ].each do |name, uri, required| install_get_attribute(name, uri, required) end diff --git a/lib/rss/dublincore.rb b/lib/rss/dublincore.rb index 06cb73ec97..dcf8e46c65 100644 --- a/lib/rss/dublincore.rb +++ b/lib/rss/dublincore.rb @@ -46,11 +46,11 @@ module RSS # For backward compatibility DublincoreModel = DublinCoreModel - class RDF < Element - class Channel < Element; include DublinCoreModel; end - class Image < Element; include DublinCoreModel; end - class Item < Element; include DublinCoreModel; end - class Textinput < Element; include DublinCoreModel; end + class RDF + class Channel; include DublinCoreModel; end + class Image; include DublinCoreModel; end + class Item; include DublinCoreModel; end + class Textinput; include DublinCoreModel; end end prefix_size = DC_PREFIX.size + 1 diff --git a/lib/rss/parser.rb b/lib/rss/parser.rb index a04f7959ec..e1c61f46ae 100644 --- a/lib/rss/parser.rb +++ b/lib/rss/parser.rb @@ -260,19 +260,18 @@ module RSS def start_else_element(local, prefix, attrs, ns) class_name = local[0,1].upcase << local[1..-1] current_class = @last_element.class - begin -# if current_class.const_defined?(class_name) +# begin + if current_class.constants.include?(class_name) next_class = current_class.const_get(class_name) start_have_something_element(local, prefix, attrs, ns, next_class) - rescue NameError -# else +# rescue NameError + else if @ignore_unknown_element @proc_stack.push(nil) else parent = "ROOT ELEMENT???" - begin - parent = current_class::TAG_NAME - rescue NameError + if current_class.const_defined?("TAG_NAME") + parent = current_class.const_get("TAG_NAME") end raise NotExceptedTagError.new(local, parent) end @@ -317,14 +316,18 @@ module RSS klass.get_attributes.each do |a_name, a_uri, required| - if a_uri + if a_uri.is_a?(String) or !a_uri.respond_to?(:include?) + a_uri = [a_uri] + end + unless a_uri == [nil] for prefix, uri in ns - if uri == a_uri + if a_uri.include?(uri) val = attrs["#{prefix}:#{a_name}"] break if val end end - else + end + if val.nil? and a_uri.include?(nil) val = attrs[a_name] end diff --git a/lib/rss/rss.rb b/lib/rss/rss.rb index e53934f725..fbd134c9c9 100644 --- a/lib/rss/rss.rb +++ b/lib/rss/rss.rb @@ -1,7 +1,7 @@ require "time" class Time - class << Time + class << self unless respond_to?(:w3cdtf) def w3cdtf(date) if /\A\s* @@ -510,11 +510,8 @@ EOC if not_shift not_shift = false - else - begin - tag = tags.shift - rescue NameError - end + elsif tags + tag = tags.shift end if DEBUG @@ -551,11 +548,9 @@ EOC end else if elem[0] == tag - begin - if model[i+1][0] != elem[0] and tags.first == elem[0] - raise TooMuchTagError.new(elem[0], tag_name) - end - rescue NameError # for model[i+1][0] and tags.first + if model[i+1] and model[i+1][0] != elem[0] and + tags and tags.first == elem[0] + raise TooMuchTagError.new(elem[0], tag_name) end else raise MissingTagError.new(elem[0], tag_name) diff --git a/lib/rss/xmlparser.rb b/lib/rss/xmlparser.rb index 355a428d2d..7be0dc9a11 100644 --- a/lib/rss/xmlparser.rb +++ b/lib/rss/xmlparser.rb @@ -17,6 +17,14 @@ rescue LoadError end end +module XML + class Parser + unless defined?(Error) + Error = ::XMLParserError + end + end +end + module RSS class REXMLLikeXMLParser < ::XML::Parser -- cgit v1.2.3