Class: RightAws::RightAWSParser
Overview
:nodoc:
Direct Known Subclasses
Ec2::QEc2ConfirmProductInstanceParser, Ec2::QEc2CreateKeyPairParser, Ec2::QEc2DescribeImageAttributeParser, Ec2::QEc2DescribeImagesParser, Ec2::QEc2DescribeInstancesParser, Ec2::QEc2DescribeKeyPairParser, Ec2::QEc2DescribeSecurityGroupsParser, Ec2::QEc2GetConsoleOutputParser, Ec2::QEc2RegisterImageParser, Ec2::QEc2RunInstancesParser, Ec2::QEc2TerminateInstancesParser, Ec2::RightBoolResponseParser, RightErrorResponseParser, S3Interface::S3AclParser, S3Interface::S3BucketLocationParser, S3Interface::S3ImprovedListBucketParser, S3Interface::S3ListAllMyBucketsParser, S3Interface::S3ListBucketParser, SqsInterface::SqsCreateQueueParser, SqsInterface::SqsGetQueueAttributesParser, SqsInterface::SqsGetVisibilityTimeoutParser, SqsInterface::SqsListGrantsParser, SqsInterface::SqsListQueuesParser, SqsInterface::SqsReceiveMessagesParser, SqsInterface::SqsSendMessagesParser, SqsInterface::SqsStatusParser
Constant Summary collapse
- DEFAULT_XML_LIBRARY =
default parsing library
'rexml'
- @@supported_xml_libs =
a list of supported parsers
[DEFAULT_XML_LIBRARY, 'libxml']
- @@xml_lib =
xml library name: ‘rexml’ | ‘libxml’
DEFAULT_XML_LIBRARY
Instance Attribute Summary collapse
-
#result ⇒ Object
Returns the value of attribute result.
-
#xml_lib ⇒ Object
Returns the value of attribute xml_lib.
-
#xmlpath ⇒ Object
readonly
Returns the value of attribute xmlpath.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(params = {}) ⇒ RightAWSParser
constructor
A new instance of RightAWSParser.
-
#method_missing(method, *params) ⇒ Object
Parser must have a lots of methods (see /usr/lib/ruby/1.8/rexml/parsers/streamparser.rb) We dont need most of them in RightAWSParser and method_missing helps us to skip their definition.
-
#parse(xml_text, params = {}) ⇒ Object
Parser method.
-
#reset ⇒ Object
the functions to be overriden by children (if nessesery).
- #tag_end(name) ⇒ Object
- #tag_start(name, attributes) ⇒ Object
- #tagend(name) ⇒ Object
- #tagstart(name, attributes) ⇒ Object
- #tagtext(text) ⇒ Object
- #text(text) ⇒ Object
Constructor Details
#initialize(params = {}) ⇒ RightAWSParser
Returns a new instance of RightAWSParser.
507 508 509 510 511 512 513 514 |
# File 'lib/awsbase/right_awsbase.rb', line 507 def initialize(params={}) @xmlpath = '' @result = false @text = '' @xml_lib = params[:xml_lib] || @@xml_lib @logger = params[:logger] reset end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *params) ⇒ Object
Parser must have a lots of methods (see /usr/lib/ruby/1.8/rexml/parsers/streamparser.rb) We dont need most of them in RightAWSParser and method_missing helps us to skip their definition
579 580 581 582 583 584 585 586 |
# File 'lib/awsbase/right_awsbase.rb', line 579 def method_missing(method, *params) # if the method is one of known - just skip it ... return if [:comment, :attlistdecl, :notationdecl, :elementdecl, :entitydecl, :cdata, :xmldecl, :attlistdecl, :instruction, :doctype].include?(method) # ... else - call super to raise an exception super(method, params) end |
Instance Attribute Details
#result ⇒ Object
Returns the value of attribute result.
503 504 505 |
# File 'lib/awsbase/right_awsbase.rb', line 503 def result @result end |
#xml_lib ⇒ Object
Returns the value of attribute xml_lib.
505 506 507 |
# File 'lib/awsbase/right_awsbase.rb', line 505 def xml_lib @xml_lib end |
#xmlpath ⇒ Object (readonly)
Returns the value of attribute xmlpath.
504 505 506 |
# File 'lib/awsbase/right_awsbase.rb', line 504 def xmlpath @xmlpath end |
Class Method Details
.xml_lib ⇒ Object
496 497 498 |
# File 'lib/awsbase/right_awsbase.rb', line 496 def self.xml_lib @@xml_lib end |
.xml_lib=(new_lib_name) ⇒ Object
499 500 501 |
# File 'lib/awsbase/right_awsbase.rb', line 499 def self.xml_lib=(new_lib_name) @@xml_lib = new_lib_name end |
Instance Method Details
#parse(xml_text, params = {}) ⇒ Object
Parser method. Params:
xml_text - xml message text(String) or Net:HTTPxxx instance (response)
params[:xml_lib] - library name: 'rexml' | 'libxml'
533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 |
# File 'lib/awsbase/right_awsbase.rb', line 533 def parse(xml_text, params={}) # Get response body xml_text = xml_text.body unless xml_text.is_a?(String) @xml_lib = params[:xml_lib] || @xml_lib # check that we had no problems with this library otherwise use default @xml_lib = DEFAULT_XML_LIBRARY unless @@supported_xml_libs.include?(@xml_lib) # load xml library if @xml_lib=='libxml' && !defined?(XML::SaxParser) begin require 'xml/libxml' # is it new ? - Setup SaxParserCallback if XML::Parser::VERSION >= '0.5.1.0' RightSaxParserCallback.include_callback end rescue LoadError => e @@supported_xml_libs.delete(@xml_lib) @xml_lib = DEFAULT_XML_LIBRARY if @logger @logger.error e.inspect @logger.error e.backtrace @logger.info "Can not load 'libxml' library. '#{DEFAULT_XML_LIBRARY}' is used for parsing." end end end # Parse the xml text case @xml_lib when 'libxml' xml = XML::SaxParser.new xml.string = xml_text # check libxml-ruby version if XML::Parser::VERSION >= '0.5.1.0' xml.callbacks = RightSaxParserCallback.new(self) else xml.on_start_element{|name, attr_hash| self.tag_start(name, attr_hash)} xml.on_characters{ |text| self.text(text)} xml.on_end_element{ |name| self.tag_end(name)} end xml.parse else REXML::Document.parse_stream(xml_text, self) end end |
#reset ⇒ Object
the functions to be overriden by children (if nessesery)
588 |
# File 'lib/awsbase/right_awsbase.rb', line 588 def reset ; end |
#tag_end(name) ⇒ Object
520 521 522 523 524 |
# File 'lib/awsbase/right_awsbase.rb', line 520 def tag_end(name) @xmlpath[/^(.*?)\/?#{name}$/] @xmlpath = $1 tagend(name) end |
#tag_start(name, attributes) ⇒ Object
515 516 517 518 519 |
# File 'lib/awsbase/right_awsbase.rb', line 515 def tag_start(name, attributes) @text = '' (name, attributes) @xmlpath += @xmlpath.empty? ? name : "/#{name}" end |
#tagend(name) ⇒ Object
590 |
# File 'lib/awsbase/right_awsbase.rb', line 590 def tagend(name) ; end |
#tagstart(name, attributes) ⇒ Object
589 |
# File 'lib/awsbase/right_awsbase.rb', line 589 def (name, attributes); end |
#tagtext(text) ⇒ Object
591 |
# File 'lib/awsbase/right_awsbase.rb', line 591 def tagtext(text) ; end |
#text(text) ⇒ Object
525 526 527 528 |
# File 'lib/awsbase/right_awsbase.rb', line 525 def text(text) @text = text tagtext(text) end |