List of usage examples for java.util ResourceBundle getKeys
public abstract Enumeration<String> getKeys();
From source file:com.gisgraphy.util.ConvertUtil.java
/** * Method to convert a ResourceBundle to a Properties object. * //from w w w. j ava2 s . co m * @param rb * a given resource bundle * @return Properties a populated properties object */ public static Properties convertBundleToProperties(ResourceBundle rb) { Properties props = new Properties(); for (Enumeration<String> keys = rb.getKeys(); keys.hasMoreElements();) { String key = keys.nextElement(); props.put(key, rb.getString(key)); } return props; }
From source file:net.big_oh.common.utils.PropertyUtil.java
/** * Construct a new {@link Properties} object from the {@link ResourceBundle} * identified by resourceBundleName. Prior to looking up the ResourceBundle, * the resourceBundleName parameter is processed to conform to the naming * conventions for ResourceBundles: <br/> * <ul>//from w w w. j a v a2s . c om * <li>1) Any terminating ".properties" is stripped off.</li> * <li>2) Period characters ('.') are replaced with forward slash characters * ('/').</li> * </ul> * * @param resourceBundleName * The name of the ResourceBundle from which the new Properties * object will be constructed. * @return A Properties object built from the named REsourceBundle. * @throws MissingResourceException */ public static Properties loadProperties(String resourceBundleName) throws MissingResourceException { logger.info("Requested properties file from resource bundle named " + resourceBundleName + "."); Properties props = new Properties(); if (resourceBundleName != null) { // correct common naming mistakes when getting resource bundles String requestedResourceBundleName = resourceBundleName; resourceBundleName = resourceBundleName.replaceAll("\\.properties$", ""); resourceBundleName = resourceBundleName.replace('/', '.'); if (!resourceBundleName.equals(requestedResourceBundleName)) { logger.info("Translated requested resource bundle name from '" + requestedResourceBundleName + "' to '" + resourceBundleName + "'"); } ResourceBundle rb = ResourceBundle.getBundle(resourceBundleName); for (Enumeration<String> keys = rb.getKeys(); keys.hasMoreElements();) { final String key = (String) keys.nextElement(); final String value = rb.getString(key); props.put(key, value); } } return props; }
From source file:org.musicrecital.util.ConvertUtil.java
/** * Method to convert a ResourceBundle to a Map object. * * @param rb a given resource bundle/*from www. jav a 2 s.co m*/ * @return Map a populated map */ public static Map<String, String> convertBundleToMap(ResourceBundle rb) { Map<String, String> map = new HashMap<String, String>(); Enumeration<String> keys = rb.getKeys(); while (keys.hasMoreElements()) { String key = keys.nextElement(); map.put(key, rb.getString(key)); } return map; }
From source file:org.orcid.utils.OrcidStringUtils.java
public static Map<String, String> resourceBundleToMap(ResourceBundle resource) { Map<String, String> map = new HashMap<String, String>(); Enumeration<String> keys = resource.getKeys(); while (keys.hasMoreElements()) { String key = keys.nextElement(); map.put(key, resource.getString(key)); }// w w w. j a v a 2 s .c o m return map; }
From source file:org.pentaho.metaverse.api.model.BaseSynchronizedGraphFactory.java
/** * Opens Graph based on configuration defined in a {@link ResourceBundle}. * * @param configBundle The {@link ResourceBundle} containing the graph configuration * @return {@link BaseSynchronizedGraph} instance {@link com.tinkerpop.blueprints.KeyIndexableGraph} * @see com.tinkerpop.blueprints.GraphFactory#open(String) *//*from w w w . ja va2 s . c o m*/ public static Graph open(final ResourceBundle configBundle) { final Map<String, String> graphProps = new HashMap<>(); final Enumeration<String> keys = configBundle.getKeys(); while (keys.hasMoreElements()) { final String key = keys.nextElement(); final String value = configBundle.getString(key); graphProps.put(key, value); } return open(graphProps); }
From source file:org.eclipse.jubula.tools.internal.i18n.CompSystemI18n.java
/** * //from w w w .j av a 2s. c o m * @return a String representation of the ResourceBundles to use for * fromString(String string) * @see fromString(String string) */ public static String bundlesToString() { final String keyValueSeparator = "="; //$NON-NLS-1$ final String lineBreak = "\n"; //$NON-NLS-1$ final StringBuffer entries = new StringBuffer(); for (Iterator<ResourceBundle> bundlesIt = PLUGIN_BUNDLES.iterator(); bundlesIt.hasNext();) { final ResourceBundle bundle = bundlesIt.next(); for (Enumeration keys = bundle.getKeys(); keys.hasMoreElements();) { final String key = String.valueOf(keys.nextElement()); final String value = bundle.getString(key); entries.append(key).append(keyValueSeparator).append(value).append(lineBreak); } } return entries.toString(); }
From source file:org.jiemamy.utils.ResourceBundleUtil.java
/** * {@link ResourceBundle}{@link Map}???// ww w . j av a2s .c o m * * @param bundle ? * @return {@link Map} * @throws IllegalArgumentException ?{@code null}??? */ public static Map<String, String> convertMap(ResourceBundle bundle) { Validate.notNull(bundle); Map<String, String> ret = new HashMap<String, String>(); for (Enumeration<String> e = bundle.getKeys(); e.hasMoreElements();) { String key = e.nextElement(); String value = bundle.getString(key); ret.put(key, value); } return ret; }
From source file:org.eclipse.jubula.tools.i18n.CompSystemI18n.java
/** * //from w ww. j a va2s .c om * @return a String representation of the ResourceBundles to use for * fromString(String string) * @see fromString(String string) */ public static String bundlesToString() { final String keyValueSeparator = "="; //$NON-NLS-1$ final String lineBreak = "\n"; //$NON-NLS-1$ final StringBuffer entries = new StringBuffer(); for (Iterator bundlesIt = PLUGIN_BUNDLES.iterator(); bundlesIt.hasNext();) { final ResourceBundle bundle = (ResourceBundle) bundlesIt.next(); for (Enumeration keys = bundle.getKeys(); keys.hasMoreElements();) { final String key = String.valueOf(keys.nextElement()); final String value = bundle.getString(key); entries.append(key).append(keyValueSeparator).append(value).append(lineBreak); } } return entries.toString(); }
From source file:com.krawler.esp.utils.PropsLoader.java
public static Properties loadProperties(String name, ClassLoader loader) { if (name == null) throw new IllegalArgumentException("null input: name"); if (name.startsWith("/")) name = name.substring(1);// w w w . j ava 2s .c o m if (name.endsWith(SUFFIX)) name = name.substring(0, name.length() - SUFFIX.length()); Properties result = null; InputStream in = null; try { if (loader == null) loader = ClassLoader.getSystemClassLoader(); if (LOAD_AS_RESOURCE_BUNDLE) { name = name.replace('/', '.'); // Throws MissingResourceException on lookup failures: final ResourceBundle rb = ResourceBundle.getBundle(name, Locale.getDefault(), loader); result = new Properties(); for (Enumeration keys = rb.getKeys(); keys.hasMoreElements();) { final String key = (String) keys.nextElement(); final String value = rb.getString(key); result.put(key, value); } } else { name = name.replace('.', '/'); if (!name.endsWith(SUFFIX)) name = name.concat(SUFFIX); // Returns null on lookup failures: in = loader.getResourceAsStream(name); if (in != null) { result = new Properties(); result.load(in); // Can throw IOException } } } catch (Exception e) { logger.warn(e.getMessage(), e); result = null; } finally { if (in != null) try { in.close(); } catch (Throwable ignore) { logger.warn(ignore.getMessage(), ignore); } } if (THROW_ON_LOAD_FAILURE && (result == null)) { throw new IllegalArgumentException("could not load [" + name + "]" + " as " + (LOAD_AS_RESOURCE_BUNDLE ? "a resource bundle" : "a classloader resource")); } return result; }
From source file:com.projity.strings.Messages.java
public static Properties getProperties(ResourceBundle bundle) { Properties properties = new Properties(); for (Enumeration keys = bundle.getKeys(); keys.hasMoreElements();) { String key = (String) keys.nextElement(); properties.put(key, bundle.getString(key)); }/*from www.ja va2 s .co m*/ return properties; }