1 package tim.prune.load.xml;
4 import java.io.FileInputStream;
5 import java.util.zip.GZIPInputStream;
7 import tim.prune.I18nManager;
8 import tim.prune.data.SourceInfo;
9 import tim.prune.load.MediaLinkInfo;
12 * Class to handle the loading of gzipped xml files
14 public class GzipFileLoader
16 /** App for callback of file loading */
17 private App _app = null;
18 /** Object to do the handling of the xml */
19 XmlFileLoader _xmlLoader = null;
23 * @param inApp App object
24 * @param inXmlLoader object to do the xml handling
26 public GzipFileLoader(App inApp, XmlFileLoader inXmlLoader)
29 _xmlLoader = inXmlLoader;
33 * Open the selected file and select appropriate xml loader
34 * @param inFile File to open
36 public void openFile(File inFile)
38 GZIPInputStream istream = null;
41 istream = new GZIPInputStream(new FileInputStream(inFile));
43 // Parse the stream using either Xerces or java classes
44 _xmlLoader.parseXmlStream(istream);
45 XmlHandler handler = _xmlLoader.getHandler();
46 if (handler == null) {
47 _app.showErrorMessage("error.load.dialogtitle", "error.load.noread");
52 SourceInfo sourceInfo = new SourceInfo(inFile,
53 (handler instanceof GpxHandler?SourceInfo.FILE_TYPE.GPX:SourceInfo.FILE_TYPE.KML));
54 _app.informDataLoaded(handler.getFieldArray(), handler.getDataArray(),
55 null, sourceInfo, handler.getTrackNameList(),
56 new MediaLinkInfo(inFile, handler.getLinkArray()));
61 // Error occurred, could be a non-xml file borking the parser
62 _app.showErrorMessageNoLookup("error.load.dialogtitle",
63 I18nManager.getText("error.load.othererror") + " " + e.getClass().getName());
64 // It would be nice to verify the filename of the file inside the gz,
65 // but the java classes don't give access to this information
71 catch (Exception e2) {}