Search in sources :

Example 46 with MissingResourceException

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;
}
Also used : Locale(java.util.Locale) MissingResourceException(java.util.MissingResourceException) ArrayList(java.util.ArrayList)

Example 47 with MissingResourceException

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;
}
Also used : MissingResourceException(java.util.MissingResourceException) ResourceBundle(java.util.ResourceBundle)

Example 48 with MissingResourceException

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;
}
Also used : MissingResourceException(java.util.MissingResourceException) ResourceBundle(java.util.ResourceBundle)

Example 49 with MissingResourceException

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;
}
Also used : MissingResourceException(java.util.MissingResourceException) ResourceBundle(java.util.ResourceBundle)

Example 50 with MissingResourceException

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;
}
Also used : MissingResourceException(java.util.MissingResourceException) ResourceBundle(java.util.ResourceBundle)

Aggregations

MissingResourceException (java.util.MissingResourceException)163 ResourceBundle (java.util.ResourceBundle)85 Locale (java.util.Locale)67 ArrayList (java.util.ArrayList)13 IOException (java.io.IOException)10 MessageFormat (java.text.MessageFormat)8 HashMap (java.util.HashMap)8 Map (java.util.Map)8 File (java.io.File)7 PropertyResourceBundle (java.util.PropertyResourceBundle)7 SMSException (com.sun.identity.sm.SMSException)6 Secure.getString (android.provider.Settings.Secure.getString)5 SSOException (com.iplanet.sso.SSOException)5 Iterator (java.util.Iterator)5 Set (java.util.Set)5 InputStream (java.io.InputStream)4 HashSet (java.util.HashSet)4 ISResourceBundle (com.sun.identity.common.ISResourceBundle)3 SimpleDateFormat (java.text.SimpleDateFormat)3 Enumeration (java.util.Enumeration)3