Search in sources :

Example 66 with MissingResourceException

use of java.util.MissingResourceException in project jdk8u_jdk by JetBrains.

the class AccessibleBundle method loadResourceBundle.

/*
     * Loads the Accessibility resource bundle if necessary.
     */
private void loadResourceBundle(String resourceBundleName, Locale locale) {
    if (!table.contains(locale)) {
        try {
            Hashtable resourceTable = new Hashtable();
            ResourceBundle bundle = ResourceBundle.getBundle(resourceBundleName, locale);
            Enumeration iter = bundle.getKeys();
            while (iter.hasMoreElements()) {
                String key = (String) iter.nextElement();
                resourceTable.put(key, bundle.getObject(key));
            }
            table.put(locale, resourceTable);
        } catch (MissingResourceException e) {
            System.err.println("loadResourceBundle: " + e);
            // non-localized key.
            return;
        }
    }
}
Also used : Enumeration(java.util.Enumeration) Hashtable(java.util.Hashtable) MissingResourceException(java.util.MissingResourceException) ResourceBundle(java.util.ResourceBundle)

Example 67 with MissingResourceException

use of java.util.MissingResourceException in project jdk8u_jdk by JetBrains.

the class IIOMetadataFormatImpl method getResource.

private String getResource(String key, Locale locale) {
    if (locale == null) {
        locale = Locale.getDefault();
    }
    /**
         * If an applet supplies an implementation of IIOMetadataFormat and
         * resource bundles, then the resource bundle will need to be
         * accessed via the applet class loader. So first try the context
         * class loader to locate the resource bundle.
         * If that throws MissingResourceException, then try the
         * system class loader.
         */
    ClassLoader loader = (ClassLoader) java.security.AccessController.doPrivileged(new java.security.PrivilegedAction() {

        public Object run() {
            return Thread.currentThread().getContextClassLoader();
        }
    });
    ResourceBundle bundle = null;
    try {
        bundle = ResourceBundle.getBundle(resourceBaseName, locale, loader);
    } catch (MissingResourceException mre) {
        try {
            bundle = ResourceBundle.getBundle(resourceBaseName, locale);
        } catch (MissingResourceException mre1) {
            return null;
        }
    }
    try {
        return bundle.getString(key);
    } catch (MissingResourceException e) {
        return null;
    }
}
Also used : MissingResourceException(java.util.MissingResourceException) ResourceBundle(java.util.ResourceBundle)

Example 68 with MissingResourceException

use of java.util.MissingResourceException in project android_frameworks_base by crdroidandroid.

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 69 with MissingResourceException

use of java.util.MissingResourceException in project android_frameworks_base by crdroidandroid.

the class TextToSpeechService method onIsValidVoiceName.

/**
     * Checks whether the engine supports a voice with a given name.
     *
     * Can be called on multiple threads.
     *
     * The default implementation treats the voice name as a language tag, creating a Locale from
     * the voice name, and passes it to {@link #onIsLanguageAvailable(String, String, String)}.
     *
     * @param voiceName Name of the voice.
     * @return {@link TextToSpeech#ERROR} or {@link TextToSpeech#SUCCESS}.
     */
public int onIsValidVoiceName(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;
        }
        return TextToSpeech.SUCCESS;
    } catch (MissingResourceException e) {
        return TextToSpeech.ERROR;
    }
}
Also used : Locale(java.util.Locale) MissingResourceException(java.util.MissingResourceException)

Example 70 with MissingResourceException

use of java.util.MissingResourceException in project android_frameworks_base by crdroidandroid.

the class TtsEngines method parseLocaleString.

/**
     * Parses a locale encoded as a string, and tries its best to return a valid {@link Locale}
     * object, even if the input string is encoded using the old-style 3 character format e.g.
     * "deu-deu". At the end, we test if the resulting locale can return ISO3 language and
     * country codes ({@link Locale#getISO3Language()} and {@link Locale#getISO3Country()}),
     * if it fails to do so, we return null.
     */
public Locale parseLocaleString(String localeString) {
    String language = "", country = "", variant = "";
    if (!TextUtils.isEmpty(localeString)) {
        String[] split = localeString.split("[" + LOCALE_DELIMITER_OLD + LOCALE_DELIMITER_NEW + "]");
        language = split[0].toLowerCase();
        if (split.length == 0) {
            Log.w(TAG, "Failed to convert " + localeString + " to a valid Locale object. Only" + " separators");
            return null;
        }
        if (split.length > 3) {
            Log.w(TAG, "Failed to convert " + localeString + " to a valid Locale object. Too" + " many separators");
            return null;
        }
        if (split.length >= 2) {
            country = split[1].toUpperCase();
        }
        if (split.length >= 3) {
            variant = split[2];
        }
    }
    String normalizedLanguage = sNormalizeLanguage.get(language);
    if (normalizedLanguage != null) {
        language = normalizedLanguage;
    }
    String normalizedCountry = sNormalizeCountry.get(country);
    if (normalizedCountry != null) {
        country = normalizedCountry;
    }
    if (DBG)
        Log.d(TAG, "parseLocalePref(" + language + "," + country + "," + variant + ")");
    Locale result = new Locale(language, country, variant);
    try {
        result.getISO3Language();
        result.getISO3Country();
        return result;
    } catch (MissingResourceException e) {
        Log.w(TAG, "Failed to convert " + localeString + " to a valid Locale object.");
        return null;
    }
}
Also used : Locale(java.util.Locale) MissingResourceException(java.util.MissingResourceException) Secure.getString(android.provider.Settings.Secure.getString)

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