changeset 430:1295512197f8 Dev_main

Bug #1502: Any parser XML errors will show the error and halt the rest of the loading.
author Nicholas Jillings <n.g.r.jillings@se14.qmul.ac.uk>
date Fri, 18 Dec 2015 18:28:06 +0000
parents a066b8bc556f
children cb2132a83247
files core.js
diffstat 1 files changed, 27 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/core.js	Fri Dec 18 17:54:47 2015 +0000
+++ b/core.js	Fri Dec 18 18:28:06 2015 +0000
@@ -66,6 +66,18 @@
 	
 	var parse = new DOMParser();
 	projectXML = parse.parseFromString(response,'text/xml');
+	var errorNode = projectXML.getElementsByTagName('parsererror');
+	if (errorNode.length >= 1)
+	{
+		var msg = document.createElement("h3");
+		msg.textContent = "FATAL ERROR";
+		var span = document.createElement("span");
+		span.textContent = "The XML parser returned the following errors when decoding your XML file";
+		document.getElementsByTagName('body')[0].appendChild(msg);
+		document.getElementsByTagName('body')[0].appendChild(span);
+		document.getElementsByTagName('body')[0].appendChild(errorNode[0]);
+		return;
+	}
 	
 	// Build the specification
 	specification.decode(projectXML);
@@ -185,11 +197,21 @@
 function errorSessionDump(msg){
 	// Create the partial interface XML save
 	// Include error node with message on why the dump occured
+	popup.showPopup();
+	popup.popupContent.innerHTML = null;
+	var err = document.createElement('error');
+	var parent = document.createElement("div");
+	if (typeof msg === "object")
+	{
+		err.appendChild(msg);
+		popup.popupContent.appendChild(msg);
+		
+	} else {
+		err.textContent = msg;
+		popup.popupContent.innerHTML = "ERROR : "+msg;
+	}
 	var xmlDoc = interfaceXMLSave();
-	var err = document.createElement('error');
-	err.textContent = msg;
 	xmlDoc.appendChild(err);
-	var parent = document.createElement("div");
 	parent.appendChild(xmlDoc);
 	var file = [parent.innerHTML];
 	var bb = new Blob(file,{type : 'application/xml'});
@@ -200,8 +222,8 @@
 	a.download = "save.xml";
 	a.textContent = "Save File";
 	
-	popup.showPopup();
-	popup.popupContent.innerHTML = "ERROR : "+msg;
+	
+	
 	popup.popupContent.appendChild(a);
 }