Search in sources :

Example 31 with MissingResourceException

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

Example 32 with MissingResourceException

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

Example 33 with MissingResourceException

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

Example 34 with MissingResourceException

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;
}
Also used : HashMap(java.util.HashMap) MissingResourceException(java.util.MissingResourceException) ISResourceBundle(com.sun.identity.common.ISResourceBundle) ResourceBundle(java.util.ResourceBundle) Map(java.util.Map) HashMap(java.util.HashMap)

Example 35 with MissingResourceException

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

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