File: ExifGateway.java

package info (click to toggle)
gpsprune 10-1
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 2,220 kB
  • ctags: 3,013
  • sloc: java: 22,662; sh: 23; makefile: 16; python: 15
file content (80 lines) | stat: -rw-r--r-- 2,350 bytes parent folder | download
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
71
72
73
74
75
76
77
78
79
80
package tim.prune.jpeg;

import java.io.File;

import javax.swing.JOptionPane;

import tim.prune.I18nManager;

/**
 * Skeleton gateway to the Exif functions.
 * This is required by Debian to divert Exif handling
 * to the external libmetadata-extractor-java library
 * instead of the included modified routines.
 *
 * To use the internal routines, set the USE_INTERNAL_LIBRARY flag to true
 * and include the internal classes in the compiled jar.
 * To use the external library, set the USE_INTERNAL_LIBRARY flag to false
 * and do not export the internal classes.
 */
public abstract class ExifGateway
{
	// *********************************************************
	// TODO: Check this exif library flag before releasing!
	/** Flag to specify internal or external library */
	private static final boolean USE_INTERNAL_LIBRARY = false;
	// *********************************************************

	/** Library object to call */
	private static ExifLibrary _exifLibrary = null;
	/** Flag to set whether failure warning has already been shown */
	private static boolean _exifFailWarned = false;

	/** Static block to initialise library */
	static
	{
		String libraryClass = USE_INTERNAL_LIBRARY?"InternalExifLibrary":"ExternalExifLibrary";
		try
		{
			_exifLibrary = (ExifLibrary) Class.forName("tim.prune.jpeg." + libraryClass).newInstance();
		}
		catch (Throwable nolib) {_exifLibrary = null;}
	}


	/**
	 * Get the Jpeg data from the given file
	 * @param inFile file to read
	 * @return jpeg data, or null if none found
	 */
	public static JpegData getJpegData(File inFile)
	{
		try
		{
			// Call library (if found)
			if (_exifLibrary != null) {
				JpegData data = _exifLibrary.getJpegData(inFile);
				return data;
			}
		}
		catch (LinkageError nolib) {}
		// Not successful - warn if necessary
		if (!_exifFailWarned)
		{
			JOptionPane.showMessageDialog(null, I18nManager.getText("error.jpegload.exifreadfailed"),
				I18nManager.getText("error.jpegload.dialogtitle"), JOptionPane.WARNING_MESSAGE);
			_exifFailWarned = true;
		}
		return null;
	}

	/**
	 * @return key to use to describe library, matching key for about dialog
	 */
	public static String getDescriptionKey()
	{
		String key = USE_INTERNAL_LIBRARY?"internal":"external";
		if (_exifLibrary == null || !_exifLibrary.looksOK()) {key = key + ".failed";}
		return key;
	}
}