aboutsummaryrefslogtreecommitdiffstats
path: root/util/datamapper.lua
diff options
context:
space:
mode:
Diffstat (limited to 'util/datamapper.lua')
-rw-r--r--util/datamapper.lua52
1 files changed, 41 insertions, 11 deletions
diff --git a/util/datamapper.lua b/util/datamapper.lua
index a208dd7e..d2a6a963 100644
--- a/util/datamapper.lua
+++ b/util/datamapper.lua
@@ -162,6 +162,8 @@ function parse_array(schema, s)
error("NYI")
end
+ value = totype(proptype, value)
+
if value ~= nil then
table.insert(out, value);
end
@@ -180,19 +182,20 @@ local function parse(schema, s)
end
local function unparse(schema, t, current_name, current_ns)
- if schema.type == "object" then
-
- if schema.xml then
- if schema.xml.name then
- current_name = schema.xml.name
- end
- if schema.xml.namespace then
- current_ns = schema.xml.namespace
- end
+ if schema.xml then
+ if schema.xml.name then
+ current_name = schema.xml.name
+ end
+ if schema.xml.namespace then
+ current_ns = schema.xml.namespace
end
- local out = st.stanza(current_name, {xmlns = current_ns})
+ end
+
+ local out = st.stanza(current_name, {xmlns = current_ns})
+
+ if schema.type == "object" then
for prop, propschema in pairs(schema.properties) do
local v = t[prop]
@@ -264,13 +267,40 @@ local function unparse(schema, t, current_name, current_ns)
if c then
out:add_direct_child(c);
end
-
+ elseif proptype == "array" and type(propschema) == "table" and type(v) == "table" then
+ local c = unparse(propschema, v, name, namespace);
+ if c then
+ if value_where == "in_wrapper" then
+ local w = st.stanza(propschema.xml.name or name, {xmlns = propschema.xml.namespace or namespace})
+ w:add_direct_child(c);
+ out:add_direct_child(w);
+ else
+ out:add_direct_child(c);
+ end
+ end
+ else
+ error("NYI")
end
end
end
end
return out
+ elseif schema.type == "array" then
+ local proptype, value_where, name, namespace = unpack_propschema(schema.items, current_name, current_ns)
+
+ if proptype == "string" then
+ for _, item in ipairs(t) do
+ if value_where == "in_text_tag" then
+ out:text_tag(name, item, {xmlns = namespace});
+ else
+ error("NYI")
+ end
+ end
+ else
+ error("NYI")
+ end
+ return out
end
end