Module: OpenWFE::XmlCodec

Defined in:
lib/openwfe/orest/xmlcodec.rb

Overview

Ugly XML codec for OpenWFE workitems

(one of the first things I wrote in Ruby…)

Class Method Summary collapse

Class Method Details

.decode(xmlElt) ⇒ Object

Takes as input some XML element and returns is decoded (as an instance)



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# File 'lib/openwfe/orest/xmlcodec.rb', line 61

def XmlCodec.decode (xmlElt)

    return nil unless xmlElt

    if xmlElt.kind_of? String

        xmlElt = REXML::Document.new(
            xmlElt, 
            :compress_whitespace => :all,
            :ignore_whitespace_nodes => :all)

        xmlElt = xmlElt.root
    end

    #puts "decode() xmlElt.name is >#{xmlElt.name}<"

    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 decode_launch_ok(xmlElt) if xmlElt.name == OK

    return decode_list(xmlElt) if xmlElt.name == HISTORY
    return decode_historyitem(xmlElt) if xmlElt.name == HISTORY_ITEM

    return decode_list(xmlElt) if xmlElt.name == FLOW_EXPRESSION_IDS
    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
    return decode_expression(xmlElt) if xmlElt.name == EXPRESSION

    return decode_attribute(xmlElt.elements[1]) if xmlElt.name == ATTRIBUTES

    #
    # default

    decode_attribute(xmlElt)

    #raise      #    ArgumentError,      #    "Cannot decode : '"+xmlElt.name+"' "+xmlElt.to_s()
end

.encode(owfeData) ⇒ Object

Takes some OpenWFE Ruby instance and returns it as XML

Raises:

  • (ArgumentError)


117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
# File 'lib/openwfe/orest/xmlcodec.rb', line 117

def XmlCodec.encode (owfeData)

    #puts "encode() #{owfeData.inspect}"

    return encode_launchitem(owfeData) \
        if owfeData.kind_of? LaunchItem

    return encode_fei(owfeData) \
        if owfeData.kind_of? FlowExpressionId

    return encode_inflowworkitem(owfeData) \
        if owfeData.kind_of? InFlowWorkItem

    raise \
        ArgumentError, \
        "Cannot encode : "+owfeData.inspect()
end

.encode_workitem_as_header(in_flow_workitem, locked) ⇒ Object



135
136
137
138
139
140
141
142
143
144
145
146
# File 'lib/openwfe/orest/xmlcodec.rb', line 135

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