Module | OpenWFE::XmlCodec |
In: |
lib/openwfe/orest/xmlcodec.rb
|
Ugly XML codec for OpenWFE workitems
(one of the first things I wrote in Ruby…)
Takes as input some XML element and returns is decoded (as an instance)
# File lib/openwfe/orest/xmlcodec.rb, line 61 61: def XmlCodec.decode (xmlElt) 62: 63: return nil unless xmlElt 64: 65: if xmlElt.kind_of? String 66: 67: xmlElt = REXML::Document.new( 68: xmlElt, 69: :compress_whitespace => :all, 70: :ignore_whitespace_nodes => :all) 71: 72: xmlElt = xmlElt.root 73: end 74: 75: #puts "decode() xmlElt.name is >#{xmlElt.name}<" 76: 77: return decode_session_id(xmlElt) if xmlElt.name == 'session' 78: return decode_list(xmlElt) if xmlElt.name == STORES 79: return decode_store(xmlElt) if xmlElt.name == STORE 80: return decode_list(xmlElt) if xmlElt.name == HEADERS 81: return decode_header(xmlElt) if xmlElt.name == HEADER 82: 83: return decode_launch_ok(xmlElt) if xmlElt.name == OK 84: 85: return decode_list(xmlElt) if xmlElt.name == HISTORY 86: return decode_historyitem(xmlElt) if xmlElt.name == HISTORY_ITEM 87: 88: return decode_list(xmlElt) if xmlElt.name == FLOW_EXPRESSION_IDS 89: return decode_fei(xmlElt) if xmlElt.name == FLOW_EXPRESSION_ID 90: 91: return decode_inflowworkitem(xmlElt) \ 92: if xmlElt.name == IN_FLOW_WORKITEM 93: return decode_launchitem(xmlElt) \ 94: if xmlElt.name == LAUNCHITEM 95: 96: return decode_list(xmlElt) if xmlElt.name == LAUNCHABLES 97: return decode_launchable(xmlElt) if xmlElt.name == LAUNCHABLE 98: 99: return decode_list(xmlElt) if xmlElt.name == EXPRESSIONS 100: return decode_expression(xmlElt) if xmlElt.name == EXPRESSION 101: 102: return decode_attribute(xmlElt.elements[1]) if xmlElt.name == ATTRIBUTES 103: 104: # 105: # default 106: 107: decode_attribute(xmlElt) 108: 109: #raise # ArgumentError, # "Cannot decode : '"+xmlElt.name+"' "+xmlElt.to_s() 110: end
Takes some OpenWFE Ruby instance and returns it as XML
# File lib/openwfe/orest/xmlcodec.rb, line 117 117: def XmlCodec.encode (owfeData) 118: 119: #puts "encode() #{owfeData.inspect}" 120: 121: return encode_launchitem(owfeData) \ 122: if owfeData.kind_of? LaunchItem 123: 124: return encode_fei(owfeData) \ 125: if owfeData.kind_of? FlowExpressionId 126: 127: return encode_inflowworkitem(owfeData) \ 128: if owfeData.kind_of? InFlowWorkItem 129: 130: raise \ 131: ArgumentError, \ 132: "Cannot encode : "+owfeData.inspect() 133: end
# File lib/openwfe/orest/xmlcodec.rb, line 135 135: def XmlCodec.encode_workitem_as_header (in_flow_workitem, locked) 136: 137: e = REXML::Element.new HEADER 138: 139: e.add_attribute A_LAST_MODIFIED, "#{in_flow_workitem.last_modified}" 140: e.add_attribute A_LOCKED, locked 141: 142: e << XmlCodec::encode_fei(in_flow_workitem.fei) 143: e << XmlCodec::encode_attributes(in_flow_workitem) 144: 145: e 146: end