package ie.dcu.apps.ist; import ie.dcu.util.*; import java.io.*; import java.net.*; import java.security.*; import java.util.*; import static ie.dcu.util.FileUtils.pathJoin; import static ie.dcu.util.OsUtils.*; /** * Base application. Contains information strings and methods to load * application wide resources. * * @author Kevin McGuinness */ public class Application { public static final String APP_ID = "ist"; public static final String APP_NAME = "AISO (Annotation of Image Segments using Ontologies)"; public static final String APP_VERSION = "0.2.1 (beta)"; public static final String APP_RESOURCE_DIR = "resources"; /** * Default locations to look for plugins */ public static final String[] DEFAULT_PLUGIN_SEARCH_PATH = defaultPluginSearchPath(); /** * Loads a properties file from the application resource area * (resources/config) * * @param name * The properties file name. ".properties" will be appended if * necessary. * @return A Properties object * @throws IOException * If there is an error creating the Properties object. */ public static Properties loadProperties(String name) throws IOException { if (!name.endsWith(".properties")) { name = name + ".properties"; } String path = FileUtils.pathJoin(APP_RESOURCE_DIR, "config", name); File file = new File(path); System.out.println("Path:" + file); return PropsUtils.load(file); } /** * Returns the users plugins folder */ public static String userPluginsFolder() { return pathJoin(userHome(), ".ist", "plugins"); } /** * Returns the applications base folder */ public static String applicationFolder() { String apphome = System.getenv("IST_HOME"); if (apphome != null) { File file = new File(apphome); if (file.isDirectory()) { return file.getAbsolutePath(); } } ProtectionDomain domain = Application.class.getProtectionDomain(); CodeSource source = domain.getCodeSource(); URL location = source.getLocation(); String path = location.getPath(); try { path = URLDecoder.decode(path, "UTF-8"); if (isWindows()) { path = path.substring(1); } path = new File(path).getParent(); } catch (UnsupportedEncodingException e) { path = System.getProperty("user.dir"); } return path; } public static String applicationPluginsFolder() { return pathJoin(applicationFolder(), "plugins"); } public static String osxPluginSearchPath() { return pathJoin(userHome(), "Library", "Application Support", APP_NAME, "Plugins"); } private static String[] defaultPluginSearchPath() { ArrayList paths = new ArrayList(); paths.add(userPluginsFolder()); if (isMacOSX()) { paths.add(osxPluginSearchPath()); } paths.add(applicationPluginsFolder()); return paths.toArray(new String[paths.size()]); } }