use of java.util.MissingResourceException in project android_frameworks_base by AOSPA.
the class TextToSpeechService method onGetVoices.
/**
* Queries the service for a set of supported voices.
*
* Can be called on multiple threads.
*
* The default implementation tries to enumerate all available locales, pass them to
* {@link #onIsLanguageAvailable(String, String, String)} and create Voice instances (using
* the locale's BCP-47 language tag as the voice name) for the ones that are supported.
* Note, that this implementation is suitable only for engines that don't have multiple voices
* for a single locale. Also, this implementation won't work with Locales not listed in the
* set returned by the {@link Locale#getAvailableLocales()} method.
*
* @return A list of voices supported.
*/
public List<Voice> onGetVoices() {
// Enumerate all locales and check if they are available
ArrayList<Voice> voices = new ArrayList<Voice>();
for (Locale locale : Locale.getAvailableLocales()) {
int expectedStatus = getExpectedLanguageAvailableStatus(locale);
try {
int localeStatus = onIsLanguageAvailable(locale.getISO3Language(), locale.getISO3Country(), locale.getVariant());
if (localeStatus != expectedStatus) {
continue;
}
} catch (MissingResourceException e) {
// Ignore locale without iso 3 codes
continue;
}
Set<String> features = onGetFeaturesForLanguage(locale.getISO3Language(), locale.getISO3Country(), locale.getVariant());
String voiceName = onGetDefaultVoiceNameFor(locale.getISO3Language(), locale.getISO3Country(), locale.getVariant());
voices.add(new Voice(voiceName, locale, Voice.QUALITY_NORMAL, Voice.LATENCY_NORMAL, false, features));
}
return voices;
}
use of java.util.MissingResourceException in project intellij-community by JetBrains.
the class AbstractBundle method getResourceBundle.
public static ResourceBundle getResourceBundle(@NotNull String pathToBundle, @NotNull ClassLoader loader) {
Map<String, ResourceBundle> map = ourCache.get(loader);
ResourceBundle result = map.get(pathToBundle);
if (result == null) {
try {
ResourceBundle.Control control = ResourceBundle.Control.getControl(ResourceBundle.Control.FORMAT_PROPERTIES);
result = ResourceBundle.getBundle(pathToBundle, Locale.getDefault(), loader, control);
} catch (MissingResourceException e) {
LOG.info("Cannot load resource bundle from *.properties file, falling back to slow class loading: " + pathToBundle);
ResourceBundle.clearCache(loader);
result = ResourceBundle.getBundle(pathToBundle, Locale.getDefault(), loader);
}
map.put(pathToBundle, result);
}
return result;
}
use of java.util.MissingResourceException in project intellij-community by JetBrains.
the class JavacResourcesReader method dumpPatterns.
// for debug purposes
/*
public static void printPatterns() {
final ResourceBundle messagesBundle = getMessagesBundle();
if (messagesBundle == null) {
System.out.println("No bundles found");
return;
}
final Enumeration keys = messagesBundle.getKeys();
while (keys.hasMoreElements()) {
final Object key = keys.nextElement();
System.out.println(key + "->" + messagesBundle.getObject((String)key));
}
}
*/
public static boolean dumpPatterns() {
final ResourceBundle messagesBundle = getMessagesBundle();
if (messagesBundle == null) {
return false;
}
System.err.println(MSG_PATTERNS_START);
for (int idx = 0; idx < MSG_NAME_KEY_PAIRS.length; idx++) {
BundleKey bundleKey = MSG_NAME_KEY_PAIRS[idx];
try {
System.err.println(bundleKey.category + CATEGORY_VALUE_DIVIDER + bundleKey.getCategoryValue(messagesBundle));
} catch (MissingResourceException ignored) {
}
}
System.err.println(MSG_PATTERNS_END);
return true;
}
use of java.util.MissingResourceException in project lucene-solr by apache.
the class NLS method getResourceBundleObject.
private static Object getResourceBundleObject(String messageKey, Locale locale) {
// need to loop thru all registered resource bundles
for (Iterator<String> it = bundles.keySet().iterator(); it.hasNext(); ) {
Class<? extends NLS> clazz = bundles.get(it.next());
ResourceBundle resourceBundle = ResourceBundle.getBundle(clazz.getName(), locale);
if (resourceBundle != null) {
try {
Object obj = resourceBundle.getObject(messageKey);
if (obj != null)
return obj;
} catch (MissingResourceException e) {
// just continue it might be on the next resource bundle
}
}
}
// if resource is not found
return null;
}
use of java.util.MissingResourceException in project jmeter by apache.
the class JMeterUtils method getResStringDefault.
/**
* Helper method to do the actual work of fetching resources; allows
* getResString(S,S) to be deprecated without affecting getResString(S);
*/
private static String getResStringDefault(String key, String defaultValue, Locale forcedLocale) {
if (key == null) {
return null;
}
// Resource keys cannot contain spaces, and are forced to lower case
// $NON-NLS-1$ // $NON-NLS-2$
String resKey = key.replace(' ', '_');
resKey = resKey.toLowerCase(java.util.Locale.ENGLISH);
String resString = null;
try {
ResourceBundle bundle = resources;
if (forcedLocale != null || bundle == null) {
bundle = getBundle(forcedLocale);
}
if (bundle.containsKey(resKey)) {
resString = bundle.getString(resKey);
} else {
log.warn("ERROR! Resource string not found: [" + resKey + "]");
resString = defaultValue;
}
if (ignoreResorces) {
// Special mode for debugging resource handling
return "[" + key + "]";
}
} catch (MissingResourceException mre) {
if (ignoreResorces) {
// Special mode for debugging resource handling
return "[?" + key + "?]";
}
log.warn("ERROR! Resource string not found: [" + resKey + "]", mre);
resString = defaultValue;
}
return resString;
}
Aggregations