1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353
|
## -*- Ruby -*-
## SAX (Simple API for XML) 1.0 for Ruby (experimental)
## 1999 by yoshidam
##
## SAX information: http://www.megginson.com/SAX/
##
module XML
module SAX
module AttributeList
def getLength
raise "not implemented"
end
def getName(pos)
raise "not implemented"
end
def getType(pos_or_name)
raise "not implemented"
end
def getValue(pos_or_name)
raise "not implemented"
end
end
module DTDHandler
def notationDecl(name, pubid, sysid)
raise "not implemented"
end
def unparsedEntityDecl(name, pubid, sysid, notation)
raise "not implemented"
end
end
module DocumentHandler
def setDocumentLocator(locator)
raise "not implemented"
end
def startDocument
raise "not implemented"
end
def endDocument()
raise "not implemented"
end
def startElement(name, atts)
raise "not implemented"
end
def endElement(name)
raise "not implemented"
end
def characters(ch, start, length)
raise "not implemented"
end
def ignorableWhitespace(ch, start, length)
raise "not implemented"
end
def processingInstruction(target, data)
raise "not implemented"
end
end
module EntityResolver
def resolveEntity(pubid, sysid)
raise "not implemented"
end
end
module ErrorHandler
def warning(e)
raise "not implemented"
end
def error(e)
raise "not implemented"
end
def fatalError(e)
raise "not implemented"
end
end
module Locator
def getPublicId
raise "not implemented"
end
def getSystemId
raise "not implemented"
end
def getLineNumber
raise "not implemented"
end
def getColumnNumber
raise "not implemented"
end
end
module Parser
def setLocale(locale)
raise "not implemented"
end
def setEntityResolver(resolver)
raise "not implemented"
end
def setDTDHandler(handler)
raise "not implemented"
end
def setDocumentHandler(handler)
raise "not implemented"
end
def setErrorHandler
raise "not implemented"
end
def parse(source_or_sysid)
raise "not implemented"
end
end
class HandlerBase
include EntityResolver
include DTDHandler
include DocumentHandler
include ErrorHandler
def resolveEntity(pubid, sysid)
nil
end
def notationDecl(name, pubid, sysid)
end
def unparsedEntityDecl(name, pubid, sysid, natation)
end
def setDocumentLocator(locator)
end
def startDocument
end
def endDocument
end
def startElement(name, atts)
end
def endElement(name)
end
def characters(ch, start, length)
end
def ignorableWhitespace(ch, sart, length)
end
def processingInstruction(target, data)
end
def warning(e)
end
def error(e)
end
def fatalError(e)
raise e
end
end
class InputSource
def initialize(sysid)
@publicId = nil
@systemId = nil
@stream = nil
@encoding = nil
if sysid.kind_of?(String)
setSystemId(sysid)
elsif !sysid.nil?
setByteStream(sysid)
end
end
def setPublicId(pubid)
@publicId = pubid
end
def getPublicId
@publicId
end
def setSystemId(sysid)
@systemId = sysid
end
def getSystemId
@systemId
end
def setByteStream(stream)
@stream = stream
end
def getByteStream
@stream
end
def setEncoding(encoding)
@encoding = encoding
end
def getEncoding
@encoding
end
def setCharacterStream(stream)
raise "not implemented"
end
def getCharacterStream
raise "not implemented"
end
end
class SAXException < Exception
## initialize(String)
## initialize(Exception)
## initialize(String, Exception)
def initialize(message, e = nil)
@message = nil
@exception = nil
if message.kind_of?(String) && e.nil?
@message = message
elsif message.kind_of?(Exception) && e.nil?
@exception = e
elsif message.kind_of?(String) && e.kind_of?(Exception)
@message = message
@exception = e
else
raise TypeError.new("parameter error")
end
end
def getMessage
if @message.nil? && !@exception.nil?
return @exception.to_s
end
@message
end
def getException
@exception
end
def toString
getMessage
end
alias to_s toString
end
class SAXParseException < SAXException
## initialize(String, Locator)
## initialize(String, Locator, Exception)
## initialize(String, String, String, Fixnum, Fixnum)
## initialize(String, String, String, Fixnum, Fixnum, Exception)
def initialize(message, pubid = nil, sysid = nil,
line = nil, column = nil, e = nil)
@publicId = nil
@systemiId = nil
@lineNumber = nil
@columnNumber = nil
if message.kind_of?(String) && pubid.kind_of?(Locator) &&
sysid.nil? && line.nil? && column.nil? && e.nil?
super(message)
@publicId = pubid.getPublicId
@systemId = pubid.getSystemId
@lineNumber = pubid.getLineNumber
@columnNumber = pubid.getColumnNumber
elsif message.kind_of?(String) && pubid.kind_of?(Locator) &&
sysid.kind_of?(Exception) && line.nil? && column.nil? && e.nil?
super(message, sysid)
@publicId = pubid.getPublicId
@systemId = pubid.getSystemId
@lineNumber = pubid.getLineNumber
@columnNumber = pubid.getColumnNumber
elsif message.kind_of?(String) && pubid.kind_of?(String) &&
sysid.kind_of?(String) && line.kind_of?(Fixnum) &&
column.kind_of?(Fixnum) && e.nil?
super(message)
@publicId = pubid
@systemId = sysid
@lineNumber = line
@columnNumber = column
elsif message.kind_of?(String) && pubid.kind_of?(String) &&
sysid.kind_of?(String) && line.kind_of?(Fixnum) &&
column.kind_of?(Fixnum) && e.kind_of?(Exception)
super(message, e)
@publicId = pubid
@systemId = sysid
@lineNumber = line
@columnNumber = column
else
raise TypeError.new("parameter error")
end
end
def getPublicId
@publicId
end
def getSystemId
@systemId
end
def getLineNumber
@lineNumber
end
def getColumnNumber
@columnNumber
end
end
module Helpers
module ParserFactory
def ParserFactory::makeParser(klass)
if klass.kind_of?(Class)
klass.new
elsif klass.kind_of?(String)
eval(klass).new
end
end
end
end
end
end
|