List of usage examples for java.util ResourceBundle getString
public final String getString(String key)
From source file:Main.java
public static Properties convertResourceBundleToProperties(ResourceBundle resource) { Properties properties = new Properties(); Enumeration<String> keys = resource.getKeys(); while (keys.hasMoreElements()) { String key = keys.nextElement(); properties.put(key, resource.getString(key)); //System.out.println("key: '" + key + "' value: '" + properties.get(key) + "'"); }/* ww w .ja va 2 s .co m*/ return properties; }
From source file:gov.nih.nci.firebird.common.ValidationFailure.java
/** * Creates a new failure instance (non-field level). * * @param resources contains the failure messages * @param messageKey the key to the specific failure * @param arguments parameter values to be inserted into the failure message * @return the failure// w ww . j av a 2 s . co m */ public static ValidationFailure create(ResourceBundle resources, String messageKey, Object... arguments) { MessageFormat format = new MessageFormat(resources.getString(messageKey)); String message = format.format(arguments, new StringBuffer(), new FieldPosition(0)).toString(); return new ValidationFailure(message); }
From source file:PropertyLoader.java
public static Properties loadProperties(String name, ClassLoader loader) throws Exception { if (name.startsWith("/")) name = name.substring(1);/*from w w w . j a va 2s .co m*/ if (name.endsWith(SUFFIX)) name = name.substring(0, name.length() - SUFFIX.length()); Properties result = new Properties(); InputStream in = null; if (loader == null) loader = ClassLoader.getSystemClassLoader(); if (LOAD_AS_RESOURCE_BUNDLE) { name = name.replace('/', '.'); ResourceBundle rb = ResourceBundle.getBundle(name, Locale.getDefault(), loader); for (Enumeration keys = rb.getKeys(); keys.hasMoreElements();) { result.put((String) keys.nextElement(), rb.getString((String) keys.nextElement())); } } else { name = name.replace('.', '/'); if (!name.endsWith(SUFFIX)) name = name.concat(SUFFIX); in = loader.getResourceAsStream(name); if (in != null) { result = new Properties(); result.load(in); // can throw IOException } } in.close(); return result; }
From source file:com.icesoft.faces.utils.MessageUtils.java
private static void loadMessageInfo(String bundleName, Locale locale, String messageId, String[] messageInfo) { ResourceBundle bundle = ResourceBundle.getBundle(bundleName, locale, getClassLoader(bundleName)); try {//from ww w . j a v a2 s .c o m messageInfo[SUMMARY] = bundle.getString(messageId); messageInfo[DETAIL] = bundle.getString(messageId + DETAIL_SUFFIX); } catch (MissingResourceException e) { } }
From source file:it.doqui.index.ecmengine.client.engine.EcmEngineDelegateFactory.java
/** * Metodo factory che crea una nuova istanza del client delegate. * //from w w w. ja va 2 s . co m * <p>La factory cerca di istanziare la classe di implementazione * specificata dall'utente nel file di proprietà * {@code ecmengine-engine-delegate.properties}. Se tale operazione fallisce * la factory cerca di istanziare la classe di default definita * in {@link it.doqui.index.ecmengine.client.engine.util.EcmEngineDelegateConstants#ECMENGINE_DELEGATE_CLASS_NAME_DEFAULT}. * </p> * * @return Una nuova istanza del client delegate. * * @throws EcmEngineDelegateInstantiationException Se si verifica un * errore nell'istanziazione del client delegate. */ public static EcmEngineDelegate getEcmEngineDelegate() throws EcmEngineDelegateInstantiationException { final ResourceBundle resources = ResourceBundle.getBundle(ECMENGINE_PROPERTIES_FILE); final String caller = resources.getString(ECMENGINE_DELEGATE_CALLER); final Log logger = LogFactory.getLog(caller + ECMENGINE_DELEGATE_LOG_CATEGORY); final String implClass = resources.getString(ECMENGINE_DELEGATE_CLASS); EcmEngineDelegate ecmEngineDelegateImpl = null; logger.debug("[EcmEngineDelegateFactory::getEcmEngineDelegate] BEGIN"); logger.debug("[EcmEngineDelegateFactory::getEcmEngineDelegate] " + "Classe delegate: " + implClass); try { ecmEngineDelegateImpl = getClassInstance(implClass, logger); } catch (EcmEngineDelegateInstantiationException e) { logger.warn("[EcmEngineDelegateFactory::getEcmEngineDelegate] " + "Impossibile caricare la classe \"" + implClass + "\": " + e.getMessage()); logger.debug("[EcmEngineDelegateFactory::getEcmEngineDelegate] " + "Classe delegate di default: " + ECMENGINE_DELEGATE_CLASS_NAME_DEFAULT); try { ecmEngineDelegateImpl = getClassInstance(ECMENGINE_DELEGATE_CLASS_NAME_DEFAULT, logger); } catch (EcmEngineDelegateInstantiationException ex) { logger.error("[EcmEngineDelegateFactory::getEcmEngineDelegate] " + "Impossibile caricare la classe di default \"" + ECMENGINE_DELEGATE_CLASS_NAME_DEFAULT + "\": " + ex.getMessage()); throw ex; // Rilancia l'eccezione al chiamante } } finally { logger.debug("[EcmEngineDelegateFactory::getEcmEngineDelegate] END"); } return ecmEngineDelegateImpl; }
From source file:com.projity.util.VersionUtils.java
public static String getVersion() { String version = null;//from w ww. j av a 2 s. c om try { ResourceBundle bundle = ResourceBundle.getBundle("org.ultimania.kanon.version"); if (bundle != null) version = bundle.getString("angelfalls.version"); } catch (Exception e) { log.error("Could not found org.ultimania.kanon.version.properties file."); } return version; }
From source file:com.icesoft.faces.utils.MessageUtils.java
protected static String getResource(String bundleName, Locale locale, String messageId) { ResourceBundle bundle = ResourceBundle.getBundle(bundleName, locale, getClassLoader(bundleName)); String ret = null;// w ww .j a va 2 s . com try { ret = bundle.getString(messageId); } catch (Exception e) { } return ret; }
From source file:it.doqui.index.ecmengine.client.backoffice.EcmEngineBackofficeDelegateFactory.java
/** * Metodo factory che crea una nuova istanza del client delegate. * //from w ww . j a va 2 s.c o m * <p>La factory cerca di istanziare la classe di implementazione * specificata dall'utente nel file di proprietà * {@code ecmengine-backoffice-delegate.properties}. Se tale operazione fallisce * la factory cerca di istanziare la classe di default definita * in {@link EcmEngineBackofficeDelegateConstants#ECMENGINE_BKO_DELEGATE_CLASS_NAME_DEFAULT}. * </p> * * @return Una nuova istanza del client delegate. * * @throws EcmEngineBackofficeDelegateInstantiationException Se si verifica un * errore nell'istanziazione del client delegate. */ public static EcmEngineBackofficeDelegate getEcmEngineBackofficeDelegate() throws EcmEngineBackofficeDelegateInstantiationException { final ResourceBundle resources = ResourceBundle.getBundle(ECMENGINE_BKO_PROPERTIES_FILE); final String caller = resources.getString(ECMENGINE_BKO_DELEGATE_CALLER); final Log logger = LogFactory.getLog(caller + ECMENGINE_BKO_DELEGATE_LOG_CATEGORY); final String implClass = resources.getString(ECMENGINE_BKO_DELEGATE_CLASS); logger.debug("[EcmEngineBackofficeDelegateFactory::getEcmEngineBackofficeDelegate] BEGIN"); EcmEngineBackofficeDelegate backofficeInstance = null; logger.debug("[EcmEngineBackofficeDelegateFactory::getEcmEngineBackofficeDelegate] " + "Classe delegate: " + implClass); try { backofficeInstance = getClassInstance(implClass, logger); } catch (EcmEngineBackofficeDelegateInstantiationException e) { logger.warn("[EcmEngineBackofficeDelegateFactory::getEcmEngineBackofficeDelegate] " + "Impossibile caricare la classe \"" + implClass + "\": " + e.getMessage()); logger.debug("[EcmEngineBackofficeDelegateFactory::getEcmEngineBackofficeDelegate] " + "Classe delegate di default: " + ECMENGINE_BKO_DELEGATE_CLASS_NAME_DEFAULT); try { backofficeInstance = getClassInstance(ECMENGINE_BKO_DELEGATE_CLASS_NAME_DEFAULT, logger); } catch (EcmEngineBackofficeDelegateInstantiationException ex) { logger.error("[EcmEngineBackofficeDelegateFactory::getEcmEngineBackofficeDelegate] " + "Impossibile caricare la classe di default \"" + ECMENGINE_BKO_DELEGATE_CLASS_NAME_DEFAULT + "\": " + ex.getMessage()); throw ex; // Rilancia l'eccezione al chiamante } } finally { logger.debug("[EcmEngineBackofficeDelegateFactory::getEcmEngineBackofficeDelegate] END"); } return backofficeInstance; }
From source file:PropertiesDemo.java
static void iterateKeys(Locale currentLocale) { ResourceBundle labels = ResourceBundle.getBundle("LabelsBundle", currentLocale); Enumeration bundleKeys = labels.getKeys(); while (bundleKeys.hasMoreElements()) { String key = (String) bundleKeys.nextElement(); String value = labels.getString(key); System.out.println("key = " + key + ", " + "value = " + value); }/*from www . j a v a 2 s . c o m*/ }
From source file:com.htmlhifive.tools.codeassist.core.messages.MessagesBase.java
/** * ????????.//ww w . j ava 2 s.co m * * @param key ? * @return ???? */ private static String getResourceBundleString(String key) { synchronized (RESOURCE_BUNDLES) { for (ResourceBundle resourceBundle : RESOURCE_BUNDLES) { if (resourceBundle.containsKey(key)) { return resourceBundle.getString(key); } } return null; } }