Refactoring: cleaning directories structure
[fnpeditor.git] / src / editor / modules / metadataEditor / transformations.js
diff --git a/src/editor/modules/metadataEditor/transformations.js b/src/editor/modules/metadataEditor/transformations.js
new file mode 100644 (file)
index 0000000..a09ee38
--- /dev/null
@@ -0,0 +1,24 @@
+define(['libs/jquery'], function($) {
+
+    'use strict';
+
+    return {
+        getMetadata: function(xml) {
+            var toret = {};
+            $(xml).find('metadata').children().each(function() {
+                var node = $(this);
+                toret[this.nodeName.split(':')[1].toLowerCase()] = node.text();
+            });
+            return toret;
+        },
+        getXML: function(metadata) {
+            var meta = $('<metadata></metadata>\n');
+            _.each(_.keys(metadata), function(key) {
+                meta.append('\n\t<dc:'+key+'>' + metadata[key] + '</dc:'+key+'>');
+            });
+            meta.append('\n');
+            return vkbeautify.xml(meta.html());
+        }
+    };
+
+});
\ No newline at end of file