2015-12-16 00:07:31 -05:00
|
|
|
# frozen_string_literal: false
|
2004-03-21 04:20:47 -05:00
|
|
|
begin
|
2004-10-16 00:51:15 -04:00
|
|
|
require "xml/parser"
|
2004-03-21 04:20:47 -05:00
|
|
|
rescue LoadError
|
2004-10-16 00:51:15 -04:00
|
|
|
require "xmlparser"
|
2004-03-21 04:20:47 -05:00
|
|
|
end
|
|
|
|
|
2004-01-27 22:46:13 -05:00
|
|
|
begin
|
2004-10-16 00:51:15 -04:00
|
|
|
require "xml/encoding-ja"
|
2004-01-27 22:46:13 -05:00
|
|
|
rescue LoadError
|
2004-10-16 00:51:15 -04:00
|
|
|
require "xmlencoding-ja"
|
|
|
|
if defined?(Kconv)
|
|
|
|
module XMLEncoding_ja
|
|
|
|
class SJISHandler
|
|
|
|
include Kconv
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2004-01-27 22:46:13 -05:00
|
|
|
end
|
|
|
|
|
2004-04-06 23:36:38 -04:00
|
|
|
module XML
|
2004-10-16 00:51:15 -04:00
|
|
|
class Parser
|
|
|
|
unless defined?(Error)
|
2014-01-19 00:43:26 -05:00
|
|
|
# This error is legacy, so we just set it to the new one
|
2013-08-19 13:02:40 -04:00
|
|
|
Error = ::XMLParserError # :nodoc:
|
2004-10-16 00:51:15 -04:00
|
|
|
end
|
|
|
|
end
|
2004-04-06 23:36:38 -04:00
|
|
|
end
|
|
|
|
|
2004-01-27 22:46:13 -05:00
|
|
|
module RSS
|
2009-03-05 22:56:38 -05:00
|
|
|
|
2004-10-16 00:51:15 -04:00
|
|
|
class REXMLLikeXMLParser < ::XML::Parser
|
2009-03-05 22:56:38 -05:00
|
|
|
|
2004-10-16 00:51:15 -04:00
|
|
|
include ::XML::Encoding_ja
|
2004-01-27 22:46:13 -05:00
|
|
|
|
2004-10-16 00:51:15 -04:00
|
|
|
def listener=(listener)
|
|
|
|
@listener = listener
|
|
|
|
end
|
2004-01-27 22:46:13 -05:00
|
|
|
|
2004-10-16 00:51:15 -04:00
|
|
|
def startElement(name, attrs)
|
|
|
|
@listener.tag_start(name, attrs)
|
|
|
|
end
|
2009-03-05 22:56:38 -05:00
|
|
|
|
2004-10-16 00:51:15 -04:00
|
|
|
def endElement(name)
|
|
|
|
@listener.tag_end(name)
|
|
|
|
end
|
2004-01-27 22:46:13 -05:00
|
|
|
|
2004-10-16 00:51:15 -04:00
|
|
|
def character(data)
|
|
|
|
@listener.text(data)
|
|
|
|
end
|
2004-01-27 22:46:13 -05:00
|
|
|
|
2004-10-16 00:51:15 -04:00
|
|
|
def xmlDecl(version, encoding, standalone)
|
|
|
|
@listener.xmldecl(version, encoding, standalone == 1)
|
|
|
|
end
|
2004-01-27 22:46:13 -05:00
|
|
|
|
2004-10-16 00:51:15 -04:00
|
|
|
def processingInstruction(target, content)
|
|
|
|
@listener.instruction(target, content)
|
|
|
|
end
|
2004-03-21 04:20:47 -05:00
|
|
|
|
2004-10-16 00:51:15 -04:00
|
|
|
end
|
2004-01-27 22:46:13 -05:00
|
|
|
|
2004-10-16 00:51:15 -04:00
|
|
|
class XMLParserParser < BaseParser
|
2004-01-27 22:46:13 -05:00
|
|
|
|
2005-11-23 08:35:11 -05:00
|
|
|
class << self
|
|
|
|
def listener
|
|
|
|
XMLParserListener
|
|
|
|
end
|
2004-10-16 00:51:15 -04:00
|
|
|
end
|
2009-03-05 22:56:38 -05:00
|
|
|
|
2005-11-23 08:35:11 -05:00
|
|
|
private
|
2004-10-16 00:51:15 -04:00
|
|
|
def _parse
|
|
|
|
begin
|
|
|
|
parser = REXMLLikeXMLParser.new
|
|
|
|
parser.listener = @listener
|
|
|
|
parser.parse(@rss)
|
|
|
|
rescue ::XML::Parser::Error => e
|
|
|
|
raise NotWellFormedError.new(parser.line){e.message}
|
|
|
|
end
|
|
|
|
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
|
|
|
class XMLParserListener < BaseListener
|
2004-01-27 22:46:13 -05:00
|
|
|
|
2004-10-16 00:51:15 -04:00
|
|
|
include ListenerMixin
|
2009-03-05 22:56:38 -05:00
|
|
|
|
2004-10-16 00:51:15 -04:00
|
|
|
def xmldecl(version, encoding, standalone)
|
|
|
|
super
|
|
|
|
# Encoding is converted to UTF-8 when XMLParser parses XML.
|
|
|
|
@encoding = 'UTF-8'
|
|
|
|
end
|
2004-01-27 22:46:13 -05:00
|
|
|
|
2004-10-16 00:51:15 -04:00
|
|
|
end
|
2004-01-27 22:46:13 -05:00
|
|
|
|
|
|
|
end
|