lib/openwfe/rest/xmlcodec.rb in openwferu-0.9.9 vs lib/openwfe/rest/xmlcodec.rb in openwferu-0.9.10

- old
+ new

@@ -35,10 +35,11 @@ # # "hecho en Costa Rica" # +require 'base64' require 'rexml/document' require 'openwfe/utils' require 'openwfe/workitem' require 'openwfe/flowexpressionid' @@ -60,11 +61,15 @@ return nil unless xmlElt if xmlElt.kind_of? String - xmlElt = REXML::Document.new(xmlElt) + xmlElt = REXML::Document.new( + xmlElt, + :compress_whitespace => :all, + :ignore_whitespace_nodes => :all) + xmlElt = xmlElt.root end #puts "decode() xmlElt.name is >#{xmlElt.name}<" @@ -143,11 +148,11 @@ launchable = Launchable.new() launchable.url = xmlElt.attributes[URL] launchable.engine_id = xmlElt.attributes[ENGINE_ID] - return launchable + launchable end def decode_expression (xmlElt) @@ -208,35 +213,45 @@ fei.expression_id = xmlElt.attributes[EXPRESSION_ID] #puts " ... fei.expressionName is >#{fei.expressionName}<" #puts " ... fei.wfid is >#{fei.workflowInstanceId}<" - return fei + fei end def decode_attribute (xmlElt) #puts "decodeAttribute() '#{xmlElt.name}' --> '#{xmlElt.text}'" # # atomic types - return xmlElt.text if xmlElt.name == E_STRING - return Integer(xmlElt.text) if xmlElt.name == E_INTEGER - return Integer(xmlElt.text) if xmlElt.name == E_LONG - return Float(xmlElt.text) if xmlElt.name == E_DOUBLE - return parse_boolean(xmlElt.text) if xmlElt.name == E_BOOLEAN + return xmlElt.text \ + if xmlElt.name == E_STRING + return Integer(xmlElt.text) \ + if xmlElt.name == E_INTEGER + return Integer(xmlElt.text) \ + if xmlElt.name == E_LONG + return Float(xmlElt.text) \ + if xmlElt.name == E_DOUBLE + return parse_boolean(xmlElt.text) \ + if xmlElt.name == E_BOOLEAN - return xmlElt if xmlElt.name == E_XML + return decode_xmldocument(xmlElt) \ + if xmlElt.name == E_XML_DOCUMENT + return xmlElt.children[0] \ + if xmlElt.name == E_RAW_XML - return Base64Attribute.new(xmlElt.txt) if xmlElt.name == E_BASE64 + return Base64Attribute.new(xmlElt.text) \ + if xmlElt.name == E_BASE64 # # composite types - return decode_list(xmlElt) if xmlElt.name == E_LIST + return decode_list(xmlElt) \ + if xmlElt.name == E_LIST if xmlElt.name == E_SMAP or xmlElt.name == E_MAP map = {} map[MAP_TYPE] = xmlElt.name @@ -256,10 +271,16 @@ ArgumentError, \ "Cannot decode <#{xmlElt.name}/> in \n"+\ OpenWFE.xmldoc_to_string(xmlElt.document()) end + def decode_xmldocument (xmlElt) + + s = Base64::decode64 xmlElt.text.strip + REXML::Document.new s + end + def decode_entry (xmlElt, map) key = xmlElt.elements[1] val = xmlElt.elements[2] @@ -450,29 +471,31 @@ def encode_attribute (att) #puts "encodeAttribute() att.class is #{att.class}" return encode_atomicattribute(E_STRING, att) \ - if att.kind_of? String + if att.kind_of?(String) return encode_atomicattribute(E_INTEGER, att) \ - if att.kind_of? Fixnum + if att.kind_of?(Fixnum) return encode_atomicattribute(E_DOUBLE, att) \ - if att.kind_of? Float + if att.kind_of?(Float) + return encode_xmldocument(att) \ + if att.kind_of?(REXML::Document) return encode_xmlattribute(att) \ - if att.kind_of? REXML::Element + if att.kind_of?(REXML::Element) return encode_atomicattribute(E_BOOLEAN, true) \ - if att.kind_of? TrueClass + if att.kind_of?(TrueClass) return encode_atomicattribute(E_BOOLEAN, false) \ - if att.kind_of? FalseClass + if att.kind_of?(FalseClass) return encode_base64attribute(att) \ - if att.kind_of? Base64Attribute + if att.kind_of?(Base64Attribute) - return encode_mapattribute(att) if att.kind_of? Hash - return encode_listattribute(att) if att.kind_of? Array + return encode_mapattribute(att) if att.kind_of?(Hash) + return encode_listattribute(att) if att.kind_of?(Array) # # default encode_atomicattribute(E_STRING, att) @@ -480,40 +503,46 @@ #raise \ # ArgumentError, \ # "Cannot encode attribute of class '#{att.class}'" end + def encode_xmldocument (elt) + e = REXML::Element.new(E_XML_DOCUMENT) + e.text = Base64::encode64(elt.to_s) + e + end + def encode_xmlattribute (elt) - return elt if elt.name == E_XML + return elt if elt.name == E_RAW_XML # # else, wrap within <raw-xml>...</raw-xml> - e = REXML::Element.new(E_XML) + e = REXML::Element.new(E_RAW_XML) e << elt - return e + e end def encode_base64attribute (att) e = REXML::Element.new(E_BASE64) e.text = att.content - return e + e end def encode_atomicattribute (name, value) elt = REXML::Element.new(name) #elt << REXML::Text.new(value.to_s()) elt.add_text(value.to_s()) - return elt + elt end def encode_listattribute (list)