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;
12 import tim.prune.load.MediaLinkInfo;
15 * Class to handle the loading of gzipped xml files
17 public class GzipFileLoader
19 /** App for callback of file loading */
20 private App _app = null;
21 /** Object to do the handling of the xml */
22 XmlFileLoader _xmlLoader = null;
26 * @param inApp App object
27 * @param inXmlLoader object to do the xml handling
29 public GzipFileLoader(App inApp, XmlFileLoader inXmlLoader)
32 _xmlLoader = inXmlLoader;
36 * Open the selected file and select appropriate xml loader
37 * @param inFile File to open
39 public void openFile(File inFile)
41 GZIPInputStream istream = null;
44 istream = new GZIPInputStream(new FileInputStream(inFile));
46 SAXParser saxParser = SAXParserFactory.newInstance().newSAXParser();
47 saxParser.parse(istream, _xmlLoader);
48 XmlHandler handler = _xmlLoader.getHandler();
49 if (handler == null) {
50 _app.showErrorMessage("error.load.dialogtitle", "error.load.noread");
55 SourceInfo sourceInfo = new SourceInfo(inFile,
56 (handler instanceof GpxHandler?SourceInfo.FILE_TYPE.GPX:SourceInfo.FILE_TYPE.KML));
57 _app.informDataLoaded(handler.getFieldArray(), handler.getDataArray(),
58 Altitude.Format.METRES, sourceInfo, handler.getTrackNameList(),
59 new MediaLinkInfo(inFile, handler.getLinkArray()));
64 // Error occurred, could be a non-xml file borking the parser
65 _app.showErrorMessageNoLookup("error.load.dialogtitle",
66 I18nManager.getText("error.load.othererror") + " " + e.getClass().getName());
67 // It would be nice to verify the filename of the file inside the gz,
68 // but the java classes don't give access to this information
74 catch (Exception e2) {}