3 import java.io.IOException;
5 import tim.prune.config.Config;
9 * Class to manage interfaces to external tools, like exiftool
11 public abstract class ExternalTools
13 /** Constant for Exiftool */
14 public static final int TOOL_EXIFTOOL = 0;
15 /** Constant for Gpsbabel */
16 public static final int TOOL_GPSBABEL = 1;
17 /** Constant for Gnuplot */
18 public static final int TOOL_GNUPLOT = 2;
19 /** Constant for Xerces xml library */
20 public static final int TOOL_XERCES = 3;
21 /** Config keys in order that the tools are defined above */
22 private static final String[] CONFIG_KEYS = {Config.KEY_EXIFTOOL_PATH, Config.KEY_GPSBABEL_PATH, Config.KEY_GNUPLOT_PATH};
23 /** Verification flags for the tools in the order defined above */
24 private static final String[] VERIFY_FLAGS = {"-v", "-V", "-V"};
28 * Check if the selected tool is installed
29 * @param inToolNum number of tool, from constants
30 * @return true if selected tool is installed
32 public static boolean isToolInstalled(int inToolNum)
38 String toolPath = Config.getConfigString(CONFIG_KEYS[inToolNum]);
39 if (toolPath != null && toolPath.length() > 0) {
40 return check(toolPath + " " + VERIFY_FLAGS[inToolNum]);
45 return Class.forName("org.apache.xerces.parsers.SAXParser").getClassLoader() != null;
47 catch (ClassNotFoundException e) {
48 // System.err.println(e.getClass().getName() + " : " + e.getMessage());
57 * Check if the selected tool is installed using the given path
58 * @param inToolNum number of tool, from constants
59 * @param inPath selected path to use instead of configured one
60 * @return true if selected tool is installed
62 public static boolean isToolInstalled(int inToolNum, String inPath)
64 if (inPath == null || inPath.equals("")) {return false;}
69 return check(inPath + " " + VERIFY_FLAGS[inToolNum]);
76 * Attempt to call the specified command
77 * @return true if found, false otherwise
79 private static boolean check(String inCommand)
83 Runtime.getRuntime().exec(inCommand);
86 catch (IOException ioe)
88 // exception thrown, command not found