27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
|
# File 'lib/versionone_sdk/parser_xml_assets.rb', line 27
def getJsondocForXmlAssetNode(oNodeAsset=nil)
if oNodeAsset.nil?
raise RuntimeError, 'E_NIL_NODE'
end
oJsondoc = JsonDoc::Document.new
oJsondoc.bIsStrict = false
if oNodeAsset.attribute('id')
sId = oNodeAsset.attribute('id').value
if sId =~ /^(.+):([0-9]+)$/
sObjectType = $1
iObjectId = $2.to_i
oJsondoc.setProp(:__id__sObjectDomain,'Versionone')
oJsondoc.setProp(:__id__sObjectType,sObjectType)
oJsondoc.setProp(:__id__iObjectId, iObjectId)
end
end
if oNodeAsset.attribute('href').value
sUrl = @sUrl \
? @sUrl + oNodeAsset.attribute('href').value
: oNodeAsset.attribute('href').value
oJsondoc.setProp(:__id__sObjectUrl,sUrl)
end
oNodeAsset.children.each do |oNodeChild|
if oNodeChild.name == 'Attribute'
if oNodeChild.attribute('name')
yPropKey = oNodeChild.attribute('name').to_s.to_sym
sPropVal = oNodeChild.text
sPropVal = nil if sPropVal == ''
oJsondoc.setProp(yPropKey,sPropVal)
end
elsif oNodeChild.name == 'Relation'
yPropKey = oNodeChild.attribute('name').to_s.to_sym
oNodeRelation = oNodeChild
oNodeRelation.children.each do |oNodeRelationChild|
if oNodeRelationChild.name == 'Asset'
if oNodeRelationChild.attribute('idref').value
oJsondoc.pushProp(yPropKey,oNodeRelationChild.attribute('idref').value)
end
else
raise RuntimeError, "E_UNKNOWN_RELATION_CHILD_NAME #{oNodeRelationChild.name}"
end
end
if oNodeRelation.children.count == 0
oJsondoc.setProp(yPropKey,[])
end
else
raise RuntimeError, "E_UNKNOWN_ASSET_NODE_NAME #{oNodeChild.name}"
end
end
return oJsondoc
end
|