Class: RightAws::RightAWSParser
Overview
:nodoc:
Direct Known Subclasses
AcfInterface::AcfDistributionListParser, AcwInterface::GetMetricStatisticsParser, AcwInterface::ListMetricsParser, AsInterface::DescribeAutoScalingGroupsParser, AsInterface::DescribeLaunchConfigurationsParser, AsInterface::DescribeScalingActivitiesParser, AsInterface::DescribeTriggersParser, Ec2::QEc2AllocateAddressParser, Ec2::QEc2CreateKeyPairParser, Ec2::QEc2DescribeAddressesParser, Ec2::QEc2DescribeAvailabilityZonesParser, Ec2::QEc2DescribeKeyPairParser, Ec2::QEc2DescribeRegionsParser, Ec2::QEc2DescribeSecurityGroupsParser, Ec2::RightBoolResponseParser, ElbInterface::AvailabilityZonesForLoadBalancerParser, ElbInterface::CreateLoadBalancerParser, ElbInterface::DeleteLoadBalancerParser, ElbInterface::DescribeInstanceHealthParser, ElbInterface::DescribeLoadBalancersParser, ElbInterface::HealthCheckParser, ElbInterface::InstancesWithLoadBalancerParser, RightErrorResponseParser, RightHttp2xxParser, S3Interface::S3AclParser, S3Interface::S3BucketLocationParser, S3Interface::S3CopyParser, S3Interface::S3ImprovedListBucketParser, S3Interface::S3ListAllMyBucketsParser, S3Interface::S3ListBucketParser, S3Interface::S3LoggingParser, SdbInterface::QSdbGetAttributesParser, SdbInterface::QSdbListDomainParser, SdbInterface::QSdbQueryParser, SdbInterface::QSdbQueryWithAttributesParser, SdbInterface::QSdbSelectParser, SdbInterface::QSdbSimpleParser, SqsGen2Interface::SqsCreateQueueParser, SqsGen2Interface::SqsGetQueueAttributesParser, SqsGen2Interface::SqsListQueuesParser, SqsGen2Interface::SqsReceiveMessageParser, SqsGen2Interface::SqsSendMessagesParser, SqsGen2Interface::SqsStatusParser, 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
-
#full_tag_name ⇒ Object
readonly
Returns the value of attribute full_tag_name.
-
#result ⇒ Object
Returns the value of attribute result.
-
#tag ⇒ Object
readonly
Returns the value of attribute tag.
-
#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.
791 792 793 794 795 796 797 798 799 800 |
# File 'lib/awsbase/right_awsbase.rb', line 791 def initialize(params={}) @xmlpath = '' @full_tag_name = '' @result = false @text = '' @tag = '' @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
867 868 869 870 871 872 873 874 |
# File 'lib/awsbase/right_awsbase.rb', line 867 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
#full_tag_name ⇒ Object (readonly)
Returns the value of attribute full_tag_name.
788 789 790 |
# File 'lib/awsbase/right_awsbase.rb', line 788 def full_tag_name @full_tag_name end |
#result ⇒ Object
Returns the value of attribute result.
785 786 787 |
# File 'lib/awsbase/right_awsbase.rb', line 785 def result @result end |
#tag ⇒ Object (readonly)
Returns the value of attribute tag.
789 790 791 |
# File 'lib/awsbase/right_awsbase.rb', line 789 def tag @tag end |
#xml_lib ⇒ Object
Returns the value of attribute xml_lib.
787 788 789 |
# File 'lib/awsbase/right_awsbase.rb', line 787 def xml_lib @xml_lib end |
#xmlpath ⇒ Object (readonly)
Returns the value of attribute xmlpath.
786 787 788 |
# File 'lib/awsbase/right_awsbase.rb', line 786 def xmlpath @xmlpath end |
Class Method Details
.xml_lib ⇒ Object
778 779 780 |
# File 'lib/awsbase/right_awsbase.rb', line 778 def self.xml_lib @@xml_lib end |
.xml_lib=(new_lib_name) ⇒ Object
781 782 783 |
# File 'lib/awsbase/right_awsbase.rb', line 781 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'
821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 |
# File 'lib/awsbase/right_awsbase.rb', line 821 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)
876 |
# File 'lib/awsbase/right_awsbase.rb', line 876 def reset ; end |
#tag_end(name) ⇒ Object
808 809 810 811 812 |
# File 'lib/awsbase/right_awsbase.rb', line 808 def tag_end(name) @xmlpath = @full_tag_name[/^(.*?)\/?#{name}$/] && $1 tagend(name) @full_tag_name = @xmlpath end |
#tag_start(name, attributes) ⇒ Object
801 802 803 804 805 806 807 |
# File 'lib/awsbase/right_awsbase.rb', line 801 def tag_start(name, attributes) @text = '' @tag = name @full_tag_name += @full_tag_name.empty? ? name : "/#{name}" (name, attributes) @xmlpath = @full_tag_name end |
#tagend(name) ⇒ Object
878 |
# File 'lib/awsbase/right_awsbase.rb', line 878 def tagend(name) ; end |
#tagstart(name, attributes) ⇒ Object
877 |
# File 'lib/awsbase/right_awsbase.rb', line 877 def (name, attributes); end |
#tagtext(text) ⇒ Object
879 |
# File 'lib/awsbase/right_awsbase.rb', line 879 def tagtext(text) ; end |
#text(text) ⇒ Object
813 814 815 816 |
# File 'lib/awsbase/right_awsbase.rb', line 813 def text(text) @text += text tagtext(text) end |