blob: d57ba0d72cc02bf4896b114335b3fad8c28051ec [file] [log] [blame]
Chinthakayala, Sheshashailavas (sc2914)d1569972017-08-28 05:25:46 -09001function resetStatus(){
2 showMsg("","green");
3}
4
5function showMsg(msg,color){
6 $("#node-validate-result").html(msg);
7 $("#node-validate-result")
8 .css('color', '')
9 .css('color', color);
10}
11
12function getAttributeValue(xmlStr,attribute){
13
14 var attrVal=null;
15 try{
16 if(xmlStr != null){
17 var myRe = new RegExp(attribute + "[\s+]?=[\s+]?['\"]([^'\"]+)['\"]","m");
18 var myArray = myRe.exec(xmlStr);
19 if(myArray != null && myArray[1] != null){
20 attrVal=myArray[1];
21 }
22 }
23 }catch(err){
24 console.log(err);
25 }
26 return attrVal;
27}
28
29
30var resp = true;
31var processedNode = "";
32var errList=[];
33var elementCount=0;
34function processNode(xmlNode){
35 if(xmlNode == null) return;
36 if(xmlNode.nodeName != "parsererror" && xmlNode.nodeName != "#text"){
37 processedNode = xmlNode.nodeName;
38 }
39 //console.log("processedNode:" + processedNode);
40 switch(xmlNode.nodeType){
41 case 1:
42 elementCount++;
43 //ELEMENT_NODE
44 //console.log(xmlNode.nodeName);
45 //console.dir(xmlNode.nodeName);
46 if(xmlNode.nodeName == "parsererror"){
47 //var nearNode = xmlNode.previousSibling != null ?xmlNode.previousSibling.nodeName : xmlNode.parentNode.nodeName;
48 console.log("Error parsing xml after node " + processedNode);
49 var msg = "error parsing XML after element <" + processedNode + "> Element#" + elementCount;
50 errList.push(msg);
51 resp = false;
52 return;
53 }
54 processedNode = xmlNode.nodeName;
55 var attrs = xmlNode.attributes;
56 for(var i=0;i<attrs.length;i++){
57 //console.log("Attribute:" + attrs[i].nodeName);
58 //console.log("Value:" + attrs[i].value);
59 if(attrs[i].nodeName != "value" && attrs[i].value == ""){
60 var msg="";
61 /*
62 var prevSibling = xmlNode.previousSibling;
63 if(prevSibling != null && prevSibling != undefined){
64 msg = "element &lt;" + xmlNode.nodeName + "&gt; attribute '" + attrs[i].nodeName + "' is not set. Element#" + elementCount;
65 }else{
66 msg = "element &lt;" + xmlNode.nodeName + "&gt; attribute '" + attrs[i].nodeName + "' is not set. Element#" + elementCount;
67 }
68 */
69 msg = "element &lt;" + xmlNode.nodeName + "&gt; attribute '" + attrs[i].nodeName + "' is not set. Element#" + elementCount;
70 errList.push(msg);
71 //console.log("element <" + xmlNode.nodeName + "> attribute '" + attrs[i].nodeName + "' is not set.Element#" + elementCount);
72 resp = false;
73 }
74 }
75 var childNodes = xmlNode.childNodes;
76 for(var k=0;k<childNodes.length;k++){
77 processNode(childNodes[k]);
78 }
79 break;
80 case 2:
81 //ATTRIBUTE_NODE
82 //console.log(xmlNode.nodeName);
83 break;
84 case 3:
85 //TEXT_NODE
86 //console.log(xmlNode.nodeValue);
87 break;
88 case 4:
89 //CDATA_SECTION_NODE
90 console.log("CDATA_SECTION_NODE");
91 break;
92 case 5:
93 //ENTITY_REFERENCE_NODE
94 console.log("ENTITY_REFERENCE_NODE");
95 break;
96 case 6:
97 //ENTITY_NODE
98 console.log("ENTITY_NODE");
99 break;
100 case 7:
101 //PROCESSING_INSTRUCTION_NODE
102 console.log("PROCESSING_INSTRUCTION_NODE");
103 break;
104 case 8:
105 //COMMENT_NODE
106 console.log("COMMENT_NODE");
107 break;
108 case 9:
109 //DOCUMENT_NODE
110 console.log("DOCUMENT_NODE");
111 break;
112 case 10:
113 //DOCUMENT_TYPE_NODE
114 console.log("DOCUMENT_TYPE_NODE");
115 break;
116 case 11:
117 //DOCUMENT_TYPE_NODE
118 console.log("DOCUMENT_FRAGMENT_NODE");
119 break;
120 case 12:
121 //NOTATION_NODE
122 console.log("DOCUMENT_FRAGMENT_NODE");
123 break;
124 }
125}
126
127function validateFinalXML(xmlStr){
128
129 //console.dir(RED);
130 processedNode="";
131 resp=true;
132 errList=[];
133 elementCount=0;
134 //console.log("In validateXML xmlStr:" + xmlStr);
135 if(xmlStr == null || xmlStr == "") return true;
136 xmlStr = xmlStr.trim();
137 try{
138 var xmlDoc;
139 if (window.DOMParser){
140 try{
141 var parser=new DOMParser();
142 xmlDoc=parser.parseFromString(xmlStr,'text/xml');
143 //console.log("Not IE");
144 var n = xmlDoc.documentElement.nodeName;
145 if(n == "html"){
146 resp=false;
147 console.log("Error parsing");
148 return resp;
149 }
150 }catch(e){
151 console.log("Error parsing" +e);
152 return false;
153 }
154 }else{
155 try{
156 //console.log("IE");
157 // code for IE
158 xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
159 xmlDoc.async=false;
160 xmlDoc.loadXMLString(xmlStr);
161 }catch(e){
162 console.log("Error parsing" +e);
163 return false;
164 }
165 }
166
167 //console.dir(xmlDoc);
168 processNode(xmlDoc.documentElement);
169
170 if(resp){
171 console.log("Validation Successful");
172 RED.notify("<strong>XML validation</strong>: SUCCESS","success");
173 }else{
174 console.log("Errors found. ");
175 RED.notify("<strong>XML validation</strong>: FAILED","error");
176 }
177 }catch(e){
178 console.log("error:" +e);
179 RED.notify("<strong>XML validation</strong>: FAILED","error");
180 resp=false;
181 return resp;
182 }
183 return resp;
184}
185
186function validateXML(xmlStr){
187
188 //console.dir(RED);
189 processedNode="";
190 resp=true;
191 errList=[];
192 elementCount=0;
Chinthakayala,Sheshashailavas(sc2914)8f6a6c42018-06-27 16:11:44 +0000193 console.log("In validateXML xmlStr:" + xmlStr);
Chinthakayala, Sheshashailavas (sc2914)d1569972017-08-28 05:25:46 -0900194 //var xmlStr = $("#node-input-xml-editor").text();
195 if(xmlStr == null || xmlStr == undefined){
196 xmlStr = $("#node-input-xml-editor").text();
197 }
198 if(xmlStr == undefined) return false;
199 //console.dir($("#node-input-xml-editor"));
200 //console.log("xmlStr:" + xmlStr);
201 xmlStr = xmlStr.trim();
202 var startTag ;
203 var endTag ;
204 try{
205 var re = /^[0-9]+/;
206 xmlStr = xmlStr.replace(re,'');
207 var regex = /(<)([\w-]+)(.*)?/;
208 var match = regex.exec(xmlStr);
209 if(match != null){
210 if(match[1] != undefined && match[2] != undefined){
211 startTag = match[2];
212 }
213 }else{
214 resp=false;
215 showMsg("startTag not found.","red");
216 return resp;
217 }
218 }catch(e){
219 console.log(e);
220 return false;
221 }
222 //console.log(xmlStr);
223 if(xmlStr == ""){
224 resp=false;
225 showMsg("XML not found","red");
226 return resp;
227 }
228 endTag = "</" + startTag + ">";
229
230 if(xmlStr.indexOf(endTag) != -1){
231 resp=false;
232 showMsg("Error: End tag &lt;/" + startTag + "&gt; must not be included.","red");
233 console.log("End tag " + endTag + " must not be included.");
234 return resp;
235 }
236 try{
237 //var xmlTopStr = "<?xml version='1.0' encoding='UTF-8'?>\n" ;
238 //xmlStr = xmlTopStr + xmlStr;
239 //xmlStr = xmlStr.replace(/'/g,"\"");
240 xmlStr+= "\n" + endTag;
241 xmlStr = xmlStr.trim();
242 //console.log("xmlStr:" + xmlStr);
243 var xmlDoc;
244 if (window.DOMParser){
245 try{
246 var parser=new DOMParser();
247 xmlDoc=parser.parseFromString(xmlStr,'text/xml');
248 //console.log("Not IE");
249 var n = xmlDoc.documentElement.nodeName;
250 if(n == "html"){
251 resp=false;
252 showMsg("Error parsing","red");
253 console.log("Error parsing");
254 return resp;
255 }
256 }catch(e){
257 console.log("Error parsing" +e);
258 return false;
259 }
260 }else{
261 try{
262 //console.log("IE");
263 // code for IE
264 xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
265 xmlDoc.async=false;
266 xmlDoc.loadXMLString(xmlStr);
267 }catch(e){
268 console.log("Error parsing" +e);
269 return false;
270 }
271 }
272
273 //console.dir(xmlDoc);
274 processNode(xmlDoc.documentElement);
275 if(resp){
276 showMsg("Validation Successful","green");
277 }else{
278 showMsg("Errors found. <a onclick='javascript:showErrors()'>show errors</a>","red");
279 console.log("Errors found. ");
280 }
281 }catch(e){
282 console.log("error:" +e);
283 showMsg(e,"red");
284 resp=false;
285 return resp;
286 }
287 return resp;
288}
289
290function showErrors() {
291 //var sourceField = event != null ?event.srcElement:event.target;
292 //console.dir(sourceField);
293 //sourceField.style.backgroundColor="skyblue";
294 //var leftVal = event.target.offsetLeft ;
295 //alert(topVal + ":" + leftVal);
296 /*left:leftVal,*/
297 //var pos = event.target;
298 //var topVal = event.target.offsetTop + topPosition ;
299 //var topVal = event.target.offsetTop +75;
300 var htmlStr="<div id='error-list-div'><table id='errTable' border='1'><tr><th>Error List</th></tr>";
301 for(var i=0;errList != null && i<errList.length;i++){
302 var errSeq = i+1;
303 htmlStr += "<tr><td>" + errSeq + ")" + errList[i] + "</td></tr>";
304 }
305 htmlStr += "</table></div>";
306 //var prevHtml = $("#tab-info").html();
307 //htmlStr += "<input type='button' value='Hide Errors' onclick=\"closeShowErrors('" + prevHtml + "')\" >";
308 //$('#show-errors-div').html(htmlStr);
309 //$("#tab-info").html(prevHtml + htmlStr);
310
311 //$('<div></div>').dialog({
312 $('#show-errors-dialog').dialog({
313 modal: true,
314 title: "XML Error List ",
315 width: 500,
316 open: function () {
317 $(this).html(htmlStr);
318 },
319 buttons: {
320 Close: function () {
321 $(this).dialog("close");
322 }
323 }
324 }); // end dialog div
325}
Chinthakayala,Sheshashailavas(sc2914)8f6a6c42018-06-27 16:11:44 +0000326
327var dgParsedParameters ;
328var dgProcessNode ;
329var callNodes ;
330function extractSliParameters(xmlNode){
331 if(xmlNode == null) return;
332 if(xmlNode.nodeName != "parsererror" && xmlNode.nodeName != "#text"){
333 dgProcessNode = xmlNode.nodeName;
334 }
335 //console.log("processedNode:" + processedNode);
336 switch(xmlNode.nodeType){
337 case 1:
338 elementCount++;
339 //ELEMENT_NODE
340 console.log(xmlNode.nodeName);
341 if(xmlNode.nodeName == "parsererror"){
342 return;
343 }
344 dgProcessNode = xmlNode.nodeName;
345 if(dgProcessNode == "call"){
346 var attrs1 = xmlNode.attributes;
347 var moduleName = "";
348 var rpcName = "";
349 for(var i=0;i<attrs1.length;i++){
350 if(attrs1[i].nodeName == "module"){
351 moduleName = attrs1[i].value;
352 }else if(attrs1[i].nodeName == "rpc"){
353 rpcName = attrs1[i].value;
354 }
355 }
356 console.log(moduleName + "_" + rpcName);
357 callNodes[moduleName + "_" + rpcName] = "";
358 }else if(dgProcessNode == "set"){
359 //console.log("found set node");
360 var childNodes = xmlNode.childNodes;
361 //console.dir(childNodes);
362 for(var k=0;k<childNodes.length;k++){
363 if(childNodes[k].nodeName == "parameter"){
364 var parameterName="";
365 var parameterValue="";
366 var attrs2 = childNodes[k].attributes;
367 for(var i=0;i<attrs2.length;i++){
368 if(attrs2[i].nodeName == "name"){
369 parameterName = attrs2[i].value;
370 }else if(attrs2[i].nodeName == "value"){
371 parameterValue = attrs2[i].value;
372 }
373 }
374 //console.log("PARAMETER:" + parameterName + ":" + parameterValue );
375 }
376 }
377 }else{
378 var attrs = xmlNode.attributes;
379 for(var i=0;i<attrs.length;i++){
380 //console.log("Attribute:" + attrs[i].nodeName);
381 //console.log("Value:" + attrs[i].value);
382 if(attrs[i].value != "" && attrs[i].value.indexOf("$")){
383 var attributeValue = attrs[i].value.trim().replace(/`/g, "");
384 var splitVariables = attributeValue.split(" ");
385 for(var k=0;k<splitVariables.length;k++){
386 var v = splitVariables[k].trim();
387 //check if
388 if(v.indexOf("$") == 0){
389 dgParsedParameters[v] = "";
390 }
391 }
392
393 }
394 }
395
396 var childNodes = xmlNode.childNodes;
397 for(var k=0;k<childNodes.length;k++){
398 extractSliParameters(childNodes[k]);
399 }
400 break;
401 }
402 case 2:
403 //ATTRIBUTE_NODE
404 //console.log(xmlNode.nodeName);
405 break;
406 case 3:
407 //TEXT_NODE
408 //console.log(xmlNode.nodeValue);
409 break;
410 case 4:
411 //CDATA_SECTION_NODE
412 console.log("CDATA_SECTION_NODE");
413 break;
414 case 5:
415 //ENTITY_REFERENCE_NODE
416 console.log("ENTITY_REFERENCE_NODE");
417 break;
418 case 6:
419 //ENTITY_NODE
420 console.log("ENTITY_NODE");
421 break;
422 case 7:
423 //PROCESSING_INSTRUCTION_NODE
424 console.log("PROCESSING_INSTRUCTION_NODE");
425 break;
426 case 8:
427 //COMMENT_NODE
428 console.log("COMMENT_NODE");
429 break;
430 case 9:
431 //DOCUMENT_NODE
432 console.log("DOCUMENT_NODE");
433 break;
434 case 10:
435 //DOCUMENT_TYPE_NODE
436 console.log("DOCUMENT_TYPE_NODE");
437 break;
438 case 11:
439 //DOCUMENT_TYPE_NODE
440 console.log("DOCUMENT_FRAGMENT_NODE");
441 break;
442 case 12:
443 //NOTATION_NODE
444 console.log("DOCUMENT_FRAGMENT_NODE");
445 break;
446 }
447}
448
449function getSliParametersFromDG(xmlStr){
450 dgProcessNode="";
451 dgParsedParameters = {};
452 callNodes ={} ;
453 //var exportableNodeSet = getCurrentFlowNodeSet();
454 if(xmlStr == undefined || xmlStr == ""){
455 xmlStr = getNodeToXml();
456 //console.log("xmlStr:" + xmlStr);
457 }
458 if(xmlStr == null || xmlStr == "") return true;
459 xmlStr = xmlStr.trim();
460 try{
461 var xmlDoc;
462 if (window.DOMParser){
463 try{
464 var parser=new DOMParser();
465 xmlDoc=parser.parseFromString(xmlStr,'text/xml');
466 //console.log("Not IE");
467 var n = xmlDoc.documentElement.nodeName;
468 if(n == "html"){
469 resp=false;
470 console.log("Error parsing");
471 return resp;
472 }
473 }catch(e){
474 console.log("Error parsing" +e);
475 return false;
476 }
477 }else{
478 try{
479 //console.log("IE");
480 // code for IE
481 xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
482 xmlDoc.async=false;
483 xmlDoc.loadXMLString(xmlStr);
484 }catch(e){
485 console.log("Error parsing" +e);
486 return false;
487 }
488 }
489
490 //console.dir(xmlDoc);
491 extractSliParameters(xmlDoc.documentElement);
492 //console.dir(dgParsedParameters);
493 }catch(e){
494 console.log("error:" +e);
495 RED.notify("<strong>XML validation</strong>: FAILED","error");
496 return resp;
497 }
498}