Class: RightAws::RightAWSParser
- Inherits:
-
Object
- Object
- RightAws::RightAWSParser
- Defined in:
- lib/awsbase/right_awsbase.rb
Overview
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::S3ImprovedListBucketParser, S3Interface::S3ListAllMyBucketsParser, S3Interface::S3ListBucketParser, SqsInterface::SqsCreateQueueParser, SqsInterface::SqsGetQueueAttributesParser, SqsInterface::SqsGetVisibilityTimeoutParser, SqsInterface::SqsListGrantsParser, SqsInterface::SqsListQueuesParser, SqsInterface::SqsReceiveMessagesParser, SqsInterface::SqsSendMessagesParser, SqsInterface::SqsStatusParser
Constant Summary collapse
- @@xml_lib =
:nodoc:
'rexml'
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
-
.xml_lib ⇒ Object
xml library name: ‘rexml’ | ‘libxml’.
- .xml_lib=(new_lib_name) ⇒ Object
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.
352 353 354 355 356 357 358 359 |
# File 'lib/awsbase/right_awsbase.rb', line 352 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
415 416 417 418 419 420 421 422 |
# File 'lib/awsbase/right_awsbase.rb', line 415 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.
348 349 350 |
# File 'lib/awsbase/right_awsbase.rb', line 348 def result @result end |
#xml_lib ⇒ Object
Returns the value of attribute xml_lib.
350 351 352 |
# File 'lib/awsbase/right_awsbase.rb', line 350 def xml_lib @xml_lib end |
#xmlpath ⇒ Object (readonly)
Returns the value of attribute xmlpath.
349 350 351 |
# File 'lib/awsbase/right_awsbase.rb', line 349 def xmlpath @xmlpath end |
Class Method Details
.xml_lib ⇒ Object
xml library name: ‘rexml’ | ‘libxml’
341 342 343 |
# File 'lib/awsbase/right_awsbase.rb', line 341 def self.xml_lib @@xml_lib end |
.xml_lib=(new_lib_name) ⇒ Object
344 345 346 |
# File 'lib/awsbase/right_awsbase.rb', line 344 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'
378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 |
# File 'lib/awsbase/right_awsbase.rb', line 378 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 # load xml library if @xml_lib=='libxml' && !defined?(XML::SaxParser) begin require 'xml/libxml' rescue LoadError => e @xml_lib = 'rexml' if @logger @logger.error e.inspect @logger.error e.backtrace @logger.info "Can not load 'libxml' library. 'Rexml' is used for parsing." end end end # Parse the xml text case @xml_lib when 'libxml' xml = XML::SaxParser.new xml.string = xml_text 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)} xml.parse else if @logger && @xml_lib!='rexml' @logger.info "RightAWSParser#parse: Unknown xml library ('#{@xml_lib}') is selected. The default 'rexml' is used." end REXML::Document.parse_stream(xml_text, self) end end |
#reset ⇒ Object
the functions to be overriden by children (if nessesery)
424 |
# File 'lib/awsbase/right_awsbase.rb', line 424 def reset ; end |
#tag_end(name) ⇒ Object
365 366 367 368 369 |
# File 'lib/awsbase/right_awsbase.rb', line 365 def tag_end(name) @xmlpath[/^(.*?)\/?#{name}$/] @xmlpath = $1 tagend(name) end |
#tag_start(name, attributes) ⇒ Object
360 361 362 363 364 |
# File 'lib/awsbase/right_awsbase.rb', line 360 def tag_start(name, attributes) @text = '' (name, attributes) @xmlpath += @xmlpath.empty? ? name : "/#{name}" end |
#tagend(name) ⇒ Object
426 |
# File 'lib/awsbase/right_awsbase.rb', line 426 def tagend(name) ; end |
#tagstart(name, attributes) ⇒ Object
425 |
# File 'lib/awsbase/right_awsbase.rb', line 425 def (name, attributes); end |
#tagtext(text) ⇒ Object
427 |
# File 'lib/awsbase/right_awsbase.rb', line 427 def tagtext(text) ; end |
#text(text) ⇒ Object
370 371 372 373 |
# File 'lib/awsbase/right_awsbase.rb', line 370 def text(text) @text = text tagtext(text) end |