lib/openwfe/rest/xmlcodec.rb in openwferu-0.9.5 vs lib/openwfe/rest/xmlcodec.rb in openwferu-0.9.6
- old
+ new
@@ -35,31 +35,39 @@
#
# "hecho en Costa Rica"
#
-#require 'base64'
require 'rexml/document'
require 'openwfe/utils'
require 'openwfe/workitem'
require 'openwfe/flowexpressionid'
require 'openwfe/rest/definitions'
module OpenWFE
+ #
+ # Ugly XML codec for OpenWFE workitems
+ #
class XmlCodec
#
# Takes as input some XML element and returns is decoded
# (as an instance)
#
def decode (xmlElt)
- return nil if not xmlElt
+ return nil unless xmlElt
+ if xmlElt.kind_of? String
+
+ xmlElt = REXML::Document.new(xmlElt)
+ xmlElt = xmlElt.root
+ end
+
#puts "decode() xmlElt.name is >#{xmlElt.name}<"
return decode_list(xmlElt) if xmlElt.name == STORES
return decode_store(xmlElt) if xmlElt.name == STORE
return decode_list(xmlElt) if xmlElt.name == HEADERS
@@ -75,10 +83,12 @@
return decode_fei(xmlElt) \
if xmlElt.name == FLOW_EXPRESSION_ID
return decode_inflowworkitem(xmlElt) \
if xmlElt.name == IN_FLOW_WORKITEM
+ return decode_launchitem(xmlElt) \
+ if xmlElt.name == LAUNCHITEM
return decode_list(xmlElt) if xmlElt.name == LAUNCHABLES
return decode_launchable(xmlElt) if xmlElt.name == LAUNCHABLE
return decode_list(xmlElt) if xmlElt.name == EXPRESSIONS
@@ -238,16 +248,16 @@
end
return map
end
- #puts xmldoc_to_string(xmlElt.document())
+ #puts OpenWFE.xmldoc_to_string(xmlElt.document())
raise \
ArgumentError, \
"Cannot decode <#{xmlElt.name}/> in \n"+\
- xmldoc_to_string(xmlElt.document())
+ OpenWFE.xmldoc_to_string(xmlElt.document())
end
def decode_entry (xmlElt, map)
key = xmlElt.elements[1]
@@ -321,10 +331,24 @@
return wi
end
+ def decode_launchitem (xmlElt)
+
+ li = LaunchItem.new()
+
+ li.workflow_definition_url =
+ xmlElt.attributes[WORKFLOW_DEFINITION_URL]
+
+ li.attributes =
+ decode(OpenWFE.first_element(xmlElt, ATTRIBUTES))
+
+ li
+ end
+
+
#
# ENCODE
#
@@ -342,11 +366,11 @@
def encode_launchitem (launchitem)
doc = REXML::Document.new()
- root = REXML::Element.new(E_LAUNCHITEM)
+ root = REXML::Element.new(LAUNCHITEM)
encode_item(launchitem, root)
root.attributes[WORKFLOW_DEFINITION_URL] = \
launchitem.workflow_definition_url
@@ -548,18 +572,30 @@
return elt
end
end
XMLCODEC = XmlCodec.new
+ #
+ # some kind of a singleton, rather a lonelyton
+ #
+ # Decodes any XML blurb produced by OpenWFE[ja] into a Ruby instance.
+ #
def OpenWFE.xml_decode (xmlelt)
XMLCODEC.decode(xmlelt)
end
+ #
+ # Encodes to XML (OpenWFE dialect ;) ) workitems and launch items.
+ #
def OpenWFE.xml_encode (owfedata)
XMLCODEC.encode(owfedata)
end
+ #
+ # Just turns some XML to a String (if decl is set to false, no
+ # XML declaration will be printed).
+ #
def OpenWFE.xmldoc_to_string (xml, decl=true)
s = ""
if decl and xml[0].kind_of? REXML::XMLDecl