X-Git-Url: http://gitweb.fperrin.net/?a=blobdiff_plain;f=tim%2Fprune%2Fload%2Fxml%2FXmlFileLoader.java;h=d528420029a325f8cfc33238de6c80b5c55ef8cc;hb=6814c830d470f73c7ec57c71235de333f5ea4279;hp=3f1b2eb6fed19246785cf41a883e75a5c4b7f476;hpb=54b9d8bc8f0025ccf97a67d9dd217ef1f9cf082f;p=GpsPrune.git diff --git a/tim/prune/load/xml/XmlFileLoader.java b/tim/prune/load/xml/XmlFileLoader.java index 3f1b2eb..d528420 100644 --- a/tim/prune/load/xml/XmlFileLoader.java +++ b/tim/prune/load/xml/XmlFileLoader.java @@ -1,6 +1,8 @@ package tim.prune.load.xml; import java.io.File; +import java.io.FileInputStream; + import javax.xml.parsers.SAXParser; import javax.xml.parsers.SAXParserFactory; @@ -10,6 +12,7 @@ import org.xml.sax.helpers.DefaultHandler; import tim.prune.App; import tim.prune.I18nManager; import tim.prune.data.Altitude; +import tim.prune.data.SourceInfo; /** * Class for handling loading of Xml files, and passing the @@ -60,11 +63,13 @@ public class XmlFileLoader extends DefaultHandler implements Runnable */ public void run() { + FileInputStream inStream = null; try { // Construct a SAXParser and use this as a default handler SAXParser saxParser = SAXParserFactory.newInstance().newSAXParser(); - saxParser.parse(_file, this); + inStream = new FileInputStream(_file); + saxParser.parse(inStream, this); // Check whether handler was properly instantiated if (_handler == null) @@ -76,12 +81,19 @@ public class XmlFileLoader extends DefaultHandler implements Runnable else { // Pass information back to app + SourceInfo sourceInfo = new SourceInfo(_file, + (_handler instanceof GpxHandler?SourceInfo.FILE_TYPE.GPX:SourceInfo.FILE_TYPE.KML)); _app.informDataLoaded(_handler.getFieldArray(), _handler.getDataArray(), - Altitude.Format.METRES, _file.getName()); + Altitude.Format.METRES, sourceInfo, _handler.getTrackNameList()); } } catch (Exception e) { + // clean up file stream + try { + inStream.close(); + } + catch (Exception e2) {} // Show error dialog _app.showErrorMessageNoLookup("error.load.dialogtitle", I18nManager.getText("error.load.othererror") + " " + e.getMessage());