Class: Aws::AwsParser
Overview
:nodoc:
Direct Known Subclasses
Aws::AcfInterface::AcfDistributionConfigParser, Aws::AcfInterface::AcfDistributionListParser, Aws::AcfInterface::AcfDistributionParser, Ec2::QEc2AllocateAddressParser, Ec2::QEc2AttachAndDetachVolumeParser, Ec2::QEc2BundleInstanceParser, Ec2::QEc2ConfirmProductInstanceParser, Ec2::QEc2CreateKeyPairParser, Ec2::QEc2CreateSnapshotParser, Ec2::QEc2CreateVolumeParser, Ec2::QEc2DescribeAddressesParser, Ec2::QEc2DescribeAvailabilityZonesParser, Ec2::QEc2DescribeBundleTasksParser, Ec2::QEc2DescribeImageAttributeParser, Ec2::QEc2DescribeImagesParser, Ec2::QEc2DescribeInstancesParser, Ec2::QEc2DescribeKeyPairParser, Ec2::QEc2DescribeRegionsParser, Ec2::QEc2DescribeSecurityGroupsParser, Ec2::QEc2DescribeSnapshotsParser, Ec2::QEc2DescribeTagsParser, Ec2::QEc2DescribeVolumesParser, Ec2::QEc2GetConsoleOutputParser, Ec2::QEc2MonitorInstancesParser, Ec2::QEc2RegisterImageParser, Ec2::QEc2TerminateInstancesParser, Ec2::RightBoolResponseParser, Elb::QElbCreateParser, Elb::QElbDeleteParser, Elb::QElbDescribeInstancesHealthParser, Elb::QElbDescribeLoadBalancersParser, Elb::QElbRegisterInstancesParser, Mon::QMonGetMetricStatistics, Mon::QMonListMetrics, RightErrorResponseParser, RightHttp2xxParser, S3Interface::S3AclParser, S3Interface::S3BucketLocationParser, S3Interface::S3CopyParser, S3Interface::S3ImprovedListBucketParser, S3Interface::S3ListAllMyBucketsParser, S3Interface::S3ListBucketParser, S3Interface::S3LoggingParser, SdbInterface::QSdbDomainMetadataParser, SdbInterface::QSdbGetAttributesParser, SdbInterface::QSdbListDomainParser, SdbInterface::QSdbQueryParser, SdbInterface::QSdbQueryWithAttributesParser, SdbInterface::QSdbSelectParser, SdbInterface::QSdbSimpleParser, SqsInterface::SqsCreateQueueParser, SqsInterface::SqsGetQueueAttributesParser, SqsInterface::SqsListQueuesParser, SqsInterface::SqsReceiveMessageParser, 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 = {}) ⇒ AwsParser
constructor
A new instance of AwsParser.
-
#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 AwsParser 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 = {}) ⇒ AwsParser
Returns a new instance of AwsParser.
1078 1079 1080 1081 1082 1083 1084 1085 |
# File 'lib/awsbase/right_awsbase.rb', line 1078 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 AwsParser and method_missing helps us to skip their definition
1158 1159 1160 1161 1162 1163 1164 1165 |
# File 'lib/awsbase/right_awsbase.rb', line 1158 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.
1074 1075 1076 |
# File 'lib/awsbase/right_awsbase.rb', line 1074 def result @result end |
#xml_lib ⇒ Object
Returns the value of attribute xml_lib.
1076 1077 1078 |
# File 'lib/awsbase/right_awsbase.rb', line 1076 def xml_lib @xml_lib end |
#xmlpath ⇒ Object (readonly)
Returns the value of attribute xmlpath.
1075 1076 1077 |
# File 'lib/awsbase/right_awsbase.rb', line 1075 def xmlpath @xmlpath end |
Class Method Details
.xml_lib ⇒ Object
1066 1067 1068 |
# File 'lib/awsbase/right_awsbase.rb', line 1066 def self.xml_lib @@xml_lib end |
.xml_lib=(new_lib_name) ⇒ Object
1070 1071 1072 |
# File 'lib/awsbase/right_awsbase.rb', line 1070 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'
1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 |
# File 'lib/awsbase/right_awsbase.rb', line 1109 def parse(xml_text, params={}) # Get response body unless xml_text.is_a?(String) xml_text = xml_text.body.respond_to?(:force_encoding) ? xml_text.body.force_encoding("UTF-8") : xml_text.body end @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.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)
1168 1169 |
# File 'lib/awsbase/right_awsbase.rb', line 1168 def reset; end |
#tag_end(name) ⇒ Object
1093 1094 1095 1096 1097 1098 |
# File 'lib/awsbase/right_awsbase.rb', line 1093 def tag_end(name) if @xmlpath =~ /^(.*?)\/?#{name}$/ @xmlpath = $1 end tagend(name) end |
#tag_start(name, attributes) ⇒ Object
1087 1088 1089 1090 1091 |
# File 'lib/awsbase/right_awsbase.rb', line 1087 def tag_start(name, attributes) @text = '' (name, attributes) @xmlpath += @xmlpath.empty? ? name : "/#{name}" end |
#tagend(name) ⇒ Object
1175 1176 1177 |
# File 'lib/awsbase/right_awsbase.rb', line 1175 def tagend(name) ; end |
#tagstart(name, attributes) ⇒ Object
1171 1172 1173 |
# File 'lib/awsbase/right_awsbase.rb', line 1171 def (name, attributes) ; end |
#tagtext(text) ⇒ Object
1179 1180 1181 |
# File 'lib/awsbase/right_awsbase.rb', line 1179 def tagtext(text) ; end |
#text(text) ⇒ Object
1100 1101 1102 1103 |
# File 'lib/awsbase/right_awsbase.rb', line 1100 def text(text) @text += text tagtext(text) end |