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