class XMLRPC::XMLParser::AbstractTreeParser
Public Instance Methods
parseMethodCall(str)
click to toggle source
# File lib/xmlrpc/parser.rb, line 196 def parseMethodCall(str) methodCall_document(createCleanedTree(str)) end
parseMethodResponse(str)
click to toggle source
# File lib/xmlrpc/parser.rb, line 192 def parseMethodResponse(str) methodResponse_document(createCleanedTree(str)) end
Private Instance Methods
array(node)
click to toggle source
# File lib/xmlrpc/parser.rb, line 343 def array(node) nodeMustBe(node, "array") hasOnlyOneChild(node, "data") data(node.firstChild) end
assert(b)
click to toggle source
# File lib/xmlrpc/parser.rb, line 260 def assert(b) if not b then raise "assert-fail" end end
base64(node)
click to toggle source
# File lib/xmlrpc/parser.rb, line 323 def base64(node) nodeMustBe(node, "base64") #hasOnlyOneChild(node) Convert.base64(text_zero_one(node)) end
boolean(node)
click to toggle source
# File lib/xmlrpc/parser.rb, line 289 def boolean(node) nodeMustBe(node, "boolean") hasOnlyOneChild(node) Convert.boolean(text(node.firstChild)) end
data(node)
click to toggle source
# File lib/xmlrpc/parser.rb, line 349 def data(node) nodeMustBe(node, "data") node.childNodes.to_a.collect do |val| value(val) end end
dateTime(node)
click to toggle source
# File lib/xmlrpc/parser.rb, line 316 def dateTime(node) nodeMustBe(node, "dateTime.iso8601") hasOnlyOneChild(node) Convert.dateTime( text(node.firstChild) ) end
double(node)
click to toggle source
# File lib/xmlrpc/parser.rb, line 307 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)
click to toggle source
# File lib/xmlrpc/parser.rb, line 398 def fault(node) nodeMustBe(node, "fault") hasOnlyOneChild(node, "value") f = value(node.firstChild) Convert.fault(f) end
hasOnlyOneChild(node, name=nil)
click to toggle source
Returns, when successfully the only child-node
# File lib/xmlrpc/parser.rb, line 250 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)
click to toggle source
# File lib/xmlrpc/parser.rb, line 280 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)
click to toggle source
# File lib/xmlrpc/parser.rb, line 330 def member(node) nodeMustBe(node, "member") assert( node.childNodes.to_a.size == 2 ) [ name(node[0]), value(node[1]) ] end
methodCall(node)
click to toggle source
# File lib/xmlrpc/parser.rb, line 468 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)
click to toggle source
# File lib/xmlrpc/parser.rb, line 379 def methodName(node) nodeMustBe(node, "methodName") hasOnlyOneChild(node) text(node.firstChild) end
methodResponse(node)
click to toggle source
# File lib/xmlrpc/parser.rb, line 363 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)
click to toggle source
# File lib/xmlrpc/parser.rb, line 337 def name(node) nodeMustBe(node, "name") #hasOnlyOneChild(node) text_zero_one(node) end
nodeMustBe(node, name)
click to toggle source
# File lib/xmlrpc/parser.rb, line 232 def nodeMustBe(node, name) cmp = case name when Array name.include?(node.nodeName) when String name == node.nodeName else raise "error" end if not cmp then raise "wrong xml-rpc (name)" end node end
param(node)
click to toggle source
# File lib/xmlrpc/parser.rb, line 357 def param(node) nodeMustBe(node, "param") hasOnlyOneChild(node, "value") value(node.firstChild) end
params(node, call=true)
click to toggle source
# File lib/xmlrpc/parser.rb, line 385 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
removeWhitespacesAndComments(node)
click to toggle source
Removes all whitespaces but in the tags i4, i8, int, boolean.… and all comments
# File lib/xmlrpc/parser.rb, line 204 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)
click to toggle source
# File lib/xmlrpc/parser.rb, line 302 def string(node) nodeMustBe(node, "string") text_zero_one(node) end
struct(node)
click to toggle source
# File lib/xmlrpc/parser.rb, line 416 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)
click to toggle source
_nodeType is defined in the subclass
# File lib/xmlrpc/parser.rb, line 408 def text(node) assert( _nodeType(node) == :TEXT ) assert( node.hasChildNodes == false ) assert( node.nodeValue != nil ) node.nodeValue.to_s end
text_zero_one(node)
click to toggle source
The node `node` has empty string or string
# File lib/xmlrpc/parser.rb, line 267 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)
click to toggle source
# File lib/xmlrpc/parser.rb, line 296 def v_nil(node) nodeMustBe(node, "nil") assert( node.childNodes.to_a.size == 0 ) nil end
value(node)
click to toggle source
# File lib/xmlrpc/parser.rb, line 429 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