List of usage examples for java.util PropertyResourceBundle PropertyResourceBundle
@SuppressWarnings({ "unchecked", "rawtypes" }) public PropertyResourceBundle(Reader reader) throws IOException
From source file:org.gcaldaemon.gui.Messages.java
public static final String[][] getTranslatorTable(Locale locale) { Enumeration keyEnumerator = DEFAULT_RESOURCE_BUNDLE.getKeys(); LinkedList list = new LinkedList(); while (keyEnumerator.hasMoreElements()) { list.addLast(keyEnumerator.nextElement()); }//from w w w. j a va 2s .c o m String[] keys = new String[list.size()]; list.toArray(keys); Arrays.sort(keys, String.CASE_INSENSITIVE_ORDER); String[][] data = new String[keys.length][3]; PropertyResourceBundle localeBundle = null; try { String programDir = System.getProperty("gcaldaemon.program.dir", "/Progra~1/GCALDaemon"); File langDir = new File(programDir, "lang"); if (!langDir.isDirectory()) { langDir.mkdir(); } else { File msgFile = new File(langDir, "messages-" + locale.getLanguage().toLowerCase() + ".txt"); if (msgFile.isFile()) { InputStream in = new BufferedInputStream(new FileInputStream(msgFile)); localeBundle = new PropertyResourceBundle(in); in.close(); } } } catch (Exception ignored) { log.warn("Unable to load messages!", ignored); } for (int i = 0; i < keys.length; i++) { data[i][0] = keys[i]; data[i][1] = DEFAULT_RESOURCE_BUNDLE.getString(keys[i]); if (localeBundle != null) { try { data[i][2] = localeBundle.getString(keys[i]); } catch (Exception ignored) { } } if (data[i][2] == null) { data[i][2] = data[i][1]; } } return data; }
From source file:org.accada.reader.hal.impl.sim.multi.GraphicSimulatorServer.java
/** * implements the initialize method of the SimulatorServerEngine * //from ww w . j ava2 s . com * @param controller * @throws SimulatorServerException */ public void initialize(SimulatorServerController controller) throws SimulatorServerException { this.controller = controller; // load gui text String guiTextFileName = "/props/GUIText_" + LOCALE.getLanguage() + ".properties"; try { guiText = new PropertyResourceBundle(this.getClass().getResourceAsStream(guiTextFileName)); } catch (IOException e) { throw new SimulatorServerException("Could not load gui text file."); } // load properties try { props = new Properties(); props.load(this.getClass().getResourceAsStream(PROPERTIES_FILE_LOCATION)); } catch (IOException e) { throw new SimulatorServerException("Could not load properties from properties file."); } // initialize GUI initializeGUI(); LOG.info("GraphicSimulatorServer started"); }
From source file:org.fao.gast.gui.GuiBuilder.java
public ResourceBundle locateResourceBundleFile(String baseURL, String[] args, int toUse) throws IOException { StringBuilder builder = new StringBuilder(baseURL); for (int i = 0; i < toUse; i++) { if (args[i] != null) { builder.append('_'); builder.append(args[i]);/*from w w w.j a va 2 s .c o m*/ } } builder.append(".properties"); try { final InputStream inputStream = new URL(builder.toString()).openStream(); return new PropertyResourceBundle(inputStream); } catch (IOException e) { return null; } }
From source file:org.jahia.utils.maven.plugin.resources.JavaScriptDictionaryMojo.java
protected static ResourceBundle lookupBundle(File src, String resourceBundle, String... locales) throws IOException { ResourceBundle rb = null;// www .j a v a 2 s .co m for (String locale : locales) { File f = new File(src, resourceBundle + "_" + locale + ".properties"); if (f.exists()) { InputStream is = null; try { is = FileUtils.openInputStream(f); rb = new PropertyResourceBundle(is); break; } finally { IOUtils.closeQuietly(is); } } } return rb; }
From source file:org.pentaho.platform.plugin.services.importer.LocaleImportHandler.java
/** * return locale specific properties from resource bundle * * @param locale/*from w ww . j a v a 2 s . c o m*/ * @return */ private Properties buildLocaleProperties(RepositoryFileImportBundle locale, Properties localePropertiesFromIndex) { Properties localeProperties = new Properties(); PropertyResourceBundle rb = null; String comment = locale.getComment(); String fileTitle = locale.getName(); if (!localePropertiesFromIndex.isEmpty()) { // for old style index.xml as locale comment = localePropertiesFromIndex.getProperty(DESC_PROPERTY_NAME); fileTitle = localePropertiesFromIndex.getProperty(TITLE_PROPERTY_NAME); } else { try { byte[] bytes = IOUtils.toByteArray(locale.getInputStream()); java.io.InputStream bundleInputStream = new ByteArrayInputStream(bytes); rb = new PropertyResourceBundle(bundleInputStream); } catch (Exception returnEmptyIfError) { getLogger().error(returnEmptyIfError.getMessage()); return localeProperties; } if (rb != null) { // this is the 4.8 style - name and description // First try file desc. If no file desc, try for a directory desc, else try fallback comment = rb.containsKey(DESC_PROPERTY_NAME) ? rb.getString(DESC_PROPERTY_NAME) : rb.containsKey(FILE_DESCRIPTION) ? rb.getString(FILE_DESCRIPTION) : rb.containsKey(DIRECTORY_DESCRIPTION) ? rb.getString(DIRECTORY_DESCRIPTION) : comment; // First try name. If no name, try title. If no title, try for a directory name, else use filename. fileTitle = rb.containsKey(TITLE_PROPERTY_NAME) ? rb.getString(TITLE_PROPERTY_NAME) : rb.containsKey("title") ? rb.getString("title") : rb.containsKey(FILE_TITLE) ? rb.getString(FILE_TITLE) : rb.containsKey(DIRECTORY_NAME) ? rb.getString(DIRECTORY_NAME) : fileTitle; } } // this is the new .locale Jcr property names localeProperties.setProperty(FILE_DESCRIPTION, comment != null ? comment : StringUtils.EMPTY); localeProperties.setProperty(FILE_TITLE, fileTitle != null ? fileTitle : StringUtils.EMPTY); return localeProperties; }
From source file:org.eclipse.jubula.tools.i18n.CompSystemI18n.java
/** * Creates a ResourceBundle from the given String.<br> * The given String must have the specification of a properties-file:<br> * key=value<br>/*from ww w . jav a 2s . c o m*/ * key=value<br> * ...<br> * with a line break (\n) after every value. * @param string a String from bundleToString */ public static void fromString(String string) { final ByteArrayInputStream stream = new ByteArrayInputStream(string.getBytes()); try { final PropertyResourceBundle bundle = new PropertyResourceBundle(stream); PLUGIN_BUNDLES.clear(); addResourceBundle(bundle); } catch (IOException e) { log.error(e.getLocalizedMessage(), e); } }
From source file:org.pentaho.platform.plugin.services.importer.LocaleFilesProcessor.java
public Properties loadProperties(InputStream inputStream) throws IOException { assert inputStream != null; final Properties properties = new Properties(); final PropertyResourceBundle rb = new PropertyResourceBundle(inputStream); final Enumeration<?> keyEnum = rb.getKeys(); while (keyEnum.hasMoreElements()) { final Object key = keyEnum.nextElement(); assert key != null; final String sKey = String.valueOf(key); properties.put(sKey, rb.getObject(sKey)); }/*ww w.j a va2s. com*/ return properties; }
From source file:org.accada.reader.hal.impl.sim.GraphicSimulator.java
/** * implements the initialize method of the SimulatorEngine * //from w ww .j a v a 2s . com * @param controller * @param file is only required for BatchSimulator * @throws IOException */ public void initialize(SimulatorController controller) throws IOException { this.controller = controller; mgmtSimDialogs = new Hashtable<String, MgmtSimDialog>(); // load propterties props = new Properties(); props.load(this.getClass().getResourceAsStream(PROPERTIES_FILE_LOCATION)); // load text InputStream languageStream = null; // try to get language form property file if (props.containsKey("Language")) { languageStream = this.getClass() .getResourceAsStream("/props/GUIText_" + props.getProperty("Language") + ".properties"); } // try system default language if (languageStream == null) { languageStream = this.getClass() .getResourceAsStream("/props/GUIText_" + SYSTEM_DEFAULT_LOCALE.getLanguage() + ".properties"); } // try default language if (languageStream == null) { languageStream = this.getClass() .getResourceAsStream("/props/GUIText_" + DEFAULT_LOCALE.getLanguage() + ".properties"); } guiText = new PropertyResourceBundle(languageStream); // initialize GUI initializeGUI(); LOG.info("GraphicSimulator started"); }
From source file:net.sourceforge.pmd.util.database.DBType.java
/** * Load properties from one or more files or resources. * * <p>//from w w w . j a va2 s. co m * This method recursively finds property files or JAR resources matching * {@matchstring}. * </p> * . * <p> * The method is intended to be able to use , so any * * @param matchString * @return "current" set of properties (from one or more resources/property * files) */ private Properties loadDBProperties(String matchString) throws IOException { LOGGER.entering(DBType.class.getCanonicalName(), matchString); // Locale locale = Control.g; ResourceBundle resourceBundle = null; InputStream stream = null; if (LOGGER.isLoggable(Level.FINEST)) { LOGGER.finest("class_path+" + System.getProperty("java.class.path")); } /* * Attempt to match properties files in this order:- File path with * properties suffix File path without properties suffix Resource * without class prefix Resource with class prefix */ try { File propertiesFile = new File(matchString); if (LOGGER.isLoggable(Level.FINEST)) { LOGGER.finest("Attempting File no file suffix: " + matchString); } stream = new FileInputStream(propertiesFile); resourceBundle = new PropertyResourceBundle(stream); propertiesSource = propertiesFile.getAbsolutePath(); LOGGER.finest("FileSystemWithoutExtension"); } catch (FileNotFoundException notFoundOnFilesystemWithoutExtension) { if (LOGGER.isLoggable(Level.FINEST)) { LOGGER.finest("notFoundOnFilesystemWithoutExtension"); LOGGER.finest("Attempting File with added file suffix: " + matchString + ".properties"); } try { File propertiesFile = new File(matchString + ".properties"); stream = new FileInputStream(propertiesFile); resourceBundle = new PropertyResourceBundle(stream); propertiesSource = propertiesFile.getAbsolutePath(); LOGGER.finest("FileSystemWithExtension"); } catch (FileNotFoundException notFoundOnFilesystemWithExtensionTackedOn) { if (LOGGER.isLoggable(Level.FINEST)) { LOGGER.finest("Attempting JARWithoutClassPrefix: " + matchString); } try { resourceBundle = ResourceBundle.getBundle(matchString); propertiesSource = "[" + INTERNAL_SETTINGS + "]" + File.separator + matchString + ".properties"; LOGGER.finest("InJarWithoutPath"); } catch (Exception notInJarWithoutPath) { if (LOGGER.isLoggable(Level.FINEST)) { LOGGER.finest("Attempting JARWithClass prefix: " + DBType.class.getCanonicalName() + "." + matchString); } try { resourceBundle = ResourceBundle .getBundle(DBType.class.getPackage().getName() + "." + matchString); propertiesSource = "[" + INTERNAL_SETTINGS + "]" + File.separator + matchString + ".properties"; LOGGER.finest("found InJarWithPath"); } catch (Exception notInJarWithPath) { notInJarWithPath.printStackTrace(); notFoundOnFilesystemWithExtensionTackedOn.printStackTrace(); throw new RuntimeException(" Could not locate DBTYpe settings : " + matchString, notInJarWithPath); } } } } finally { IOUtils.closeQuietly(stream); } // Properties in this matched resource Properties matchedProperties = getResourceBundleAsProperties(resourceBundle); resourceBundle = null; String saveLoadedFrom = getPropertiesSource(); /* * If the matched properties contain the "extends" key, use the value as * a matchstring, to recursively set the properties before overwriting * any previous properties with the matched properties. */ String extendedPropertyFile = (String) matchedProperties.remove("extends"); if (null != extendedPropertyFile && !"".equals(extendedPropertyFile.trim())) { Properties extendedProperties = loadDBProperties(extendedPropertyFile.trim()); // Overwrite extended properties with properties in the matched // resource extendedProperties.putAll(matchedProperties); matchedProperties = extendedProperties; } /* * Record the location of the original matched resource/property file, * and the current set of properties secured. */ propertiesSource = saveLoadedFrom; setProperties(matchedProperties); return matchedProperties; }
From source file:hk.idv.kenson.jrconsole.Console.java
/** * Loading the resource bundle from file-system or classpath. * <div>Loading resource-bundle from class: classpath:/org/apache/resourceBundle</div> * <div>Loading resource-bundle file file-system: /path/to/resourceBundle.properties</div> * @param path/* w ww.j ava2 s.c o m*/ * @param locale * @return * @throws IOException */ private static ResourceBundle getBundle(String path, Locale locale) throws IOException { if (path == null) throw new NullPointerException("Cannot loading the resource-bundle from empty path"); if (path.toLowerCase().startsWith("classpath:")) return ResourceBundle.getBundle(path.substring(10), locale); else return new PropertyResourceBundle(new FileInputStream(path)); }