Class: SOAP::Parser

Inherits:
Object show all
Includes:
SOAP
Defined in:
lib/soap/parser.rb

Defined Under Namespace

Classes: FormatDecodeError, ParseError, ParseFrame, UnexpectedElementError

Constant Summary

Constants included from SOAP

AttrActor, AttrArrayType, AttrArrayTypeName, AttrEncodingStyle, AttrEncodingStyleName, AttrMustUnderstand, AttrMustUnderstandName, AttrOffset, AttrOffsetName, AttrPosition, AttrPositionName, AttrRoot, AttrRootName, Base64Literal, EleBody, EleBodyName, EleEnvelope, EleEnvelopeName, EleFault, EleFaultActor, EleFaultActorName, EleFaultCode, EleFaultCodeName, EleFaultDetail, EleFaultDetailName, EleFaultName, EleFaultString, EleFaultStringName, EleHeader, EleHeaderName, EncodingNamespace, EnvelopeNamespace, LiteralNamespace, MediaType, NextActor, PropertyName, SOAPNamespaceTag, TypeMap, VERSION, ValueArray, ValueArrayName, XSDNamespaceTag, XSINamespaceTag

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opt = {}) ⇒ Parser

Returns a new instance of Parser.



68
69
70
71
72
73
74
75
76
77
78
# File 'lib/soap/parser.rb', line 68

def initialize(opt = {})
  @opt = opt
  @parser = XSD::XMLParser.create_parser(self, opt)
  @parsestack = nil
  @lastnode = nil
  @handlers = {}
  @envelopenamespace = opt[:envelopenamespace] || EnvelopeNamespace
  @default_encodingstyle = opt[:default_encodingstyle] || EncodingNamespace
  @decode_typemap = opt[:decode_typemap] || nil
  @allow_unqualified_element = opt[:allow_unqualified_element] || false
end

Instance Attribute Details

#allow_unqualified_elementObject

Returns the value of attribute allow_unqualified_element.



66
67
68
# File 'lib/soap/parser.rb', line 66

def allow_unqualified_element
  @allow_unqualified_element
end

#decode_typemapObject

Returns the value of attribute decode_typemap.



65
66
67
# File 'lib/soap/parser.rb', line 65

def decode_typemap
  @decode_typemap
end

#default_encodingstyleObject

Returns the value of attribute default_encodingstyle.



64
65
66
# File 'lib/soap/parser.rb', line 64

def default_encodingstyle
  @default_encodingstyle
end

#envelopenamespaceObject

Returns the value of attribute envelopenamespace.



63
64
65
# File 'lib/soap/parser.rb', line 63

def envelopenamespace
  @envelopenamespace
end

Instance Method Details

#characters(text) ⇒ Object



135
136
137
138
139
140
141
142
143
144
# File 'lib/soap/parser.rb', line 135

def characters(text)
  lastframe = @parsestack.last
  if lastframe
    # Need not to be cloned because character does not have attr.
    decode_text(lastframe.ns, text, lastframe.encodingstyle)
  else
    # Ignore Text outside of SOAP Envelope.
    p text if $DEBUG
  end
end

#charsetObject



80
81
82
# File 'lib/soap/parser.rb', line 80

def charset
  @parser.charset
end

#end_element(name) ⇒ Object



146
147
148
149
150
151
152
153
# File 'lib/soap/parser.rb', line 146

def end_element(name)
  lastframe = @parsestack.pop
  unless name == lastframe.name
    raise UnexpectedElementError.new("Closing element name '#{ name }' does not match with opening element '#{ lastframe.name }'.")
  end
  decode_tag_end(lastframe.ns, lastframe.node, lastframe.encodingstyle)
  @lastnode = lastframe.node.node
end

#parse(string_or_readable) ⇒ Object



84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/soap/parser.rb', line 84

def parse(string_or_readable)
  @parsestack = []
  @lastnode = nil

  @handlers.each do |uri, handler|
    handler.decode_prologue
  end

  @parser.do_parse(string_or_readable)

  unless @parsestack.empty?
    raise FormatDecodeError.new("Unbalanced tag in XML.")
  end

  @handlers.each do |uri, handler|
    handler.decode_epilogue
  end

  @lastnode
end

#start_element(name, attrs) ⇒ Object



105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
# File 'lib/soap/parser.rb', line 105

def start_element(name, attrs)
  lastframe = @parsestack.last
  ns = parent = parent_encodingstyle = nil
  if lastframe
    ns = lastframe.ns.clone_ns
    parent = lastframe.node
    parent_encodingstyle = lastframe.encodingstyle
  else
    ns = XSD::NS.new
    parent = ParseFrame::NodeContainer.new(nil)
    parent_encodingstyle = nil
  end

  attrs = XSD::XMLParser.filter_ns(ns, attrs)
  encodingstyle = find_encodingstyle(ns, attrs)

  # Children's encodingstyle is derived from its parent.
  if encodingstyle.nil?
    if parent.node.is_a?(SOAPHeader)
      encodingstyle = LiteralNamespace
    else
      encodingstyle = parent_encodingstyle || @default_encodingstyle
    end
  end

  node = decode_tag(ns, name, attrs, parent, encodingstyle)

  @parsestack << ParseFrame.new(ns, name, node, encodingstyle)
end