mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* 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
This commit is contained in:
parent
4ded52b623
commit
8dfa6fb0a8
9 changed files with 84 additions and 38 deletions
10
ChangeLog
10
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>
|
Wed Apr 7 10:43:17 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
|
|
||||||
* Makefile.in, common.mk, */Makefile.sub (ext/extinit.o): OUTFLAG
|
* Makefile.in, common.mk, */Makefile.sub (ext/extinit.o): OUTFLAG
|
||||||
|
|
|
@ -150,7 +150,7 @@ EOT
|
||||||
end
|
end
|
||||||
|
|
||||||
[
|
[
|
||||||
["resource", nil, true]
|
["resource", [URI, nil], true]
|
||||||
].each do |name, uri, required|
|
].each do |name, uri, required|
|
||||||
install_get_attribute(name, uri, required)
|
install_get_attribute(name, uri, required)
|
||||||
end
|
end
|
||||||
|
|
|
@ -46,11 +46,11 @@ module RSS
|
||||||
# For backward compatibility
|
# For backward compatibility
|
||||||
DublincoreModel = DublinCoreModel
|
DublincoreModel = DublinCoreModel
|
||||||
|
|
||||||
class RDF < Element
|
class RDF
|
||||||
class Channel < Element; include DublinCoreModel; end
|
class Channel; include DublinCoreModel; end
|
||||||
class Image < Element; include DublinCoreModel; end
|
class Image; include DublinCoreModel; end
|
||||||
class Item < Element; include DublinCoreModel; end
|
class Item; include DublinCoreModel; end
|
||||||
class Textinput < Element; include DublinCoreModel; end
|
class Textinput; include DublinCoreModel; end
|
||||||
end
|
end
|
||||||
|
|
||||||
prefix_size = DC_PREFIX.size + 1
|
prefix_size = DC_PREFIX.size + 1
|
||||||
|
|
|
@ -260,19 +260,18 @@ module RSS
|
||||||
def start_else_element(local, prefix, attrs, ns)
|
def start_else_element(local, prefix, attrs, ns)
|
||||||
class_name = local[0,1].upcase << local[1..-1]
|
class_name = local[0,1].upcase << local[1..-1]
|
||||||
current_class = @last_element.class
|
current_class = @last_element.class
|
||||||
begin
|
# begin
|
||||||
# if current_class.const_defined?(class_name)
|
if current_class.constants.include?(class_name)
|
||||||
next_class = current_class.const_get(class_name)
|
next_class = current_class.const_get(class_name)
|
||||||
start_have_something_element(local, prefix, attrs, ns, next_class)
|
start_have_something_element(local, prefix, attrs, ns, next_class)
|
||||||
rescue NameError
|
# rescue NameError
|
||||||
# else
|
else
|
||||||
if @ignore_unknown_element
|
if @ignore_unknown_element
|
||||||
@proc_stack.push(nil)
|
@proc_stack.push(nil)
|
||||||
else
|
else
|
||||||
parent = "ROOT ELEMENT???"
|
parent = "ROOT ELEMENT???"
|
||||||
begin
|
if current_class.const_defined?("TAG_NAME")
|
||||||
parent = current_class::TAG_NAME
|
parent = current_class.const_get("TAG_NAME")
|
||||||
rescue NameError
|
|
||||||
end
|
end
|
||||||
raise NotExceptedTagError.new(local, parent)
|
raise NotExceptedTagError.new(local, parent)
|
||||||
end
|
end
|
||||||
|
@ -317,14 +316,18 @@ module RSS
|
||||||
|
|
||||||
klass.get_attributes.each do |a_name, a_uri, required|
|
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
|
for prefix, uri in ns
|
||||||
if uri == a_uri
|
if a_uri.include?(uri)
|
||||||
val = attrs["#{prefix}:#{a_name}"]
|
val = attrs["#{prefix}:#{a_name}"]
|
||||||
break if val
|
break if val
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
else
|
end
|
||||||
|
if val.nil? and a_uri.include?(nil)
|
||||||
val = attrs[a_name]
|
val = attrs[a_name]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
require "time"
|
require "time"
|
||||||
|
|
||||||
class Time
|
class Time
|
||||||
class << Time
|
class << self
|
||||||
unless respond_to?(:w3cdtf)
|
unless respond_to?(:w3cdtf)
|
||||||
def w3cdtf(date)
|
def w3cdtf(date)
|
||||||
if /\A\s*
|
if /\A\s*
|
||||||
|
@ -510,11 +510,8 @@ EOC
|
||||||
|
|
||||||
if not_shift
|
if not_shift
|
||||||
not_shift = false
|
not_shift = false
|
||||||
else
|
elsif tags
|
||||||
begin
|
|
||||||
tag = tags.shift
|
tag = tags.shift
|
||||||
rescue NameError
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
if DEBUG
|
if DEBUG
|
||||||
|
@ -551,12 +548,10 @@ EOC
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
if elem[0] == tag
|
if elem[0] == tag
|
||||||
begin
|
if model[i+1] and model[i+1][0] != elem[0] and
|
||||||
if model[i+1][0] != elem[0] and tags.first == elem[0]
|
tags and tags.first == elem[0]
|
||||||
raise TooMuchTagError.new(elem[0], tag_name)
|
raise TooMuchTagError.new(elem[0], tag_name)
|
||||||
end
|
end
|
||||||
rescue NameError # for model[i+1][0] and tags.first
|
|
||||||
end
|
|
||||||
else
|
else
|
||||||
raise MissingTagError.new(elem[0], tag_name)
|
raise MissingTagError.new(elem[0], tag_name)
|
||||||
end
|
end
|
||||||
|
|
|
@ -17,6 +17,14 @@ rescue LoadError
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
module XML
|
||||||
|
class Parser
|
||||||
|
unless defined?(Error)
|
||||||
|
Error = ::XMLParserError
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
module RSS
|
module RSS
|
||||||
|
|
||||||
class REXMLLikeXMLParser < ::XML::Parser
|
class REXMLLikeXMLParser < ::XML::Parser
|
||||||
|
|
|
@ -10,7 +10,6 @@ class String
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
require "rss/parser"
|
|
||||||
require "rss/1.0"
|
require "rss/1.0"
|
||||||
require "rss/2.0"
|
require "rss/2.0"
|
||||||
require "rss/dublincore"
|
require "rss/dublincore"
|
||||||
|
@ -81,4 +80,5 @@ end[0..20].each do |title, items|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
puts "Processing Time : #{processing_time}s"
|
puts "Used XML parser: #{RSS::Parser.default_parser}"
|
||||||
|
puts "Processing time: #{processing_time}s"
|
||||||
|
|
|
@ -10,10 +10,8 @@ class String
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
require "rss/parser"
|
|
||||||
require "rss/1.0"
|
require "rss/1.0"
|
||||||
require "rss/2.0"
|
require "rss/2.0"
|
||||||
require "rss/syndication"
|
|
||||||
require "rss/dublincore"
|
require "rss/dublincore"
|
||||||
|
|
||||||
items = []
|
items = []
|
||||||
|
@ -78,7 +76,8 @@ items.sort do |x, y|
|
||||||
end[0..20].each do |channel, item|
|
end[0..20].each do |channel, item|
|
||||||
puts "#{item.dc_date.localtime.iso8601}: " <<
|
puts "#{item.dc_date.localtime.iso8601}: " <<
|
||||||
"#{channel.title}: #{item.title}"
|
"#{channel.title}: #{item.title}"
|
||||||
puts " description : #{item.description.shorten(50)}" if item.description
|
puts " Description: #{item.description.shorten(50)}" if item.description
|
||||||
end
|
end
|
||||||
|
|
||||||
puts "Processing Time : #{processing_time}s"
|
puts "Used XML parser: #{RSS::Parser.default_parser}"
|
||||||
|
puts "Processing time: #{processing_time}s"
|
||||||
|
|
|
@ -219,6 +219,37 @@ EOR
|
||||||
|
|
||||||
end
|
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
|
def test_image
|
||||||
|
|
||||||
assert_parse(make_RDF(<<-EOR), :missing_attribute, "image", "about")
|
assert_parse(make_RDF(<<-EOR), :missing_attribute, "image", "about")
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue