[CCSDK-28] populated the seed code for dgbuilder
[ccsdk/distribution.git] / dgbuilder / core_nodes / deprecated / 74-js2xml.js
diff --git a/dgbuilder/core_nodes/deprecated/74-js2xml.js b/dgbuilder/core_nodes/deprecated/74-js2xml.js
new file mode 100644 (file)
index 0000000..164bafa
--- /dev/null
@@ -0,0 +1,39 @@
+/**\r
+ * Copyright 2013 IBM Corp.\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ **/\r
+\r
+module.exports = function(RED) {\r
+    "use strict";\r
+    var js2xmlparser = require("js2xmlparser");\r
+\r
+    function Js2XmlNode(n) {\r
+        RED.nodes.createNode(this,n);\r
+        this.warn("This node has been deprecated and will be deleted in a future release. Please update your flow to use the 'xml' node.");\r
+        this.root = n.root;\r
+        var node = this;\r
+\r
+        this.on("input", function(msg) {\r
+            try {\r
+                var root = node.root || typeof msg.payload;\r
+                if (typeof msg.payload !== "object") { msg.payload = '"'+msg.payload+'"'; }\r
+                console.log(root, typeof msg.payload,msg.payload);\r
+                msg.payload = js2xmlparser(root, msg.payload);\r
+                node.send(msg);\r
+            }\r
+            catch(e) { console.log(e); }\r
+        });\r
+    }\r
+    RED.nodes.registerType("json2xml",Js2XmlNode);\r
+}\r