summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorkou <kou@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2004-04-07 03:36:38 +0000
committerkou <kou@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2004-04-07 03:36:38 +0000
commit8dfa6fb0a80d633d71987f06462823ca13b67be8 (patch)
treeccf92cc3af99d21f06a5a9c32d02e247abe74592
parent4ded52b623ebd1b3de12db82f8b54cc156c1fd28 (diff)
* 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
-rw-r--r--ChangeLog10
-rw-r--r--lib/rss/1.0.rb2
-rw-r--r--lib/rss/dublincore.rb10
-rw-r--r--lib/rss/parser.rb23
-rw-r--r--lib/rss/rss.rb17
-rw-r--r--lib/rss/xmlparser.rb8
-rw-r--r--sample/rss/list_description.rb10
-rw-r--r--sample/rss/rss_recent.rb11
-rw-r--r--test/rss/test_parser.rb31
9 files changed, 84 insertions, 38 deletions
diff --git a/ChangeLog b/ChangeLog
index 8d3686e4a3..71ec41975d 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+Wed Apr 7 12:32:02 2004 Kouhei Sutou <kou@cozmixng.org>
+
+ * 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.
+
Wed Apr 7 10:43:17 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
* Makefile.in, common.mk, */Makefile.sub (ext/extinit.o): OUTFLAG
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
diff --git a/sample/rss/list_description.rb b/sample/rss/list_description.rb
index edb9ba07a4..e0b59ea659 100644
--- a/sample/rss/list_description.rb
+++ b/sample/rss/list_description.rb
@@ -10,7 +10,6 @@ class String
end
end
-require "rss/parser"
require "rss/1.0"
require "rss/2.0"
require "rss/dublincore"
@@ -72,13 +71,14 @@ processing_time = Time.now - before_time
channels.sort do |x, y|
x[0] <=> y[0]
end[0..20].each do |title, items|
- puts "Channel : #{title}" unless items.empty?
+ puts "Channel: #{title}" unless items.empty?
items.sort do |x, y|
x.title <=> y.title
end[0..10].each do |item|
- puts " Item : #{item.title.shorten(50)}"
- puts " Description : #{item.description.shorten(50)}"
+ puts " Item: #{item.title.shorten(50)}"
+ puts " Description: #{item.description.shorten(50)}"
end
end
-puts "Processing Time : #{processing_time}s"
+puts "Used XML parser: #{RSS::Parser.default_parser}"
+puts "Processing time: #{processing_time}s"
diff --git a/sample/rss/rss_recent.rb b/sample/rss/rss_recent.rb
index 3ccb4a4505..8e40151e1c 100644
--- a/sample/rss/rss_recent.rb
+++ b/sample/rss/rss_recent.rb
@@ -10,10 +10,8 @@ class String
end
end
-require "rss/parser"
require "rss/1.0"
require "rss/2.0"
-require "rss/syndication"
require "rss/dublincore"
items = []
@@ -76,9 +74,10 @@ processing_time = Time.now - before_time
items.sort do |x, y|
y[1].dc_date <=> x[1].dc_date
end[0..20].each do |channel, item|
- puts "#{item.dc_date.localtime.iso8601} : " <<
- "#{channel.title} : #{item.title}"
- puts " description : #{item.description.shorten(50)}" if item.description
+ puts "#{item.dc_date.localtime.iso8601}: " <<
+ "#{channel.title}: #{item.title}"
+ puts " Description: #{item.description.shorten(50)}" if item.description
end
-puts "Processing Time : #{processing_time}s"
+puts "Used XML parser: #{RSS::Parser.default_parser}"
+puts "Processing time: #{processing_time}s"
diff --git a/test/rss/test_parser.rb b/test/rss/test_parser.rb
index 461d64d612..05ff9748ad 100644
--- a/test/rss/test_parser.rb
+++ b/test/rss/test_parser.rb
@@ -219,6 +219,37 @@ EOR
end
+ def test_rdf_li
+
+ rss = make_RDF(<<-EOR)
+<channel rdf:about="http://example.com/">
+ <title>hoge</title>
+ <link>http://example.com/</link>
+ <description>hogehoge</description>
+ <image rdf:resource="http://example.com/hoge.png" />
+ <items>
+ <rdf:Seq>
+ <rdf:li \#{rdf_li_attr}/>
+ </rdf:Seq>
+ </items>
+ <textinput rdf:resource="http://example.com/search" />
+</channel>
+#{make_item}
+EOR
+
+ source = Proc.new do |rdf_li_attr|
+ eval(%Q[%Q[#{rss}]], binding)
+ end
+
+ attr = %q[resource="http://example.com/hoge"]
+ assert_parse(source.call(attr), :nothing_raised)
+
+ attr = %q[rdf:resource="http://example.com/hoge"]
+ assert_parse(source.call(attr), :nothing_raised)
+
+ assert_parse(source.call(""), :missing_attribute, "li", "resource")
+ end
+
def test_image
assert_parse(make_RDF(<<-EOR), :missing_attribute, "image", "about")