2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
22 var dgconverter = new Object();
24 dgconverter.getNodeToXml = function (inputNodeSet) {
25 var exportableNodeSet = JSON.parse(inputNodeSet);
26 //uses inputNodeSet if passed otherwise build the latest nodeSet
28 //$("#btn-deploy").removeClass("disabled");
30 function getDgStartNode(nodeList) {
31 for (var i = 0; i < nodeList.length; i++) {
32 if (nodeList[i].type == 'dgstart' && nodeList[i].wires != null && nodeList[i].wires != undefined) {
40 function getNode(id) {
41 for (var i = 0; i < exportableNodeSet.length; i++) {
42 if (exportableNodeSet[i].id == id) {
43 return exportableNodeSet[i];
49 function getStartTag(node) {
52 if (node != null && node.type != 'dgstart') {
54 var regex = /(<)([\w-]+)(.*)?/;
55 var match = regex.exec(xmlStr);
57 if (match[1] != undefined && match[2] != undefined) {
61 console.log("startTag not found.");
67 // if (inputNodeSet == null || inputNodeSet == undefined) {
68 // exportableNodeSet = getCurrentFlowNodeSet();
70 // exportableNodeSet = JSON.parse(inputNodeSet);
72 var dgstartNode = getDgStartNode(exportableNodeSet);
77 printXml(dgstartNode);
80 function printXml(node) {
83 if (node != null && node.type != 'dgstart') {
84 var comments = node.comments;
85 if (comments != null && comments != "") {
86 //if xml comments field already has the <!-- and --> remove them
87 comments = comments.replace("<!--", "");
88 comments = comments.replace("-->", "");
89 xmlStr = "<!--" + comments + "-->";
92 startTag = getStartTag(node);
93 //special handling for break node
94 if(xmlStr != undefined && xmlStr != null && xmlStr.trim() == "<break>"){
95 fullXmlStr += "<break/>";
101 var spacing = Array(level).join(" ");
102 xmlStr=xmlStr.replace(/\n/g,spacing);
113 //console.log("startTag:" + startTag);
116 var wiredNodesArr = [];
117 if (node != null && node.wires != null && node.wires[0] != null && node.wires[0] != undefined && node.wires[0].length > 0) {
118 wiredNodes = node.wires[0];
119 //console.log("Before sort");
120 for (var k = 0; wiredNodes != undefined && wiredNodes != null && k < wiredNodes.length; k++) {
121 wiredNodesArr.push(getNode(wiredNodes[k]));
123 //console.dir(wiredNodesArr);
124 //sort based on y position
125 wiredNodesArr.sort(function (a, b) {
128 //console.log("After sort");
129 //console.dir(wiredNodesArr);
132 for (var k = 0; wiredNodesArr != null && k < wiredNodesArr.length; k++) {
134 var nd = wiredNodesArr[k];
139 if (startTag != "") {
140 if(startTag != "break"){
141 fullXmlStr += "</" + startTag + ">";
145 var spacing = Array(level).join(" ");
146 fullXmlStr += spacing + "</" + startTag + ">";
147 console.log(spacing + "</" + startTag + ">");
149 fullXmlStr += "</" + startTag + ">";
150 console.log("</" + startTag + ">");
159 //console.log("endTag:" + startTag);
160 //console.log("xml:" + fullXmlStr);
162 //console.log("fullXmlStr:" + fullXmlStr);