1 package tim.prune.load.xml;
4 import java.io.FileInputStream;
5 import java.util.zip.GZIPInputStream;
6 import javax.xml.parsers.SAXParser;
7 import javax.xml.parsers.SAXParserFactory;
9 import tim.prune.I18nManager;
10 import tim.prune.data.Altitude;
11 import tim.prune.data.SourceInfo;
14 * Class to handle the loading of gzipped xml files
16 public class GzipFileLoader
18 /** App for callback of file loading */
19 private App _app = null;
20 /** Object to do the handling of the xml */
21 XmlFileLoader _xmlLoader = null;
25 * @param inApp App object
26 * @param inXmlLoader object to do the xml handling
28 public GzipFileLoader(App inApp, XmlFileLoader inXmlLoader)
31 _xmlLoader = inXmlLoader;
35 * Open the selected file and select appropriate xml loader
36 * @param inFile File to open
38 public void openFile(File inFile)
40 GZIPInputStream istream = null;
43 istream = new GZIPInputStream(new FileInputStream(inFile));
45 SAXParser saxParser = SAXParserFactory.newInstance().newSAXParser();
46 saxParser.parse(istream, _xmlLoader);
47 XmlHandler handler = _xmlLoader.getHandler();
48 if (handler == null) {
49 _app.showErrorMessage("error.load.dialogtitle", "error.load.noread");
53 SourceInfo sourceInfo = new SourceInfo(inFile,
54 (handler instanceof GpxHandler?SourceInfo.FILE_TYPE.GPX:SourceInfo.FILE_TYPE.KML));
55 _app.informDataLoaded(handler.getFieldArray(), handler.getDataArray(),
56 Altitude.Format.METRES, sourceInfo, handler.getTrackNameList(), handler.getLinkArray());
60 // Error occurred, could be a non-xml file borking the parser
61 _app.showErrorMessageNoLookup("error.load.dialogtitle",
62 I18nManager.getText("error.load.othererror") + " " + e.getClass().getName());
63 // It would be nice to verify the filename of the file inside the gz,
64 // but the java classes don't give access to this information
70 catch (Exception e2) {}