lib/openwfe/orest/xmlcodec.rb in ruote-0.9.18 vs lib/openwfe/orest/xmlcodec.rb in ruote-0.9.19

- old
+ new

@@ -1,670 +1,682 @@ # #-- # Copyright (c) 2005-2008, John Mettraux, OpenWFE.org # All rights reserved. -# -# Redistribution and use in source and binary forms, with or without +# +# Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions are met: -# +# # . Redistributions of source code must retain the above copyright notice, this -# list of conditions and the following disclaimer. -# -# . Redistributions in binary form must reproduce the above copyright notice, -# this list of conditions and the following disclaimer in the documentation +# list of conditions and the following disclaimer. +# +# . Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation # and/or other materials provided with the distribution. -# +# # . Neither the name of the "OpenWFE" nor the names of its contributors may be # used to endorse or promote products derived from this software without # specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE -# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN -# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE # POSSIBILITY OF SUCH DAMAGE. #++ # # # "hecho en Costa Rica" (with just the PickAxe at hand) # require 'base64' -require 'rexml/document' +require 'openwfe/rexml' require 'openwfe/utils' require 'openwfe/workitem' require 'openwfe/flowexpressionid' require 'openwfe/orest/definitions' -require 'openwfe/orest/workitem' module OpenWFE - # - # Ugly XML codec for OpenWFE workitems - # - # (one of the first things I wrote in Ruby...) - # - module XmlCodec + # + # a wrapper for some binary content + # + class Base64Attribute - # - # Returns the first subelt of xmlElt that matches the given elt_name. - # If the name is null, the first elt will be returned. - # - def self.first_element (xml_elt, elt_name=nil) + attr_accessor :content - return nil if not xml_elt + def initialize (base64content) - return xml_elt.elements.find { |e| e.is_a?(REXML::Element) } \ - unless elt_name + @content = base64content + end - xml_elt.elements.find do |e| - e.is_a?(REXML::Element) and e.name == elt_name - end - end + # + # dewraps (decode) the current content and returns it + # + def dewrap - # - # Takes as input some XML element and returns is decoded - # (as an instance) - # - def XmlCodec.decode (xmlElt) + Base64.decode64 @content + end - return nil unless xmlElt + # + # wraps some binary content and stores it in this attribute + # (class method) + # + def self.wrap (binaryData) - if xmlElt.kind_of? String + Base64Attribute.new(Base64.encode64(binaryData)) + end + end - xmlElt = REXML::Document.new( - xmlElt, - :compress_whitespace => :all, - :ignore_whitespace_nodes => :all) + # + # Ugly XML codec for OpenWFE workitems + # + # (one of the first things I wrote in Ruby...) + # + module XmlCodec - xmlElt = xmlElt.root - end + # + # Returns the first subelt of xmlElt that matches the given elt_name. + # If the name is null, the first elt will be returned. + # + def self.first_element (xml_elt, elt_name=nil) - #puts "decode() xmlElt.name is >#{xmlElt.name}<" + return nil if not xml_elt - return decode_session_id(xmlElt) if xmlElt.name == 'session' - return decode_list(xmlElt) if xmlElt.name == STORES - return decode_store(xmlElt) if xmlElt.name == STORE - return decode_list(xmlElt) if xmlElt.name == HEADERS - return decode_header(xmlElt) if xmlElt.name == HEADER + return xml_elt.elements.find { |e| e.is_a?(REXML::Element) } \ + unless elt_name - return decode_launch_ok(xmlElt) if xmlElt.name == OK + xml_elt.elements.find do |e| + e.is_a?(REXML::Element) and e.name == elt_name + end + end - return decode_list(xmlElt) if xmlElt.name == HISTORY - return decode_historyitem(xmlElt) if xmlElt.name == HISTORY_ITEM + # + # Takes as input some XML element and returns is decoded + # (as an instance) + # + def XmlCodec.decode (xmlElt) - return decode_list(xmlElt) if xmlElt.name == FLOW_EXPRESSION_IDS - return decode_fei(xmlElt) if xmlElt.name == FLOW_EXPRESSION_ID + return nil unless xmlElt - return decode_inflowworkitem(xmlElt) \ - if xmlElt.name == IN_FLOW_WORKITEM - return decode_launchitem(xmlElt) \ - if xmlElt.name == LAUNCHITEM + if xmlElt.kind_of? String - return decode_list(xmlElt) if xmlElt.name == LAUNCHABLES - return decode_launchable(xmlElt) if xmlElt.name == LAUNCHABLE + xmlElt = REXML::Document.new( + xmlElt, + :compress_whitespace => :all, + :ignore_whitespace_nodes => :all) - return decode_list(xmlElt) if xmlElt.name == EXPRESSIONS - return decode_expression(xmlElt) if xmlElt.name == EXPRESSION + xmlElt = xmlElt.root + end - return decode_attribute(xmlElt.elements[1]) if xmlElt.name == ATTRIBUTES + #puts "decode() xmlElt.name is >#{xmlElt.name}<" - # - # default + return decode_session_id(xmlElt) if xmlElt.name == 'session' + #return decode_list(xmlElt) if xmlElt.name == STORES + #return decode_store(xmlElt) if xmlElt.name == STORE + #return decode_list(xmlElt) if xmlElt.name == HEADERS + #return decode_header(xmlElt) if xmlElt.name == HEADER - decode_attribute(xmlElt) + return decode_launch_ok(xmlElt) if xmlElt.name == OK - #raise \ - # ArgumentError, \ - # "Cannot decode : '"+xmlElt.name+"' "+xmlElt.to_s() - end + #return decode_list(xmlElt) if xmlElt.name == HISTORY + #return decode_historyitem(xmlElt) if xmlElt.name == HISTORY_ITEM - # - # Takes some OpenWFE Ruby instance and returns it as XML - # - def XmlCodec.encode (owfeData) + return decode_list(xmlElt) if xmlElt.name == FLOW_EXPRESSION_IDS + return decode_fei(xmlElt) if xmlElt.name == FLOW_EXPRESSION_ID - #puts "encode() #{owfeData.inspect}" + return decode_inflowworkitem(xmlElt) \ + if xmlElt.name == IN_FLOW_WORKITEM + return decode_launchitem(xmlElt) \ + if xmlElt.name == LAUNCHITEM - return encode_launchitem(owfeData) \ - if owfeData.kind_of? LaunchItem + #return decode_list(xmlElt) if xmlElt.name == LAUNCHABLES + #return decode_launchable(xmlElt) if xmlElt.name == LAUNCHABLE - return encode_fei(owfeData) \ - if owfeData.kind_of? FlowExpressionId + #return decode_list(xmlElt) if xmlElt.name == EXPRESSIONS + #return decode_expression(xmlElt) if xmlElt.name == EXPRESSION - return encode_inflowworkitem(owfeData) \ - if owfeData.kind_of? InFlowWorkItem + return decode_attribute(xmlElt.elements[1]) if xmlElt.name == ATTRIBUTES - raise \ - ArgumentError, \ - "Cannot encode : "+owfeData.inspect() - end + # + # default - def XmlCodec.encode_workitem_as_header (in_flow_workitem, locked) + decode_attribute(xmlElt) - e = REXML::Element.new HEADER + #raise \ + # ArgumentError, \ + # "Cannot decode : '"+xmlElt.name+"' "+xmlElt.to_s() + end - e.add_attribute A_LAST_MODIFIED, "#{in_flow_workitem.last_modified}" - e.add_attribute A_LOCKED, locked + # + # Takes some OpenWFE Ruby instance and returns it as XML + # + def XmlCodec.encode (owfeData) - e << XmlCodec::encode_fei(in_flow_workitem.fei) - e << XmlCodec::encode_attributes(in_flow_workitem) + #puts "encode() #{owfeData.inspect}" - e - end + return encode_launchitem(owfeData) \ + if owfeData.kind_of? LaunchItem - private + return encode_fei(owfeData) \ + if owfeData.kind_of? FlowExpressionId - # - # DECODE - # + return encode_inflowworkitem(owfeData) \ + if owfeData.kind_of? InFlowWorkItem - def XmlCodec.decode_session_id (xmlElt) - Integer(xmlElt.attributes['id']) - end + raise \ + ArgumentError, \ + "Cannot encode : "+owfeData.inspect() + end - def XmlCodec.decode_list (xmlElt) - xmlElt.elements.collect { |elt| decode(elt) } - end + #-- + #def XmlCodec.encode_workitem_as_header (in_flow_workitem, locked) + # e = REXML::Element.new HEADER + # e.add_attribute A_LAST_MODIFIED, "#{in_flow_workitem.last_modified}" + # e.add_attribute A_LOCKED, locked + # e << XmlCodec::encode_fei(in_flow_workitem.fei) + # e << XmlCodec::encode_attributes(in_flow_workitem) + # e + #end + #++ + private - def XmlCodec.decode_launchable (xmlElt) + # + # DECODE + # - launchable = Launchable.new() + def XmlCodec.decode_session_id (xmlElt) + Integer(xmlElt.attributes['id']) + end - launchable.url = xmlElt.attributes[URL] - launchable.engine_id = xmlElt.attributes[ENGINE_ID] + def XmlCodec.decode_list (xmlElt) + xmlElt.elements.collect { |elt| decode(elt) } + end - launchable - end + def XmlCodec.decode_launchable (xmlElt) - def XmlCodec.decode_expression (xmlElt) + launchable = Launchable.new() - exp = Expression.new() - - exp.id = decode(first_element(xmlElt)) + launchable.url = xmlElt.attributes[URL] + launchable.engine_id = xmlElt.attributes[ENGINE_ID] - exp.apply_time = xmlElt.attributes[APPLY_TIME] - exp.state = xmlElt.attributes[STATE] - exp.state_since = xmlElt.attributes[STATE_SINCE] + launchable + end - exp - end + def XmlCodec.decode_expression (xmlElt) - def XmlCodec.decode_store (xmlElt) + exp = Expression.new() - store = Store.new() + exp.id = decode(first_element(xmlElt)) - store.name = xmlElt.attributes[NAME] - store.workitem_count = xmlElt.attributes[WORKITEM_COUNT] - store.workitem_count = Integer(store.workitem_count) - store.permissions = xmlElt.attributes[PERMISSIONS] + exp.apply_time = xmlElt.attributes[APPLY_TIME] + exp.state = xmlElt.attributes[STATE] + exp.state_since = xmlElt.attributes[STATE_SINCE] - store - end + exp + end + #-- + #def XmlCodec.decode_store (xmlElt) + # store = Store.new() + # store.name = xmlElt.attributes[NAME] + # store.workitem_count = xmlElt.attributes[WORKITEM_COUNT] + # store.workitem_count = Integer(store.workitem_count) + # store.permissions = xmlElt.attributes[PERMISSIONS] + # store + #end + #++ - def XmlCodec.decode_header (xmlElt) + #-- + #def XmlCodec.decode_header (xmlElt) + # header = Header.new() + # header.last_modified = xmlElt.attributes[A_LAST_MODIFIED] + # header.locked = parse_boolean(xmlElt.attributes[A_LOCKED]) + # header.flow_expression_id = decode(first_element(xmlElt, FLOW_EXPRESSION_ID)) + # header.attributes = decode(first_element(xmlElt, ATTRIBUTES)) + # header + #end + #++ - header = Header.new() + def XmlCodec.decode_fei (xmlElt) - header.last_modified = xmlElt.attributes[A_LAST_MODIFIED] - header.locked = parse_boolean(xmlElt.attributes[A_LOCKED]) - header.flow_expression_id = decode(first_element(xmlElt, FLOW_EXPRESSION_ID)) - header.attributes = decode(first_element(xmlElt, ATTRIBUTES)) + fei = FlowExpressionId.new - header - end + fei.owfe_version = xmlElt.attributes[OWFE_VERSION] + fei.engine_id = xmlElt.attributes[ENGINE_ID] + fei.initial_engine_id = xmlElt.attributes[INITIAL_ENGINE_ID] + fei.workflow_definition_url = xmlElt.attributes[WORKFLOW_DEFINITION_URL] + fei.workflow_definition_name = xmlElt.attributes[WORKFLOW_DEFINITION_NAME] + fei.workflow_definition_revision = xmlElt.attributes[WORKFLOW_DEFINITION_REVISION] - def XmlCodec.decode_fei (xmlElt) + fei.workflow_instance_id = xmlElt.attributes[WORKFLOW_INSTANCE_ID] - fei = FlowExpressionId.new + fei.expression_name = xmlElt.attributes[EXPRESSION_NAME] + fei.expression_id = xmlElt.attributes[EXPRESSION_ID] - fei.owfe_version = xmlElt.attributes[OWFE_VERSION] - fei.engine_id = xmlElt.attributes[ENGINE_ID] - fei.initial_engine_id = xmlElt.attributes[INITIAL_ENGINE_ID] + #puts " ... fei.expressionName is >#{fei.expressionName}<" + #puts " ... fei.wfid is >#{fei.workflowInstanceId}<" - fei.workflow_definition_url = xmlElt.attributes[WORKFLOW_DEFINITION_URL] - fei.workflow_definition_name = xmlElt.attributes[WORKFLOW_DEFINITION_NAME] - fei.workflow_definition_revision = xmlElt.attributes[WORKFLOW_DEFINITION_REVISION] + fei + end - fei.workflow_instance_id = xmlElt.attributes[WORKFLOW_INSTANCE_ID] - fei.expression_name = xmlElt.attributes[EXPRESSION_NAME] - fei.expression_id = xmlElt.attributes[EXPRESSION_ID] + def XmlCodec.decode_attribute (xmlElt) - #puts " ... fei.expressionName is >#{fei.expressionName}<" - #puts " ... fei.wfid is >#{fei.workflowInstanceId}<" + #puts "decodeAttribute() '#{xmlElt.name}' --> '#{xmlElt.text}'" - fei - end + # + # atomic types + return xmlElt.text.strip \ + if xmlElt.name == E_STRING + return Integer(xmlElt.text.strip) \ + if xmlElt.name == E_INTEGER + return Integer(xmlElt.text.strip) \ + if xmlElt.name == E_LONG + return Float(xmlElt.text.strip) \ + if xmlElt.name == E_DOUBLE + return parse_boolean(xmlElt.text) \ + if xmlElt.name == E_BOOLEAN - def XmlCodec.decode_attribute (xmlElt) + return decode_xmldocument(xmlElt) \ + if xmlElt.name == E_XML_DOCUMENT + return xmlElt.children[0] \ + if xmlElt.name == E_RAW_XML - #puts "decodeAttribute() '#{xmlElt.name}' --> '#{xmlElt.text}'" + return Base64Attribute.new(xmlElt.text) \ + if xmlElt.name == E_BASE64 - # - # atomic types + # + # composite types - return xmlElt.text.strip \ - if xmlElt.name == E_STRING - return Integer(xmlElt.text.strip) \ - if xmlElt.name == E_INTEGER - return Integer(xmlElt.text.strip) \ - if xmlElt.name == E_LONG - return Float(xmlElt.text.strip) \ - if xmlElt.name == E_DOUBLE - return parse_boolean(xmlElt.text) \ - if xmlElt.name == E_BOOLEAN + return decode_list(xmlElt) \ + if xmlElt.name == E_LIST - return decode_xmldocument(xmlElt) \ - if xmlElt.name == E_XML_DOCUMENT - return xmlElt.children[0] \ - if xmlElt.name == E_RAW_XML + if xmlElt.name == E_SMAP or xmlElt.name == E_MAP - return Base64Attribute.new(xmlElt.text) \ - if xmlElt.name == E_BASE64 + map = {} + map[MAP_TYPE] = xmlElt.name - # - # composite types + #xmlElt.elements.each("//"+M_ENTRY) do |e| + xmlElt.elements.each(M_ENTRY) do |e| + #puts "decodeAttribute() >#{e}<" + decode_entry(e, map) + end - return decode_list(xmlElt) \ - if xmlElt.name == E_LIST + return map + end - if xmlElt.name == E_SMAP or xmlElt.name == E_MAP + #puts OpenWFE.xmldoc_to_string(xmlElt.document()) - map = {} - map[MAP_TYPE] = xmlElt.name + raise \ + ArgumentError, \ + "Cannot decode <#{xmlElt.name}/> in \n"+\ + OpenWFE.xmldoc_to_string(xmlElt.document()) + end - #xmlElt.elements.each("//"+M_ENTRY) do |e| - xmlElt.elements.each(M_ENTRY) do |e| - #puts "decodeAttribute() >#{e}<" - decode_entry(e, map) - end + def XmlCodec.decode_xmldocument (xmlElt) - return map - end + s = Base64::decode64 xmlElt.text.strip + REXML::Document.new s + end - #puts OpenWFE.xmldoc_to_string(xmlElt.document()) + def XmlCodec.decode_entry (xmlElt, map) - raise \ - ArgumentError, \ - "Cannot decode <#{xmlElt.name}/> in \n"+\ - OpenWFE.xmldoc_to_string(xmlElt.document()) - end + key = xmlElt.elements[1] + val = xmlElt.elements[2] - def XmlCodec.decode_xmldocument (xmlElt) + # + # this parse method supports the old style and the [new] light + # style/schema + # - s = Base64::decode64 xmlElt.text.strip - REXML::Document.new s - end + key = key.elements[1] if key.name == M_KEY + val = val.elements[1] if val.name == M_VALUE - def XmlCodec.decode_entry (xmlElt, map) + key = decode(key) + val = decode(val) - key = xmlElt.elements[1] - val = xmlElt.elements[2] + #puts "decodeEntry() k >#{key}< v >#{val}<" + #puts "decodeEntry() subject '#{val}'" if key == '__subject__' - # - # this parse method supports the old style and the [new] light - # style/schema - # + key = key.strip if key.is_a?(String) + val = val.strip if val.is_a?(String) - key = key.elements[1] if key.name == M_KEY - val = val.elements[1] if val.name == M_VALUE + map[key] = val + end - key = decode(key) - val = decode(val) + def XmlCodec.parse_boolean (string) - #puts "decodeEntry() k >#{key}< v >#{val}<" - #puts "decodeEntry() subject '#{val}'" if key == '__subject__' + string.strip.downcase == 'true' + end - key = key.strip if key.is_a?(String) - val = val.strip if val.is_a?(String) + #-- + #def XmlCodec.decode_historyitem (xmlElt) + # hi = HistoryItem.new + # hi.author = xmlElt.attributes[A_AUTHOR] + # hi.date = xmlElt.attributes[A_DATE] + # hi.host = xmlElt.attributes[A_HOST] + # hi.text = xmlElt.text + # hi.wfd_name = xmlElt.attributes[WORKFLOW_DEFINITION_NAME] + # hi.wfd_revision = xmlElt.attributes[WORKFLOW_DEFINITION_REVISION] + # hi.wf_instance_id = xmlElt.attributes[WORKFLOW_INSTANCE_ID] + # hi.expression_id = xmlElt.attributes[EXPRESSION_ID] + # hi + #end + #++ - map[key] = val - end + def XmlCodec.decode_launch_ok (xmlElt) - def XmlCodec.parse_boolean (string) + sFei = xmlElt.attributes[A_FLOW_ID] - string.strip.downcase == 'true' - end + return true unless sFei - def XmlCodec.decode_historyitem (xmlElt) + FlowExpressionId.to_fei(sFei) + end - hi = HistoryItem.new - hi.author = xmlElt.attributes[A_AUTHOR] - hi.date = xmlElt.attributes[A_DATE] - hi.host = xmlElt.attributes[A_HOST] - hi.text = xmlElt.text + def XmlCodec.decode_inflowworkitem (xmlElt) - hi.wfd_name = xmlElt.attributes[WORKFLOW_DEFINITION_NAME] - hi.wfd_revision = xmlElt.attributes[WORKFLOW_DEFINITION_REVISION] - hi.wf_instance_id = xmlElt.attributes[WORKFLOW_INSTANCE_ID] - hi.expression_id = xmlElt.attributes[EXPRESSION_ID] + wi = InFlowWorkItem.new() - hi - end + wi.last_modified = xmlElt.attributes[A_LAST_MODIFIED] + wi.attributes = decode(first_element(xmlElt, ATTRIBUTES)) + wi.participant_name = xmlElt.attributes[A_PARTICIPANT_NAME] + wi.flow_expression_id = decode(first_element(first_element(xmlElt, E_LAST_EXPRESSION_ID), FLOW_EXPRESSION_ID)) - def XmlCodec.decode_launch_ok (xmlElt) + wi.dispatch_time = xmlElt.attributes[A_DISPATCH_TIME] - sFei = xmlElt.attributes[A_FLOW_ID] + # TODO : decode filter - return true unless sFei + #wi.history = decode(first_element(xmlElt, HISTORY)) - FlowExpressionId.to_fei(sFei) - end + wi + end + def XmlCodec.decode_launchitem (xmlElt) - def XmlCodec.decode_inflowworkitem (xmlElt) + li = LaunchItem.new - wi = InFlowWorkItem.new() + li.workflow_definition_url = + xmlElt.attributes[WORKFLOW_DEFINITION_URL] - wi.last_modified = xmlElt.attributes[A_LAST_MODIFIED] - wi.attributes = decode(first_element(xmlElt, ATTRIBUTES)) + li.attributes = + decode(first_element(xmlElt, ATTRIBUTES)) - wi.participant_name = xmlElt.attributes[A_PARTICIPANT_NAME] - wi.flow_expression_id = decode(first_element(first_element(xmlElt, E_LAST_EXPRESSION_ID), FLOW_EXPRESSION_ID)) + li + end - wi.dispatch_time = xmlElt.attributes[A_DISPATCH_TIME] - # TODO : decode filter + # + # ENCODE + # - wi.history = decode(first_element(xmlElt, HISTORY)) - wi - end + def XmlCodec.encode_item (item, elt) - def XmlCodec.decode_launchitem (xmlElt) + elt.attributes[A_LAST_MODIFIED] = item.last_modified - li = LaunchItem.new + elt << encode_attributes(item) + end - li.workflow_definition_url = - xmlElt.attributes[WORKFLOW_DEFINITION_URL] + def XmlCodec.encode_attributes (item) - li.attributes = - decode(first_element(xmlElt, ATTRIBUTES)) + eAttributes = REXML::Element.new(ATTRIBUTES) - li - end + eAttributes << encode_attribute(item.attributes) + eAttributes + end - # - # ENCODE - # + def XmlCodec.encode_launchitem (launchitem) - def XmlCodec.encode_item (item, elt) + doc = REXML::Document.new() - elt.attributes[A_LAST_MODIFIED] = item.last_modified + root = REXML::Element.new(LAUNCHITEM) - elt << encode_attributes(item) - end + encode_item(launchitem, root) - def XmlCodec.encode_attributes (item) + root.attributes[WORKFLOW_DEFINITION_URL] = \ + launchitem.workflow_definition_url - eAttributes = REXML::Element.new(ATTRIBUTES) + # TODO : + # + # - encode descriptionMap + # + # - replyTo is not necessary - eAttributes << encode_attribute(item.attributes) + doc << root - eAttributes - end + OpenWFE.xmldoc_to_string(doc) + end - def XmlCodec.encode_launchitem (launchitem) + def XmlCodec.encode_inflowitem (item, elt) - doc = REXML::Document.new() + encode_item(item, elt) - root = REXML::Element.new(LAUNCHITEM) + elt.attributes[A_PARTICIPANT_NAME] = item.participant_name - encode_item(launchitem, root) + eLastExpressionId = REXML::Element.new(E_LAST_EXPRESSION_ID) - root.attributes[WORKFLOW_DEFINITION_URL] = \ - launchitem.workflow_definition_url + eLastExpressionId << encode_fei(item.last_expression_id) - # TODO : - # - # - encode descriptionMap - # - # - replyTo is not necessary + elt << eLastExpressionId + end - doc << root - OpenWFE.xmldoc_to_string(doc) - end + def XmlCodec.encode_inflowworkitem (item) + doc = REXML::Document.new() - def XmlCodec.encode_inflowitem (item, elt) + root = REXML::Element.new(IN_FLOW_WORKITEM) - encode_item(item, elt) + encode_inflowitem(item, root) - elt.attributes[A_PARTICIPANT_NAME] = item.participant_name + root.attributes[A_DISPATCH_TIME] = item.dispatch_time - eLastExpressionId = REXML::Element.new(E_LAST_EXPRESSION_ID) + # add filter ? no - eLastExpressionId << encode_fei(item.last_expression_id) + encode_history(item, root) if item.history - elt << eLastExpressionId - end + doc << root + s = OpenWFE.xmldoc_to_string(doc) + #puts "encoded :\n#{s}" + s + end - def XmlCodec.encode_inflowworkitem (item) + #-- + #def XmlCodec.encode_history (item, elt) + # eHistory = REXML::Element.new(HISTORY) + # item.history.each do |hi| + # ehi = REXML::Element.new(HISTORY_ITEM) + # ehi.attributes[A_AUTHOR] = hi.author + # ehi.attributes[A_DATE] = hi.date + # ehi.attributes[A_HOST] = hi.host + # ehi.attributes[WORKFLOW_DEFINITION_NAME] = hi.wfd_name + # ehi.attributes[WORKFLOW_DEFINITION_REVISION] = hi.wfd_revision + # ehi.attributes[WORKFLOW_INSTANCE_ID] = hi.wf_instance_id + # ehi.attributes[EXPRESSION_ID] = hi.expression_id + # eHistory << ehi + # end + # elt << eHistory + #end + #++ - doc = REXML::Document.new() + def XmlCodec.encode_attribute (att) - root = REXML::Element.new(IN_FLOW_WORKITEM) + #puts "encodeAttribute() att.class is #{att.class}" - encode_inflowitem(item, root) + return encode_atomicattribute(E_STRING, att) \ + if att.kind_of?(String) + return encode_atomicattribute(E_INTEGER, att) \ + if att.kind_of?(Fixnum) + return encode_atomicattribute(E_DOUBLE, att) \ + if att.kind_of?(Float) - root.attributes[A_DISPATCH_TIME] = item.dispatch_time + return encode_xmldocument(att) \ + if att.kind_of?(REXML::Document) + return encode_xmlattribute(att) \ + if att.kind_of?(REXML::Element) - # add filter ? no + return encode_atomicattribute(E_BOOLEAN, true) \ + if att.kind_of?(TrueClass) + return encode_atomicattribute(E_BOOLEAN, false) \ + if att.kind_of?(FalseClass) - encode_history(item, root) if item.history + return encode_base64attribute(att) \ + if att.kind_of?(Base64Attribute) - doc << root + return encode_mapattribute(att) if att.kind_of?(Hash) + return encode_listattribute(att) if att.kind_of?(Array) - s = OpenWFE.xmldoc_to_string(doc) - #puts "encoded :\n#{s}" - s - end + # + # default + encode_atomicattribute(E_STRING, att) - def XmlCodec.encode_history (item, elt) + #raise \ + # ArgumentError, \ + # "Cannot encode attribute of class '#{att.class}'" + end - eHistory = REXML::Element.new(HISTORY) + def XmlCodec.encode_xmldocument (elt) - item.history.each do |hi| + e = REXML::Element.new(E_XML_DOCUMENT) + e.text = Base64::encode64(elt.to_s) + e + end - ehi = REXML::Element.new(HISTORY_ITEM) + def XmlCodec.encode_xmlattribute (elt) - ehi.attributes[A_AUTHOR] = hi.author - ehi.attributes[A_DATE] = hi.date - ehi.attributes[A_HOST] = hi.host + return elt if elt.name == E_RAW_XML - ehi.attributes[WORKFLOW_DEFINITION_NAME] = hi.wfd_name - ehi.attributes[WORKFLOW_DEFINITION_REVISION] = hi.wfd_revision - ehi.attributes[WORKFLOW_INSTANCE_ID] = hi.wf_instance_id - ehi.attributes[EXPRESSION_ID] = hi.expression_id + # + # else, wrap within <raw-xml>...</raw-xml> - eHistory << ehi - end + e = REXML::Element.new(E_RAW_XML) + e << elt - elt << eHistory - end + e + end - def XmlCodec.encode_attribute (att) + def XmlCodec.encode_base64attribute (att) - #puts "encodeAttribute() att.class is #{att.class}" + e = REXML::Element.new(E_BASE64) + e.text = att.content - return encode_atomicattribute(E_STRING, att) \ - if att.kind_of?(String) - return encode_atomicattribute(E_INTEGER, att) \ - if att.kind_of?(Fixnum) - return encode_atomicattribute(E_DOUBLE, att) \ - if att.kind_of?(Float) + e + end - return encode_xmldocument(att) \ - if att.kind_of?(REXML::Document) - return encode_xmlattribute(att) \ - if att.kind_of?(REXML::Element) - return encode_atomicattribute(E_BOOLEAN, true) \ - if att.kind_of?(TrueClass) - return encode_atomicattribute(E_BOOLEAN, false) \ - if att.kind_of?(FalseClass) + def XmlCodec.encode_atomicattribute (name, value) - return encode_base64attribute(att) \ - if att.kind_of?(Base64Attribute) + elt = REXML::Element.new(name) + #elt << REXML::Text.new(value.to_s()) + elt.add_text(value.to_s()) - return encode_mapattribute(att) if att.kind_of?(Hash) - return encode_listattribute(att) if att.kind_of?(Array) + elt + end - # - # default - encode_atomicattribute(E_STRING, att) + def XmlCodec.encode_listattribute (list) - #raise \ - # ArgumentError, \ - # "Cannot encode attribute of class '#{att.class}'" - end + elt = REXML::Element.new(E_LIST) - def XmlCodec.encode_xmldocument (elt) + list.each do |e| + elt << encode_attribute(e) + end - e = REXML::Element.new(E_XML_DOCUMENT) - e.text = Base64::encode64(elt.to_s) - e - end + elt + end - def XmlCodec.encode_xmlattribute (elt) - return elt if elt.name == E_RAW_XML + def XmlCodec.encode_mapattribute (hash) - # - # else, wrap within <raw-xml>...</raw-xml> + name = hash[MAP_TYPE] + name = 'map' if name == nil - e = REXML::Element.new(E_RAW_XML) - e << elt + elt = REXML::Element.new(name) - e - end + hash.each_key do |key| + next if key == MAP_TYPE - def XmlCodec.encode_base64attribute (att) + eEntry = REXML::Element.new(M_ENTRY) - e = REXML::Element.new(E_BASE64) - e.text = att.content + val = hash[key] - e - end + eEntry << encode_attribute(key) + eEntry << encode_attribute(val) + elt << eEntry + end - def XmlCodec.encode_atomicattribute (name, value) + elt + end - elt = REXML::Element.new(name) - #elt << REXML::Text.new(value.to_s()) - elt.add_text(value.to_s()) - elt - end + def XmlCodec.encode_fei (fei) + elt = REXML::Element.new(FLOW_EXPRESSION_ID) - def XmlCodec.encode_listattribute (list) + elt.attributes[OWFE_VERSION] = fei.owfe_version + elt.attributes[ENGINE_ID] = fei.engine_id + elt.attributes[INITIAL_ENGINE_ID] = fei.initial_engine_id - elt = REXML::Element.new(E_LIST) + elt.attributes[WORKFLOW_DEFINITION_URL] = fei.workflow_definition_url + elt.attributes[WORKFLOW_DEFINITION_NAME] = fei.workflow_definition_name + elt.attributes[WORKFLOW_DEFINITION_REVISION] = fei.workflow_definition_revision + elt.attributes[WORKFLOW_INSTANCE_ID] = fei.workflow_instance_id - list.each do |e| - elt << encode_attribute(e) - end + elt.attributes[EXPRESSION_NAME] = fei.expression_name + elt.attributes[EXPRESSION_ID] = fei.expression_id - elt - end - - - def XmlCodec.encode_mapattribute (hash) - - name = hash[MAP_TYPE] - name = 'map' if name == nil - - elt = REXML::Element.new(name) - - hash.each_key do |key| - - next if key == MAP_TYPE - - eEntry = REXML::Element.new(M_ENTRY) - - val = hash[key] - - eEntry << encode_attribute(key) - eEntry << encode_attribute(val) - - elt << eEntry - end - - elt - end - - - def XmlCodec.encode_fei (fei) - - elt = REXML::Element.new(FLOW_EXPRESSION_ID) - - elt.attributes[OWFE_VERSION] = fei.owfe_version - elt.attributes[ENGINE_ID] = fei.engine_id - elt.attributes[INITIAL_ENGINE_ID] = fei.initial_engine_id - - elt.attributes[WORKFLOW_DEFINITION_URL] = fei.workflow_definition_url - elt.attributes[WORKFLOW_DEFINITION_NAME] = fei.workflow_definition_name - elt.attributes[WORKFLOW_DEFINITION_REVISION] = fei.workflow_definition_revision - elt.attributes[WORKFLOW_INSTANCE_ID] = fei.workflow_instance_id - - elt.attributes[EXPRESSION_NAME] = fei.expression_name - elt.attributes[EXPRESSION_ID] = fei.expression_id - - elt - end + elt end + 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) + # + # 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) - #return xml if xml.is_a?(String) + #return xml if xml.is_a?(String) - xml << REXML::XMLDecl.new \ - if decl and (not xml[0].is_a?(REXML::XMLDecl)) + xml << REXML::XMLDecl.new \ + if decl and (not xml[0].is_a?(REXML::XMLDecl)) - #s = "" - #xml.write(s, 0) - #return s - xml.to_s - end + #s = "" + #xml.write(s, 0) + #return s + xml.to_s + end - # - # An alias for OpenWFE::xmldoc_to_string() - # - def OpenWFE.xml_to_s (xml, decl=true) + # + # An alias for OpenWFE::xmldoc_to_string() + # + def OpenWFE.xml_to_s (xml, decl=true) - OpenWFE::xmldoc_to_string(xml, decl) - end + OpenWFE::xmldoc_to_string(xml, decl) + end end