summaryrefslogtreecommitdiff
path: root/misc/freeswitch/scripts/configuration/simple_xml.lua
diff options
context:
space:
mode:
Diffstat (limited to 'misc/freeswitch/scripts/configuration/simple_xml.lua')
-rw-r--r--misc/freeswitch/scripts/configuration/simple_xml.lua50
1 files changed, 50 insertions, 0 deletions
diff --git a/misc/freeswitch/scripts/configuration/simple_xml.lua b/misc/freeswitch/scripts/configuration/simple_xml.lua
new file mode 100644
index 0000000..f04dd1e
--- /dev/null
+++ b/misc/freeswitch/scripts/configuration/simple_xml.lua
@@ -0,0 +1,50 @@
+-- Gemeinschaft 5 simple xml gererator class
+-- (c) AMOOMA GmbH 2013
+--
+
+module(...,package.seeall)
+
+SimpleXml = {}
+
+-- Create SimpleXml object
+function SimpleXml.new(self, arg)
+ arg = arg or {}
+ object = arg.object or {}
+ setmetatable(object, self);
+ self.__index = self;
+ self.class = 'simplexml';
+ return object;
+end
+
+function SimpleXml.element(self, arg)
+ local xml_tag = '<' .. tostring(arg[1]);
+ for key, value in pairs(arg) do
+ if type(key) == 'string' then
+ xml_tag = xml_tag .. ' ' .. tostring(key) .. '="' .. tostring(value) .. '"';
+ end
+ end
+ xml_tag = xml_tag .. '>';
+
+ for key=2, #arg do
+ xml_tag = xml_tag .. '\n' .. tostring(arg[key]) .. '\n';
+ end
+
+ return xml_tag .. '</' .. tostring(arg[1]) .. '>';
+end
+
+
+function SimpleXml.from_hash(self, element_name, parameter_hash, key_name, value_name)
+ local params_xml = '';
+ for key, value in pairs(parameter_hash) do
+ local arguments = { [1] = element_name };
+ if key_name and value_name then
+ arguments[key_name] = key;
+ arguments[value_name] = value;
+ else
+ arguments[key] = value;
+ end
+ params_xml = params_xml .. tostring(self:element(arguments)) .. '\n';
+ end
+
+ return params_xml;
+end