diff options
author | Chinthakayala,Sheshashailavas(sc2914) <sc2914@att.com> | 2018-06-27 16:11:44 +0000 |
---|---|---|
committer | Chinthakayala,Sheshashailavas(sc2914) <sc2914@att.com> | 2018-06-27 16:25:31 +0000 |
commit | 8f6a6c445eaeb7356e1db9d10d10b7d3fa42f27e (patch) | |
tree | bf1e5c83c357fbd4a0158cac6d41bd936e949a80 /dgbuilder/public/util/js/validateNodeXml.js | |
parent | e14a02086c9119532f9153c78346d5c1d6789ca9 (diff) |
removed dependency on built-editor.min.js
and added ability to test DG from dgbuilder
and fixed the break node on XML generation
and added ability to download
formatted DG XML and DG JSON
Issue-ID: SDNC-353
Change-Id: I799de5de2c4f61e9b56dbe996d8ac3e3b28061f7
Signed-off-by: Chinthakayala,Sheshashailavas(sc2914) <sc2914@att.com>
Diffstat (limited to 'dgbuilder/public/util/js/validateNodeXml.js')
-rw-r--r-- | dgbuilder/public/util/js/validateNodeXml.js | 175 |
1 files changed, 174 insertions, 1 deletions
diff --git a/dgbuilder/public/util/js/validateNodeXml.js b/dgbuilder/public/util/js/validateNodeXml.js index 2291d865..d57ba0d7 100644 --- a/dgbuilder/public/util/js/validateNodeXml.js +++ b/dgbuilder/public/util/js/validateNodeXml.js @@ -190,7 +190,7 @@ function validateXML(xmlStr){ resp=true; errList=[]; elementCount=0; - //console.log("In validateXML xmlStr:" + xmlStr); + console.log("In validateXML xmlStr:" + xmlStr); //var xmlStr = $("#node-input-xml-editor").text(); if(xmlStr == null || xmlStr == undefined){ xmlStr = $("#node-input-xml-editor").text(); @@ -323,3 +323,176 @@ function showErrors() { } }); // end dialog div } + +var dgParsedParameters ; +var dgProcessNode ; +var callNodes ; +function extractSliParameters(xmlNode){ + if(xmlNode == null) return; + if(xmlNode.nodeName != "parsererror" && xmlNode.nodeName != "#text"){ + dgProcessNode = xmlNode.nodeName; + } + //console.log("processedNode:" + processedNode); + switch(xmlNode.nodeType){ + case 1: + elementCount++; + //ELEMENT_NODE + console.log(xmlNode.nodeName); + if(xmlNode.nodeName == "parsererror"){ + return; + } + dgProcessNode = xmlNode.nodeName; + if(dgProcessNode == "call"){ + var attrs1 = xmlNode.attributes; + var moduleName = ""; + var rpcName = ""; + for(var i=0;i<attrs1.length;i++){ + if(attrs1[i].nodeName == "module"){ + moduleName = attrs1[i].value; + }else if(attrs1[i].nodeName == "rpc"){ + rpcName = attrs1[i].value; + } + } + console.log(moduleName + "_" + rpcName); + callNodes[moduleName + "_" + rpcName] = ""; + }else if(dgProcessNode == "set"){ + //console.log("found set node"); + var childNodes = xmlNode.childNodes; + //console.dir(childNodes); + for(var k=0;k<childNodes.length;k++){ + if(childNodes[k].nodeName == "parameter"){ + var parameterName=""; + var parameterValue=""; + var attrs2 = childNodes[k].attributes; + for(var i=0;i<attrs2.length;i++){ + if(attrs2[i].nodeName == "name"){ + parameterName = attrs2[i].value; + }else if(attrs2[i].nodeName == "value"){ + parameterValue = attrs2[i].value; + } + } + //console.log("PARAMETER:" + parameterName + ":" + parameterValue ); + } + } + }else{ + var attrs = xmlNode.attributes; + for(var i=0;i<attrs.length;i++){ + //console.log("Attribute:" + attrs[i].nodeName); + //console.log("Value:" + attrs[i].value); + if(attrs[i].value != "" && attrs[i].value.indexOf("$")){ + var attributeValue = attrs[i].value.trim().replace(/`/g, ""); + var splitVariables = attributeValue.split(" "); + for(var k=0;k<splitVariables.length;k++){ + var v = splitVariables[k].trim(); + //check if + if(v.indexOf("$") == 0){ + dgParsedParameters[v] = ""; + } + } + + } + } + + var childNodes = xmlNode.childNodes; + for(var k=0;k<childNodes.length;k++){ + extractSliParameters(childNodes[k]); + } + break; + } + case 2: + //ATTRIBUTE_NODE + //console.log(xmlNode.nodeName); + break; + case 3: + //TEXT_NODE + //console.log(xmlNode.nodeValue); + break; + case 4: + //CDATA_SECTION_NODE + console.log("CDATA_SECTION_NODE"); + break; + case 5: + //ENTITY_REFERENCE_NODE + console.log("ENTITY_REFERENCE_NODE"); + break; + case 6: + //ENTITY_NODE + console.log("ENTITY_NODE"); + break; + case 7: + //PROCESSING_INSTRUCTION_NODE + console.log("PROCESSING_INSTRUCTION_NODE"); + break; + case 8: + //COMMENT_NODE + console.log("COMMENT_NODE"); + break; + case 9: + //DOCUMENT_NODE + console.log("DOCUMENT_NODE"); + break; + case 10: + //DOCUMENT_TYPE_NODE + console.log("DOCUMENT_TYPE_NODE"); + break; + case 11: + //DOCUMENT_TYPE_NODE + console.log("DOCUMENT_FRAGMENT_NODE"); + break; + case 12: + //NOTATION_NODE + console.log("DOCUMENT_FRAGMENT_NODE"); + break; + } +} + +function getSliParametersFromDG(xmlStr){ + dgProcessNode=""; + dgParsedParameters = {}; + callNodes ={} ; + //var exportableNodeSet = getCurrentFlowNodeSet(); + if(xmlStr == undefined || xmlStr == ""){ + xmlStr = getNodeToXml(); + //console.log("xmlStr:" + xmlStr); + } + if(xmlStr == null || xmlStr == "") return true; + xmlStr = xmlStr.trim(); + try{ + var xmlDoc; + if (window.DOMParser){ + try{ + var parser=new DOMParser(); + xmlDoc=parser.parseFromString(xmlStr,'text/xml'); + //console.log("Not IE"); + var n = xmlDoc.documentElement.nodeName; + if(n == "html"){ + resp=false; + console.log("Error parsing"); + return resp; + } + }catch(e){ + console.log("Error parsing" +e); + return false; + } + }else{ + try{ + //console.log("IE"); + // code for IE + xmlDoc=new ActiveXObject("Microsoft.XMLDOM"); + xmlDoc.async=false; + xmlDoc.loadXMLString(xmlStr); + }catch(e){ + console.log("Error parsing" +e); + return false; + } + } + + //console.dir(xmlDoc); + extractSliParameters(xmlDoc.documentElement); + //console.dir(dgParsedParameters); + }catch(e){ + console.log("error:" +e); + RED.notify("<strong>XML validation</strong>: FAILED","error"); + return resp; + } +} |