changeset 29:4711c4ab0c23

Improved robustness of KML parsing (with Firefox and probably other browsers a missing node can lead to a NullPointerException that will not be catched by the try/catch)
author Sebastian Kruse <skruse@mpiwg-berlin.mpg.de>
date Wed, 28 Nov 2012 17:00:49 +0100
parents 6ec1ab4f897a
children 1e95995ddbb2
files war/scripts/sti/STICore.js
diffstat 1 files changed, 30 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- a/war/scripts/sti/STICore.js	Wed Nov 28 16:56:38 2012 +0100
+++ b/war/scripts/sti/STICore.js	Wed Nov 28 17:00:49 2012 +0100
@@ -338,25 +338,40 @@
 
             var placemark = elements[i];
 			var name, description, place, timeData, coordinates, timeStamp, timeSpan, g;
-
-			try {
-				name = placemark.getElementsByTagName("name")[0].childNodes[0].nodeValue;
-			}
-			catch(e){
+			
+			try{
+				var nameElement = placemark.getElementsByTagName("name"); 
+				if ( (nameElement != null) && (nameElement.length > 0) && (nameElement[0].childNodes.length > 0) ){
+					name = nameElement[0].childNodes[0].nodeValue;
+				}
+				else {
+					name = "";
+				}
+			} catch(e) {
 				name = "";
 			}
-
-			try {
-				description = placemark.getElementsByTagName("description")[0].childNodes[0].nodeValue;
-			}
-			catch(e){
+	
+			try{
+				var descriptionElement = placemark.getElementsByTagName("description"); 
+				if ( (descriptionElement != null) && (descriptionElement.length > 0) && (descriptionElement[0].childNodes.length > 0) ){
+					description = descriptionElement[0].childNodes[0].nodeValue;
+				}
+				else {
+					description = "";
+				}
+			} catch(e) {
 				description = "";
 			}
-
-			try {
-				place = placemark.getElementsByTagName("address")[0].childNodes[0].nodeValue;
-			}
-			catch(e){
+	
+			try{
+				var placeElement = placemark.getElementsByTagName("address"); 
+				if ( (placeElement != null) && (placeElement.length > 0) && (placeElement[0].childNodes.length > 0) ){
+					place = placeElement[0].childNodes[0].nodeValue;
+				}
+				else {
+					place = "";
+				}
+			} catch(e) {
 				place = "";
 			}