File: GzipFileLoader.java

package info (click to toggle)
gpsprune 26.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 5,824 kB
  • sloc: java: 52,154; sh: 25; makefile: 21; python: 15
file content (70 lines) | stat: -rw-r--r-- 2,219 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package tim.prune.load.xml;

import java.io.FileInputStream;
import java.util.zip.GZIPInputStream;

import tim.prune.App;
import tim.prune.I18nManager;
import tim.prune.data.SourceInfo;
import tim.prune.load.FileToBeLoaded;
import tim.prune.load.FileTypeLoader;
import tim.prune.load.MediaLinkInfo;

/**
 * Class to handle the loading of gzipped xml files
 */
public class GzipFileLoader
{
	/** App for callback of file loading */
	private App _app = null;
	/** Object to do the handling of the xml */
	XmlFileLoader _xmlLoader = null;

	/**
	 * Constructor
	 * @param inApp App object
	 * @param inXmlLoader object to do the xml handling
	 */
	public GzipFileLoader(App inApp, XmlFileLoader inXmlLoader)
	{
		_app = inApp;
		_xmlLoader = inXmlLoader;
	}

	/**
	 * Open the selected file and select appropriate xml loader
	 * @param inFileLock File to open
	 * @param inAutoAppend true to auto-append
	 */
	public void openFile(FileToBeLoaded inFileLock, boolean inAutoAppend)
	{
		try (GZIPInputStream istream = new GZIPInputStream(new FileInputStream(inFileLock.getFile())))
		{
			_xmlLoader.reset();
			// Parse the stream using either Xerces or java classes
			_xmlLoader.parseXmlStream(istream);
			XmlHandler handler = _xmlLoader.getHandler();
			if (handler == null) {
				_app.showErrorMessage("error.load.dialogtitle", "error.load.noread");
			}
			else
			{
				// Send back to app
				SourceInfo sourceInfo = new SourceInfo(inFileLock.getFile(), handler.getFileType(), handler.getFileVersion());
				sourceInfo.setFileTitle(handler.getFileTitle());
				sourceInfo.setFileDescription(handler.getFileDescription());
				sourceInfo.setExtensionInfo(handler.getExtensionInfo());
				new FileTypeLoader(_app).loadData(handler, sourceInfo, inAutoAppend,
					new MediaLinkInfo(inFileLock.getFile(), handler.getLinkArray()));
			}
		}
		catch (Exception e)
		{
			// Error occurred, could be a non-xml file borking the parser
			_app.showErrorMessageNoLookup("error.load.dialogtitle",
				I18nManager.getText("error.load.othererror") + " " + e.getClass().getName());
			// It would be nice to verify the filename of the file inside the gz,
			// but the java classes don't give access to this information
		}
	}
}