/** * Returns the translated value for the translation-key. If the current * language file doesn't contain the translated value, the default value * will be returned. * * @param key * key for the translation in the language file. the key should * <b>always</b> have the following structure * <i>PACKAGE_NAME_FROM_CALLER.CLASS_NAME_FROM_CALLER.key</i> * @param def * default value which will be returned if there is no mapping * for the key * @return translated value or the def parameter * @see Loc#LF(String, String, Object...) * @throws IllegalArgumentException * if the key is null or is empty */ public static String L(String key, final String def) { if (key == null || (key = key.trim()).length() == 0) { throw new IllegalArgumentException(); } if (Loc.DATA == null) { Log.L.warning("No parsed localization found! Loading now from saved localization file!"); try { Loc.setLocale(Loc.CFG.get(Loc.PROPERTY_LOCALE, Loc.FALLBACK_LOCALE)); } catch (final Exception e) { Log.L.severe("Error while loading the stored localization name!"); Loc.setLocale(Loc.FALLBACK_LOCALE); } if (Loc.DATA == null) { return def == null ? "Error in Loc! No loaded data!" : def; } } final String loc = Loc.DATA.get(key.toLowerCase().hashCode()); if (loc == null) { Loc.DATA.put(key.toLowerCase().hashCode(), def); return def; } return loc; }
@SuppressWarnings("unchecked") private void loadUnpacked() { URL ret = getClass().getResource("/"); File root; if (ret.getProtocol().equalsIgnoreCase("file")) { try { root = new File(ret.toURI()); } catch (URISyntaxException e) { Log.exception(e); Log.L.finer("Did not load unpacked Extensions from " + ret); return; } } else { Log.L.finer("Did not load unpacked Extensions from " + ret); return; } root = new File(root, AbstractExtension.class.getPackage().getName().replace('.', '/')); Log.L.finer("Load Extensions from: " + root.getAbsolutePath()); File[] folders = root.listFiles( new FileFilter() { public boolean accept(File pathname) { return pathname.isDirectory(); } }); ClassLoader cl = getClass().getClassLoader(); main: for (File f : folders) { File[] modules = f.listFiles( new FilenameFilter() { public boolean accept(File dir, String name) { return name.endsWith("Extension.class"); } }); boolean loaded = false; for (File module : modules) { Class<?> cls; try { cls = cl.loadClass( AbstractExtension.class.getPackage().getName() + "." + module.getParentFile().getName() + "." + module.getName().substring(0, module.getName().length() - 6)); if (AbstractExtension.class.isAssignableFrom(cls)) { loaded = true; initModule((Class<AbstractExtension<?>>) cls); continue main; } } catch (IllegalArgumentException e) { Log.L.warning("Did not init Extension " + module + " : " + e.getMessage()); } catch (Throwable e) { Log.exception(e); Dialog.getInstance().showExceptionDialog("Error", e.getMessage(), e); } } if (!loaded) { Log.L.warning("Could not load any Extension Module from " + f); } } }