summaryrefslogtreecommitdiff
path: root/lib/xmlrpc/parser.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/xmlrpc/parser.rb')
-rw-r--r--lib/xmlrpc/parser.rb68
1 files changed, 47 insertions, 21 deletions
diff --git a/lib/xmlrpc/parser.rb b/lib/xmlrpc/parser.rb
index 5db139e751..29366017bc 100644
--- a/lib/xmlrpc/parser.rb
+++ b/lib/xmlrpc/parser.rb
@@ -1,6 +1,3 @@
-#
-# Parser for XML-RPC call and response
-#
# Copyright (C) 2001, 2002, 2003 by Michael Neumann (mneumann@ntecs.de)
#
# $Id$
@@ -12,7 +9,6 @@ require "xmlrpc/base64"
require "xmlrpc/datetime"
-# add some methods to NQXML::Node
module NQXML
class Node
@@ -49,28 +45,41 @@ module NQXML
end # class Node
end # module NQXML
-module XMLRPC
+module XMLRPC # :nodoc:
+ # Raised when the remote procedure returns a fault-structure, which has two
+ # accessor-methods +faultCode+ an Integer, and +faultString+ a String.
class FaultException < StandardError
attr_reader :faultCode, :faultString
+ # Creates a new XMLRPC::FaultException instance.
+ #
+ # +faultString+ is passed to StandardError as the +msg+ of the Exception.
def initialize(faultCode, faultString)
@faultCode = faultCode
@faultString = faultString
super(@faultString)
end
- # returns a hash
+ # The +faultCode+ and +faultString+ of the exception in a Hash.
def to_h
{"faultCode" => @faultCode, "faultString" => @faultString}
end
end
+ # Helper class used to convert types.
module Convert
+
+ # Converts a String to an Integer
+ #
+ # See also String.to_i
def self.int(str)
str.to_i
end
+ # Converts a String to +true+ or +false+
+ #
+ # Raises an exception if +str+ is not +0+ or +1+
def self.boolean(str)
case str
when "0" then false
@@ -80,10 +89,18 @@ module XMLRPC
end
end
+ # Converts a String to a Float
+ #
+ # See also String.to_f
def self.double(str)
str.to_f
end
+ # Converts a the given +str+ to a +dateTime.iso8601+ formatted date.
+ #
+ # Raises an exception if the String isn't in +dateTime.iso8601+ format.
+ #
+ # See also, XMLRPC::DateTime
def self.dateTime(str)
case str
when /^(-?\d\d\d\d)-?(\d\d)-?(\d\d)T(\d\d):(\d\d):(\d\d)(?:Z|([+-])(\d\d):?(\d\d))?$/
@@ -114,12 +131,16 @@ module XMLRPC
end
end
+ # Decodes the given +str+ using XMLRPC::Base64.decode
def self.base64(str)
XMLRPC::Base64.decode(str)
end
+ # Converts the given +hash+ to a marshalled object.
+ #
+ # Returns the given +hash+ if an exception occurs.
def self.struct(hash)
- # convert to marhalled object
+ # convert to marshalled object
klass = hash["___class___"]
if klass.nil? or Config::ENABLE_MARSHALLING == false
hash
@@ -141,6 +162,15 @@ module XMLRPC
end
end
+ # Converts the given +hash+ to an XMLRPC::FaultException object by passing
+ # the +faultCode+ and +faultString+ attributes of the Hash to
+ # XMLRPC::FaultException.new
+ #
+ # Raises an Exception if the given +hash+ doesn't meet the requirements.
+ # Those requirements being:
+ # * 2 keys
+ # * <code>'faultCode'</code> key is an Integer
+ # * <code>'faultString'</code> key is a String
def self.fault(hash)
if hash.kind_of? Hash and hash.size == 2 and
hash.has_key? "faultCode" and hash.has_key? "faultString" and
@@ -154,6 +184,7 @@ module XMLRPC
end # module Convert
+ # Parser for XML-RPC call and response
module XMLParser
class AbstractTreeParser
@@ -168,10 +199,8 @@ module XMLRPC
private
- #
- # remove all whitespaces but in the tags i4, i8, int, boolean....
+ # Removes all whitespaces but in the tags i4, i8, int, boolean....
# and all comments
- #
def removeWhitespacesAndComments(node)
remove = []
childs = node.childNodes.to_a
@@ -217,9 +246,7 @@ module XMLRPC
node
end
- #
- # returns, when successfully the only child-node
- #
+ # Returns, when successfully the only child-node
def hasOnlyOneChild(node, name=nil)
if node.childNodes.to_a.size != 1
raise "wrong xml-rpc (size)"
@@ -236,7 +263,7 @@ module XMLRPC
end
end
- # the node `node` has empty string or string
+ # The node `node` has empty string or string
def text_zero_one(node)
nodes = node.childNodes.to_a.size
@@ -575,7 +602,6 @@ module XMLRPC
end # module StreamParserMixin
- # ---------------------------------------------------------------------------
class XMLStreamParser < AbstractStreamParser
def initialize
require "xmlparser"
@@ -584,7 +610,7 @@ module XMLRPC
}
end
end # class XMLStreamParser
- # ---------------------------------------------------------------------------
+
class NQXMLStreamParser < AbstractStreamParser
def initialize
require "nqxml/streamingparser"
@@ -613,7 +639,7 @@ module XMLRPC
end # class XMLRPCParser
end # class NQXMLStreamParser
- # ---------------------------------------------------------------------------
+
class XMLTreeParser < AbstractTreeParser
def initialize
@@ -665,7 +691,7 @@ module XMLRPC
end
end # class XMLParser
- # ---------------------------------------------------------------------------
+
class NQXMLTreeParser < AbstractTreeParser
def initialize
@@ -693,7 +719,7 @@ module XMLRPC
end
end # class NQXMLTreeParser
- # ---------------------------------------------------------------------------
+
class REXMLStreamParser < AbstractStreamParser
def initialize
require "rexml/document"
@@ -718,7 +744,7 @@ module XMLRPC
end
end
- # ---------------------------------------------------------------------------
+
class XMLScanStreamParser < AbstractStreamParser
def initialize
require "xmlscan/parser"
@@ -787,7 +813,7 @@ module XMLRPC
end
end
- # ---------------------------------------------------------------------------
+
XMLParser = XMLTreeParser
NQXMLParser = NQXMLTreeParser