Class: XMLRPC::XMLParser::AbstractTreeParser
Relationships & Source Files | |
Extension / Inclusion / Inheritance Descendants | |
Subclasses:
|
|
Inherits: | Object |
Defined in: | lib/xmlrpc/parser.rb |
Instance Method Summary
- #parseMethodCall(str)
- #parseMethodResponse(str)
- #array(node) private
- #assert(b) private
- #base64(node) private
- #boolean(node) private
- #data(node) private
- #dateTime(node) private
- #double(node) private
- #fault(node) private
-
#hasOnlyOneChild(node, name = nil)
private
Returns, when successfully the only child-node.
- #integer(node) private
- #member(node) private
- #methodCall(node) private
- #methodName(node) private
- #methodResponse(node) private
- #name(node) private
- #nodeMustBe(node, name) private
- #param(node) private
- #params(node, call = true) private
-
#removeWhitespacesAndComments(node)
private
Removes all whitespaces but in the tags i4, i8, int, boolean.…
- #string(node) private
- #struct(node) private
-
#text(node)
private
_nodeType is defined in the subclass.
-
#text_zero_one(node)
private
The node
node
has empty string or string. - #v_nil(node) private
- #value(node) private
Instance Method Details
#array(node) (private)
[ GitHub ]# File 'lib/xmlrpc/parser.rb', line 344
def array(node) nodeMustBe(node, "array") hasOnlyOneChild(node, "data") data(node.firstChild) end
#assert(b) (private)
[ GitHub ]# File 'lib/xmlrpc/parser.rb', line 261
def assert(b) if not b then raise "assert-fail" end end
#base64(node) (private)
[ GitHub ]# File 'lib/xmlrpc/parser.rb', line 324
def base64(node) nodeMustBe(node, "base64") #hasOnlyOneChild(node) Convert.base64(text_zero_one(node)) end
#boolean(node) (private)
[ GitHub ]# File 'lib/xmlrpc/parser.rb', line 290
def boolean(node) nodeMustBe(node, "boolean") hasOnlyOneChild(node) Convert.boolean(text(node.firstChild)) end
#data(node) (private)
[ GitHub ]# File 'lib/xmlrpc/parser.rb', line 350
def data(node) nodeMustBe(node, "data") node.childNodes.to_a.collect do |val| value(val) end end
#dateTime(node) (private)
[ GitHub ]# File 'lib/xmlrpc/parser.rb', line 317
def dateTime(node) nodeMustBe(node, "dateTime.iso8601") hasOnlyOneChild(node) Convert.dateTime( text(node.firstChild) ) end
#double(node) (private)
[ GitHub ]# File 'lib/xmlrpc/parser.rb', line 308
def double(node) #TODO: check string for float because to_f returnsa # 0.0 when wrong string nodeMustBe(node, "double") hasOnlyOneChild(node) Convert.double(text(node.firstChild)) end
#fault(node) (private)
[ GitHub ]# File 'lib/xmlrpc/parser.rb', line 399
def fault(node) nodeMustBe(node, "fault") hasOnlyOneChild(node, "value") f = value(node.firstChild) Convert.fault(f) end
#hasOnlyOneChild(node, name = nil) (private)
Returns, when successfully the only child-node
# File 'lib/xmlrpc/parser.rb', line 251
def hasOnlyOneChild(node, name=nil) if node.childNodes.to_a.size != 1 raise "wrong xml-rpc (size)" end if name != nil then nodeMustBe(node.firstChild, name) end end
#integer(node) (private)
[ GitHub ]# File 'lib/xmlrpc/parser.rb', line 281
def integer(node) #TODO: check string for float because to_i returnsa # 0 when wrong string nodeMustBe(node, %w(i4 i8 int)) hasOnlyOneChild(node) Convert.int(text(node.firstChild)) end
#member(node) (private)
[ GitHub ]# File 'lib/xmlrpc/parser.rb', line 331
def member(node) nodeMustBe(node, "member") assert( node.childNodes.to_a.size == 2 ) [ name(node[0]), value(node[1]) ] end
#methodCall(node) (private)
[ GitHub ]# File 'lib/xmlrpc/parser.rb', line 469
def methodCall(node) nodeMustBe(node, "methodCall") assert( (1..2).include?( node.childNodes.to_a.size ) ) name = methodName(node[0]) if node.childNodes.to_a.size == 2 then pa = params(node[1]) else # no parameters given pa = [] end [name, pa] end
#methodName(node) (private)
[ GitHub ]# File 'lib/xmlrpc/parser.rb', line 380
def methodName(node) nodeMustBe(node, "methodName") hasOnlyOneChild(node) text(node.firstChild) end
#methodResponse(node) (private)
[ GitHub ]# File 'lib/xmlrpc/parser.rb', line 364
def methodResponse(node) nodeMustBe(node, "methodResponse") hasOnlyOneChild(node, %w(params fault)) child = node.firstChild case child.nodeName when "params" [ true, params(child,false) ] when "fault" [ false, fault(child) ] else raise "unexpected error" end end
#name(node) (private)
[ GitHub ]# File 'lib/xmlrpc/parser.rb', line 338
def name(node) nodeMustBe(node, "name") #hasOnlyOneChild(node) text_zero_one(node) end
#nodeMustBe(node, name) (private)
[ GitHub ]#param(node) (private)
[ GitHub ]# File 'lib/xmlrpc/parser.rb', line 358
def param(node) nodeMustBe(node, "param") hasOnlyOneChild(node, "value") value(node.firstChild) end
#params(node, call = true) (private)
[ GitHub ]# File 'lib/xmlrpc/parser.rb', line 386
def params(node, call=true) nodeMustBe(node, "params") if call node.childNodes.to_a.collect do |n| param(n) end else # response (only one param) hasOnlyOneChild(node) param(node.firstChild) end end
#parseMethodCall(str)
[ GitHub ]# File 'lib/xmlrpc/parser.rb', line 197
def parseMethodCall(str) methodCall_document(createCleanedTree(str)) end
#parseMethodResponse(str)
[ GitHub ]# File 'lib/xmlrpc/parser.rb', line 193
def parseMethodResponse(str) methodResponse_document(createCleanedTree(str)) end
#removeWhitespacesAndComments(node) (private)
Removes all whitespaces but in the tags i4, i8, int, boolean.… and all comments
# File 'lib/xmlrpc/parser.rb', line 205
def removeWhitespacesAndComments(node) remove = [] childs = node.childNodes.to_a childs.each do |nd| case _nodeType(nd) when :TEXT # TODO: add nil? unless %w(i4 i8 int boolean string double dateTime.iso8601 base64).include? node.nodeName if node.nodeName == "value" if not node.childNodes.to_a.detect {|n| _nodeType(n) == :ELEMENT}.nil? remove << nd if nd.nodeValue.strip == "" end else remove << nd if nd.nodeValue.strip == "" end end when :COMMENT remove << nd else removeWhitespacesAndComments(nd) end end remove.each { |i| node.removeChild(i) } end
#string(node) (private)
[ GitHub ]# File 'lib/xmlrpc/parser.rb', line 303
def string(node) nodeMustBe(node, "string") text_zero_one(node) end
#struct(node) (private)
[ GitHub ]# File 'lib/xmlrpc/parser.rb', line 417
def struct(node) nodeMustBe(node, "struct") hash = {} node.childNodes.to_a.each do |me| n, v = member(me) hash[n] = v end Convert.struct(hash) end
#text(node) (private)
_nodeType is defined in the subclass
#text_zero_one(node) (private)
The node node
has empty string or string
# File 'lib/xmlrpc/parser.rb', line 268
def text_zero_one(node) nodes = node.childNodes.to_a.size if nodes == 1 text(node.firstChild) elsif nodes == 0 "" else raise "wrong xml-rpc (size)" end end
#v_nil(node) (private)
[ GitHub ]# File 'lib/xmlrpc/parser.rb', line 297
def v_nil(node) nodeMustBe(node, "nil") assert( node.childNodes.to_a.size == 0 ) nil end
#value(node) (private)
[ GitHub ]# File 'lib/xmlrpc/parser.rb', line 430
def value(node) nodeMustBe(node, "value") nodes = node.childNodes.to_a.size if nodes == 0 return "" elsif nodes > 1 raise "wrong xml-rpc (size)" end child = node.firstChild case _nodeType(child) when :TEXT text_zero_one(node) when :ELEMENT case child.nodeName when "i4", "i8", "int" then integer(child) when "boolean" then boolean(child) when "string" then string(child) when "double" then double(child) when "dateTime.iso8601" then dateTime(child) when "base64" then base64(child) when "struct" then struct(child) when "array" then array(child) when "nil" if Config::ENABLE_NIL_PARSER v_nil(child) else raise "wrong/unknown XML-RPC type 'nil'" end else raise "wrong/unknown XML-RPC type" end else raise "wrong type of node" end end