use of java.util.MissingResourceException in project zm-mailbox by Zimbra.
the class L10nUtil method getBundleKeySet.
/**
* Gets the list of keys for a given bundle for a given locale
* @param basename The name of the bundle (ex ZMsgs)
* @param lc The locale, null will use the default system locale
* @return A set of keys if any found, will not return null
*/
public static Set<String> getBundleKeySet(String basename, Locale lc) {
ResourceBundle rb;
try {
if (lc == null) {
lc = Locale.getDefault();
}
rb = ResourceBundle.getBundle(basename, lc, sMsgClassLoader);
Set<String> result = new HashSet<String>();
Enumeration<String> keysEnum = rb.getKeys();
while (keysEnum.hasMoreElements()) {
result.add(keysEnum.nextElement());
}
return result;
} catch (MissingResourceException e) {
// just return an empty set if we can't find the bundle
return Collections.emptySet();
}
}
use of java.util.MissingResourceException in project zm-mailbox by Zimbra.
the class L10nUtil method getMessage.
public static String getMessage(String basename, String key, Locale lc, Object... args) {
ResourceBundle rb;
try {
if (lc == null) {
lc = Locale.getDefault();
}
rb = ResourceBundle.getBundle(basename, lc, sMsgClassLoader);
String fmt = rb.getString(key);
if (fmt != null && args != null && args.length > 0) {
return MessageFormat.format(fmt, args);
} else {
return fmt;
}
} catch (MissingResourceException e) {
ZimbraLog.misc.warn("no resource bundle for base name " + basename + " can be found, " + "(locale=" + key + ")", e);
return null;
}
}
use of java.util.MissingResourceException in project voltdb by VoltDB.
the class RefCapablePropertyResourceBundle method getRef.
/**
* Return a ref to a new or existing RefCapablePropertyResourceBundle,
* or throw a MissingResourceException.
*/
private static RefCapablePropertyResourceBundle getRef(String baseName, ResourceBundle rb, ClassLoader loader) {
if (!(rb instanceof PropertyResourceBundle))
throw new MissingResourceException("Found a Resource Bundle, but it is a " + rb.getClass().getName(), PropertyResourceBundle.class.getName(), null);
if (allBundles.containsKey(rb))
return (RefCapablePropertyResourceBundle) allBundles.get(rb);
RefCapablePropertyResourceBundle newPRAFP = new RefCapablePropertyResourceBundle(baseName, (PropertyResourceBundle) rb, loader);
allBundles.put(rb, newPRAFP);
return newPRAFP;
}
use of java.util.MissingResourceException in project OpenAM by OpenRock.
the class AMResourceBundleCache method getResBundle.
/**
* Gets resource bundle from cache
*
* @param name of bundle
* @param locale of bundle
* @return resource bundle
*/
public ResourceBundle getResBundle(String name, Locale locale) {
ResourceBundle resBundle = null;
Map map = (Map) mapBundles.get(name);
if (map != null) {
resBundle = (ResourceBundle) map.get(locale);
}
if (resBundle == null) {
try {
resBundle = ResourceBundle.getBundle(name, locale);
} catch (MissingResourceException mre) {
resBundle = getResourceFromDS(name, locale);
}
synchronized (mapBundles) {
if (map == null) {
map = new HashMap(5);
mapBundles.put(name, map);
}
map.put(locale, resBundle);
}
}
return resBundle;
}
use of java.util.MissingResourceException in project android_frameworks_base by DirtyUnicorns.
the class TextToSpeechService method onLoadVoice.
/**
* Notifies the engine that it should load a speech synthesis voice. There is no guarantee
* that this method is always called before the voice is used for synthesis. It is merely
* a hint to the engine that it will probably get some synthesis requests for this voice
* at some point in the future.
*
* Will be called only on synthesis thread.
*
* The default implementation creates a Locale from the voice name (by interpreting the name as
* a BCP-47 tag for the locale), and passes it to
* {@link #onLoadLanguage(String, String, String)}.
*
* @param voiceName Name of the voice.
* @return {@link TextToSpeech#ERROR} or {@link TextToSpeech#SUCCESS}.
*/
public int onLoadVoice(String voiceName) {
Locale locale = Locale.forLanguageTag(voiceName);
if (locale == null) {
return TextToSpeech.ERROR;
}
int expectedStatus = getExpectedLanguageAvailableStatus(locale);
try {
int localeStatus = onIsLanguageAvailable(locale.getISO3Language(), locale.getISO3Country(), locale.getVariant());
if (localeStatus != expectedStatus) {
return TextToSpeech.ERROR;
}
onLoadLanguage(locale.getISO3Language(), locale.getISO3Country(), locale.getVariant());
return TextToSpeech.SUCCESS;
} catch (MissingResourceException e) {
return TextToSpeech.ERROR;
}
}
Aggregations