]> gitweb.fperrin.net Git - GpsPrune.git/blob - tim/prune/jpeg/ExifGateway.java
5420ea6762fe9d0c534e2a7aa72a8f7dc4c43561
[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         // *********************************************************
23         // TODO: Check this exif library flag before releasing!
24         /** Flag to specify internal or external library */
25         private static final boolean USE_INTERNAL_LIBRARY = true;
26         // *********************************************************
27
28         /** Library object to call */
29         private static ExifLibrary _exifLibrary = null;
30         /** Flag to set whether failure warning has already been shown */
31         private static boolean _exifFailWarned = false;
32
33         /** Static block to initialise library */
34         static
35         {
36                 String libraryClass = USE_INTERNAL_LIBRARY?"InternalExifLibrary":"ExternalExifLibrary";
37                 try
38                 {
39                         _exifLibrary = (ExifLibrary) Class.forName("tim.prune.jpeg." + libraryClass).newInstance();
40                 }
41                 catch (Throwable nolib) {_exifLibrary = null;}
42         }
43
44
45         /**
46          * Get the Jpeg data from the given file
47          * @param inFile file to read
48          * @return jpeg data, or null if none found
49          */
50         public static JpegData getJpegData(File inFile)
51         {
52                 try
53                 {
54                         // Call library (if found)
55                         if (_exifLibrary != null) {
56                                 JpegData data = _exifLibrary.getJpegData(inFile);
57                                 return data;
58                         }
59                 }
60                 catch (LinkageError nolib) {}
61                 // Not successful - warn if necessary
62                 if (!_exifFailWarned)
63                 {
64                         JOptionPane.showMessageDialog(null, I18nManager.getText("error.jpegload.exifreadfailed"),
65                                 I18nManager.getText("error.jpegload.dialogtitle"), JOptionPane.WARNING_MESSAGE);
66                         _exifFailWarned = true;
67                 }
68                 return null;
69         }
70
71         /**
72          * @return key to use to describe library, matching key for about dialog
73          */
74         public static String getDescriptionKey()
75         {
76                 String key = USE_INTERNAL_LIBRARY?"internal":"external";
77                 if (_exifLibrary == null || !_exifLibrary.looksOK()) {key = key + ".failed";}
78                 return key;
79         }
80 }