]> gitweb.fperrin.net Git - GpsPrune.git/blob - tim/prune/jpeg/ExifGateway.java
Version 11, August 2010
[GpsPrune.git] / tim / prune / jpeg / ExifGateway.java
1 package tim.prune.jpeg;
2
3 import java.io.File;
4
5 import javax.swing.JOptionPane;
6
7 import tim.prune.I18nManager;
8
9 /**
10  * Skeleton gateway to the Exif functions.
11  * This is required by Debian to divert Exif handling
12  * to the external libmetadata-extractor-java library
13  * instead of the included modified routines.
14  *
15  * To use the internal routines, set the USE_INTERNAL_LIBRARY flag to true
16  * and include the internal classes in the compiled jar.
17  * To use the external library, set the USE_INTERNAL_LIBRARY flag to false
18  * and do not export the internal classes.
19  */
20 public abstract class ExifGateway
21 {
22         /** Library object to call */
23         private static ExifLibrary _exifLibrary = null;
24         /** Flag to set whether failure warning has already been shown */
25         private static boolean _exifFailWarned = false;
26
27         /** Static block to initialise library */
28         static
29         {
30                 String libraryClass = ExifLibrarySwitch.USE_INTERNAL_LIBRARY?"InternalExifLibrary":"ExternalExifLibrary";
31                 try
32                 {
33                         _exifLibrary = (ExifLibrary) Class.forName("tim.prune.jpeg." + libraryClass).newInstance();
34                 }
35                 catch (Throwable nolib) {_exifLibrary = null;}
36         }
37
38
39         /**
40          * Get the Jpeg data from the given file
41          * @param inFile file to read
42          * @return jpeg data, or null if none found
43          */
44         public static JpegData getJpegData(File inFile)
45         {
46                 try
47                 {
48                         // Call library (if found)
49                         if (_exifLibrary != null) {
50                                 JpegData data = _exifLibrary.getJpegData(inFile);
51                                 return data;
52                         }
53                 }
54                 catch (LinkageError nolib) {}
55                 // Not successful - warn if necessary
56                 if (!_exifFailWarned)
57                 {
58                         JOptionPane.showMessageDialog(null, I18nManager.getText("error.jpegload.exifreadfailed"),
59                                 I18nManager.getText("error.jpegload.dialogtitle"), JOptionPane.WARNING_MESSAGE);
60                         _exifFailWarned = true;
61                 }
62                 return null;
63         }
64
65         /**
66          * @return key to use to describe library, matching key for about dialog
67          */
68         public static String getDescriptionKey()
69         {
70                 String key = ExifLibrarySwitch.USE_INTERNAL_LIBRARY?"internal":"external";
71                 if (_exifLibrary == null || !_exifLibrary.looksOK()) {key = key + ".failed";}
72                 return key;
73         }
74 }