Module: MARC::JRubySTAXReader
- Includes:
- GenericPullParser
- Defined in:
- lib/marc/xml_parsers.rb
Overview
DEPRECATED: JRubySTAXReader is deprecated and will be removed in a future version of ruby-marc. Please use NokogiriReader instead.
Constant Summary
Constants included from GenericPullParser
GenericPullParser::CF_TAG, GenericPullParser::DF_TAG, GenericPullParser::LEAD_TAG, GenericPullParser::REC_TAG, GenericPullParser::SF_TAG
Class Method Summary collapse
Instance Method Summary collapse
- #attributes_to_hash(attributes) ⇒ Object
-
#each(&block) ⇒ Object
Loop through the MARC records in the XML document.
- #init ⇒ Object
- #parser_dispatch ⇒ Object
Methods included from GenericPullParser
#characters, #end_element_namespace, #start_element_namespace, #yield_record
Class Method Details
.extended(receiver) ⇒ Object
404 405 406 407 |
# File 'lib/marc/xml_parsers.rb', line 404 def self.extended(receiver) require "java" # may only be neccesary in jruby 1.6 receiver.init end |
Instance Method Details
#attributes_to_hash(attributes) ⇒ Object
440 441 442 443 444 445 446 |
# File 'lib/marc/xml_parsers.rb', line 440 def attributes_to_hash(attributes) hash = {} @parser.getAttributeCount.times do |i| hash[@parser.getAttributeName(i).getLocalPart] = @parser.getAttributeValue(i) end hash end |
#each(&block) ⇒ Object
Loop through the MARC records in the XML document
418 419 420 421 422 423 424 425 |
# File 'lib/marc/xml_parsers.rb', line 418 def each(&block) if block @block = block parser_dispatch else enum_for(:each) end end |
#init ⇒ Object
409 410 411 412 413 414 415 |
# File 'lib/marc/xml_parsers.rb', line 409 def init warn "JRubySTAXReader is deprecated and will be removed in a future version of ruby-marc." super @factory = javax.xml.stream.XMLInputFactory.newInstance @parser = @factory.createXMLStreamReader(@handle.to_inputstream) end |
#parser_dispatch ⇒ Object
427 428 429 430 431 432 433 434 435 436 437 438 |
# File 'lib/marc/xml_parsers.rb', line 427 def parser_dispatch while (event = @parser.next) && (event != javax.xml.stream.XMLStreamConstants::END_DOCUMENT) case event when javax.xml.stream.XMLStreamConstants::START_ELEMENT start_element_namespace(@parser.getLocalName, [], nil, @parser.getNamespaceURI, nil) when javax.xml.stream.XMLStreamConstants::END_ELEMENT end_element_namespace(@parser.getLocalName, @parser.getPrefix, @parser.getNamespaceURI) when javax.xml.stream.XMLStreamConstants::CHARACTERS characters(@parser.getText) end end end |