@Override public Vector<ComboLanguage> getAvailableLocales() { final String bundlename = "freedomotic"; languages.clear(); File root = new File(Info.getApplicationPath() + File.separator + "i18n"); File[] files = root.listFiles( new FilenameFilter() { @Override public boolean accept(File dir, String name) { return name.matches("^" + bundlename + "(_\\w{2}(_\\w{2})?)?\\.properties$"); } }); for (File file : files) { String value = file.getName().replaceAll("^" + bundlename + "(_)?|\\.properties$", ""); if (!value.isEmpty()) { Locale loc = new Locale(value.substring(0, 2), value.substring(3, 5)); languages.add( new ComboLanguage( loc.getDisplayCountry(currentLocale) + " - " + loc.getDisplayLanguage(loc), value, loc)); } } Collections.sort(languages); languages.add(new ComboLanguage("Automatic", "auto", Locale.ENGLISH)); return languages; }
@Inject public I18nImpl(AppConfig config) { this.config = config; currentLocale = Locale.getDefault(); messages = new HashMap<String, ResourceBundle>(); RB_Control = new UTF8control(); languages = new Vector<ComboLanguage>(); packageBundleDir = new HashMap<String, File>(); // add mapping for base strings packageBundleDir.put("com.freedomotic", new File(Info.getApplicationPath() + "/i18n")); }
/** @param folder */ public static synchronized void loadTriggers(File folder) { XStream xstream = FreedomXStream.getXstream(); // This filter only returns object files FileFilter objectFileFileter = new FileFilter() { public boolean accept(File file) { if (file.isFile() && file.getName().endsWith(".xtrg")) { return true; } else { return false; } } }; File[] files = folder.listFiles(objectFileFileter); try { StringBuilder summary = new StringBuilder(); // print an header for the index.txt file summary.append("#Filename \t\t #TriggerName \t\t\t #ListenedChannel").append("\n"); if (files != null) { for (File file : files) { Trigger trigger = null; try { // validate the object against a predefined DTD String xml = DOMValidateDTD.validate( file, Info.getApplicationPath() + "/config/validator/trigger.dtd"); trigger = (Trigger) xstream.fromXML(xml); } catch (Exception e) { LOG.log( Level.SEVERE, "Trigger file {0} is not well formatted: {1}", new Object[] {file.getPath(), e.getLocalizedMessage()}); continue; } // addAndRegister trigger to the list if it is not a duplicate if (!list.contains(trigger)) { if (trigger.isHardwareLevel()) { trigger.setPersistence(false); // it has not to me stored in root/data folder addAndRegister(trigger); // in the list and start listening } else { if (folder.getAbsolutePath().startsWith(Info.getPluginsPath())) { trigger.setPersistence(false); } else { trigger.setPersistence(true); // not hardware trigger and not plugin related } list.add( trigger); // only in the list not registred. I will be registred only if used in // mapping } } else { LOG.warning("Trigger '" + trigger.getName() + "' is already in the list"); } summary .append(trigger.getUUID()) .append("\t\t") .append(trigger.getName()) .append("\t\t\t") .append(trigger.getChannel()) .append("\n"); } // writing a summary .txt file with the list of commands in this folder FileWriter fstream = new FileWriter(folder + "/index.txt"); BufferedWriter indexfile = new BufferedWriter(fstream); indexfile.write(summary.toString()); // Close the output stream indexfile.close(); } else { LOG.config("No triggers to load from this folder " + folder.toString()); } } catch (Exception e) { LOG.severe("Exception while loading this trigger.\n" + Freedomotic.getStackTraceInfo(e)); } }