List of usage examples for java.util ResourceBundle getString
public final String getString(String key)
From source file:com.gisgraphy.util.ConvertUtil.java
/** * Method to convert a ResourceBundle to a Properties object. * /*from ww w.j a v a 2 s. c o 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:com.stratelia.silverpeas.silvertrace.MsgTrace.java
/** * Reads a boolean property and return it's boolean value * @param resource the Resource object/*from w w w . j a va 2s .c o m*/ * @param propertyName the name of the property to test * @param defaultValue the default value to set to the property if it doesn't exist * @return true/false * @see */ static public boolean getBooleanProperty(ResourceBundle resource, String propertyName, boolean defaultValue) { boolean valret = defaultValue; String value = resource.getString(propertyName); if (value != null) { valret = StringUtil.getBooleanValue(value); } return valret; }
From source file:ChoiceFormatDemo.java
static void displayMessages(Locale currentLocale) { System.out.println("currentLocale = " + currentLocale.toString()); System.out.println();//from w ww . j a v a 2 s. com ResourceBundle bundle = ResourceBundle.getBundle("ChoiceBundle", currentLocale); MessageFormat messageForm = new MessageFormat(""); messageForm.setLocale(currentLocale); double[] fileLimits = { 0, 1, 2 }; String[] fileStrings = { bundle.getString("noFiles"), bundle.getString("oneFile"), bundle.getString("multipleFiles") }; ChoiceFormat choiceForm = new ChoiceFormat(fileLimits, fileStrings); String pattern = bundle.getString("pattern"); Format[] formats = { choiceForm, null, NumberFormat.getInstance() }; messageForm.applyPattern(pattern); messageForm.setFormats(formats); Object[] messageArguments = { null, "XDisk", null }; for (int numFiles = 0; numFiles < 4; numFiles++) { messageArguments[0] = new Integer(numFiles); messageArguments[2] = new Integer(numFiles); String result = messageForm.format(messageArguments); System.out.println(result); } }
From source file:fr.mael.microrss.util.Tools.java
/** * Convert ResourceBundle into a Map object. * * @param resource a resource bundle to convert. * @return Map a map version of the resource bundle. * @throws UnsupportedEncodingException *//*from w w w . ja va 2 s . com*/ public static Map<String, String> convertResourceBundleToMap(ResourceBundle resource) throws UnsupportedEncodingException { Map<String, String> map = new HashMap<String, String>(); for (String key : resource.keySet()) { map.put(key, resource.getString(key)); } return map; }
From source file:com.beginner.core.utils.PropertyUtil.java
/** * java.util.ResourceBundle?classpathproperties??TestResourcesUtil * @param key key/*from www . ja v a 2s .c o m*/ * @param fileName +????.properties?? * @return String keyvalue */ public static String getProperty(String key, String fileName) { if (StringUtils.isBlank(key)) throw new IllegalArgumentException("The key cannot be null and cannot be empty."); if (StringUtils.isBlank(fileName)) throw new IllegalArgumentException("The fileName cannot be null and cannot be empty."); Locale locale = Locale.getDefault(); ResourceBundle resource = ResourceBundle.getBundle(fileName, locale); String value = StringUtils.EMPTY; try { value = resource.getString(key); } catch (Exception e) { return value; } return value; }
From source file:net.refractions.udig.ui.internal.Messages.java
/** * Find the localized message for the given key. If arguments are given, then the * result message is formatted via {@link MessageFormat}. * * @param locale The locale to use to localize the given message. * @param key/*w w w. ja v a2s . c o m*/ * @param args If not null, then the message is formatted via {@link MessageFormat} * @return The message for the given key. */ public static String get(Locale locale, String key, Object... args) { try { // getBundle() caches the bundles ResourceBundle bundle = ResourceBundle.getBundle(BUNDLE_NAME, locale, Messages.class.getClassLoader()); if (args == null || args.length == 0) { return bundle.getString(key); } else { String msg = bundle.getString(key); return MessageFormat.format(msg, args); } } catch (Exception e) { return StringUtils.substringAfterLast(key, "_"); } }
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 a 2 s . c o m * <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:SimpleMenu.java
/** The convenience method that creates menu panes */ public static JMenu create(ResourceBundle bundle, String menuname, String[] itemnames, ActionListener listener) { // Get the menu title from the bundle. Use name as default label. String menulabel;/*from www .ja v a2 s. c o m*/ try { menulabel = bundle.getString(menuname + ".label"); } catch (MissingResourceException e) { menulabel = menuname; } // Create the menu pane. JMenu menu = new JMenu(menulabel); // For each named item in the menu. for (int i = 0; i < itemnames.length; i++) { // Look up the label for the item, using name as default. String itemlabel; try { itemlabel = bundle.getString(menuname + "." + itemnames[i] + ".label"); } catch (MissingResourceException e) { itemlabel = itemnames[i]; } JMenuItem item = new JMenuItem(itemlabel); // Look up an accelerator for the menu item try { String acceleratorText = bundle.getString(menuname + "." + itemnames[i] + ".accelerator"); item.setAccelerator(KeyStroke.getKeyStroke(acceleratorText)); } catch (MissingResourceException e) { } // Register an action listener and command for the item. if (listener != null) { item.addActionListener(listener); item.setActionCommand(itemnames[i]); } // Add the item to the menu. menu.add(item); } // Return the automatically created localized menu. return menu; }
From source file:be.fedict.eidviewer.lib.X509Utilities.java
public static String getHumanReadableName(X509Certificate certificate) { String commonName = getCN(certificate); ResourceBundle bundle = ResourceBundle.getBundle("be/fedict/eidviewer/lib/resources/X509Utilities"); if (bundle != null) { try {//from www .j av a2s. c o m return bundle.getString(commonName); } catch (MissingResourceException mre) { // intentionally empty ; will return commonName below } } return commonName; }
From source file:Main.java
public static final List<String> getListFromBundle(ResourceBundle rb, String prefix) { String name = null;// ww w.j ava 2s .c o m List<String> ret = new LinkedList<String>(); Enumeration<String> names = rb.getKeys(); while (names.hasMoreElements()) { name = names.nextElement(); if (name != null && name.startsWith(prefix) && isInteger(name.substring(name.length() - 1))) { ret.add(rb.getString(name)); } } Collections.sort(ret); return ret; }