Class: RightAws::RightAWSParser
- Inherits:
-
Object
- Object
- RightAws::RightAWSParser
- Defined in:
- lib/awsbase/right_awsbase.rb
Overview
:nodoc:
Direct Known Subclasses
AcfInterface::AcfDistributionListParser, AcfInterface::AcfInvalidationsListParser, AcfInterface::AcfOriginAccesIdentitiesListParser, AcwInterface::GetMetricStatisticsParser, AcwInterface::ListMetricsParser, AsInterface::DescribeAutoScalingGroupsParser, AsInterface::DescribeLaunchConfigurationsParser, AsInterface::DescribeScalingActivitiesParser, AsInterface::DescribeTriggersParser, Ec2::QEc2AllocateAddressParser, Ec2::QEc2AssociateAddressParser, Ec2::QEc2AttachAndDetachVolumeParser, Ec2::QEc2AttachVpnGatewayParser, Ec2::QEc2BundleInstanceParser, Ec2::QEc2CancelSpotInstanceParser, Ec2::QEc2ConfirmProductInstanceParser, Ec2::QEc2CreateKeyPairParser, Ec2::QEc2CreateSecurityGroupsParser, Ec2::QEc2CreateVolumeParser, Ec2::QEc2DescribeAddressesParser, Ec2::QEc2DescribeAvailabilityZonesParser, Ec2::QEc2DescribeBundleTasksParser, Ec2::QEc2DescribeCustomerGatewaysParser, Ec2::QEc2DescribeDhcpOptionsParser, Ec2::QEc2DescribeImageAttributeParser, Ec2::QEc2DescribeImagesParser, Ec2::QEc2DescribeInstanceAttributeParser, Ec2::QEc2DescribeInstancesParser, Ec2::QEc2DescribeInternetGatewaysParser, Ec2::QEc2DescribeKeyPairParser, Ec2::QEc2DescribeLicensesParser, Ec2::QEc2DescribePlacementGroupsParser, Ec2::QEc2DescribeRegionsParser, Ec2::QEc2DescribeReservedInstancesOfferingsParser, Ec2::QEc2DescribeReservedInstancesParser, Ec2::QEc2DescribeRouteTablesParser, Ec2::QEc2DescribeSecurityGroupsParser, Ec2::QEc2DescribeSnapshotAttributeParser, Ec2::QEc2DescribeSnapshotsParser, Ec2::QEc2DescribeSpotDatafeedSubscriptionParser, Ec2::QEc2DescribeSpotInstanceParser, Ec2::QEc2DescribeSpotPriceHistoryParser, Ec2::QEc2DescribeSubnetsParser, Ec2::QEc2DescribeTagsParser, Ec2::QEc2DescribeVolumesParser, Ec2::QEc2DescribeVpcsParser, Ec2::QEc2DescribeVpnConnectionsParser, Ec2::QEc2DescribeVpnGatewaysParser, Ec2::QEc2GetConsoleOutputParser, Ec2::QEc2GetPasswordDataParser, Ec2::QEc2ImportKeyPairParser, Ec2::QEc2MonitorInstancesParser, Ec2::QEc2PurchaseReservedInstancesOfferingParser, Ec2::QEc2RegisterImageParser, Ec2::QEc2TerminateInstancesParser, ElbInterface::AvailabilityZonesForLoadBalancerParser, ElbInterface::CreateLoadBalancerParser, ElbInterface::DeleteLoadBalancerParser, ElbInterface::DescribeInstanceHealthParser, ElbInterface::DescribeLoadBalancersParser, ElbInterface::HealthCheckParser, ElbInterface::InstancesWithLoadBalancerParser, IamInterface::BasicIamListParser, IamInterface::BasicIamParser, IamInterface::GetGroupParser, RightAws::RdsInterface::DescribeDBEngineVersionsParser, RightAws::RdsInterface::DescribeDbInstancesParser, RightAws::RdsInterface::DescribeDbParameterGroupsParser, RightAws::RdsInterface::DescribeDbParametersParser, RightAws::RdsInterface::DescribeDbSecurityGroupsParser, RightAws::RdsInterface::DescribeDbSnapshotsParser, RightAws::RdsInterface::DescribeEventsParser, RightAws::RdsInterface::DescribeOrderableDBInstanceOptionsParser, RightAws::RdsInterface::DescribeReservedDBInstancesOfferingsParser, RightAws::RdsInterface::DescribeReservedDBInstancesParser, RightBoolResponseParser, RightErrorResponseParser, RightHttp2xxParser, RightAws::Route53Interface::GetChangeParser, RightAws::Route53Interface::GetHostedZoneParser, RightAws::Route53Interface::ListHostedZonesParser, RightAws::Route53Interface::ListResourceRecordSetsParser, S3Interface::S3AclParser, S3Interface::S3BucketLocationParser, S3Interface::S3CompleteMultipartParser, S3Interface::S3CopyParser, S3Interface::S3DeleteMultipleParser, S3Interface::S3ImprovedListBucketParser, S3Interface::S3ListAllMyBucketsParser, S3Interface::S3ListBucketParser, S3Interface::S3LoggingParser, S3Interface::S3MultipartUploadInitiateResponseParser, SdbInterface::QSdbGenericParser, SdbInterface::QSdbGetAttributesParser, SdbInterface::QSdbListDomainParser, SdbInterface::QSdbQueryParser, SdbInterface::QSdbQueryWithAttributesParser, SdbInterface::QSdbSelectParser, SdbInterface::QSdbSimpleParser, SnsInterface::SnsConfirmSubscriptionParser, SnsInterface::SnsCreateTopicParser, SnsInterface::SnsGetTopicAttributesParser, SnsInterface::SnsListSubscriptionsParser, SnsInterface::SnsListTopicsParser, SnsInterface::SnsPublishParser, SnsInterface::SnsSubscribeParser, 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
- 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)
-
- (Object) full_tag_name
readonly
Returns the value of attribute full_tag_name.
-
- (Object) result
Returns the value of attribute result.
-
- (Object) tag
readonly
Returns the value of attribute tag.
-
- (Object) xml_lib
Returns the value of attribute xml_lib.
-
- (Object) xmlpath
readonly
Returns the value of attribute xmlpath.
Class Method Summary (collapse)
Instance Method Summary (collapse)
-
- (RightAWSParser) initialize(params = {})
constructor
A new instance of RightAWSParser.
-
- (Object) method_missing(method, *params)
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.
-
- (Object) parse(xml_text, params = {})
Parser method.
-
- (Object) reset
the functions to be overriden by children (if nessesery).
- - (Object) tag_end(name)
- - (Object) tag_start(name, attributes)
- - (Object) tagend(name)
- - (Object) tagstart(name, attributes)
- - (Object) tagtext(text)
- - (Object) text(text)
Constructor Details
- (RightAWSParser) initialize(params = {})
A new instance of RightAWSParser
1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 |
# File 'lib/awsbase/right_awsbase.rb', line 1202 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
- (Object) method_missing(method, *params)
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
1286 1287 1288 1289 1290 1291 1292 1293 |
# File 'lib/awsbase/right_awsbase.rb', line 1286 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
- (Object) full_tag_name (readonly)
Returns the value of attribute full_tag_name
1199 1200 1201 |
# File 'lib/awsbase/right_awsbase.rb', line 1199 def full_tag_name @full_tag_name end |
- (Object) result
Returns the value of attribute result
1196 1197 1198 |
# File 'lib/awsbase/right_awsbase.rb', line 1196 def result @result end |
- (Object) tag (readonly)
Returns the value of attribute tag
1200 1201 1202 |
# File 'lib/awsbase/right_awsbase.rb', line 1200 def tag @tag end |
- (Object) xml_lib
Returns the value of attribute xml_lib
1198 1199 1200 |
# File 'lib/awsbase/right_awsbase.rb', line 1198 def xml_lib @xml_lib end |
- (Object) xmlpath (readonly)
Returns the value of attribute xmlpath
1197 1198 1199 |
# File 'lib/awsbase/right_awsbase.rb', line 1197 def xmlpath @xmlpath end |
Class Method Details
+ (Object) xml_lib
1189 1190 1191 |
# File 'lib/awsbase/right_awsbase.rb', line 1189 def self.xml_lib @@xml_lib end |
+ (Object) xml_lib=(new_lib_name)
1192 1193 1194 |
# File 'lib/awsbase/right_awsbase.rb', line 1192 def self.xml_lib=(new_lib_name) @@xml_lib = new_lib_name end |
Instance Method Details
- (Object) parse(xml_text, params = {})
Parser method. Params:
xml_text - xml message text(String) or Net:HTTPxxx instance (response)
params[:xml_lib] - library name: 'rexml' | 'libxml'
1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 |
# File 'lib/awsbase/right_awsbase.rb', line 1232 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' # Setup SaxParserCallback if XML::Parser::VERSION >= '0.5.1' && XML::Parser::VERSION < '0.9.7' 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' if XML::Parser::VERSION >= '0.9.9' # avoid warning on every usage xml = XML::SaxParser.string(xml_text) else xml = XML::SaxParser.new xml.string = xml_text end # check libxml-ruby version if XML::Parser::VERSION >= '0.9.7' xml.callbacks = RightSaxParserCallbackNs.new(self) elsif XML::Parser::VERSION >= '0.5.1' 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 |
- (Object) reset
the functions to be overriden by children (if nessesery)
1295 |
# File 'lib/awsbase/right_awsbase.rb', line 1295 def reset ; end |
- (Object) tag_end(name)
1219 1220 1221 1222 1223 |
# File 'lib/awsbase/right_awsbase.rb', line 1219 def tag_end(name) @xmlpath = @full_tag_name[/^(.*?)\/?#{name}$/] && $1 tagend(name) @full_tag_name = @xmlpath end |
- (Object) tag_start(name, attributes)
1212 1213 1214 1215 1216 1217 1218 |
# File 'lib/awsbase/right_awsbase.rb', line 1212 def tag_start(name, attributes) @text = '' @tag = name @full_tag_name += @full_tag_name.empty? ? name : "/#{name}" (name, attributes) @xmlpath = @full_tag_name end |
- (Object) tagend(name)
1297 |
# File 'lib/awsbase/right_awsbase.rb', line 1297 def tagend(name) ; end |
- (Object) tagstart(name, attributes)
1296 |
# File 'lib/awsbase/right_awsbase.rb', line 1296 def (name, attributes); end |
- (Object) tagtext(text)
1298 |
# File 'lib/awsbase/right_awsbase.rb', line 1298 def tagtext(text) ; end |
- (Object) text(text)
1224 1225 1226 1227 |
# File 'lib/awsbase/right_awsbase.rb', line 1224 def text(text) @text += text tagtext(text) end |