Search in sources :

Example 86 with MissingResourceException

use of java.util.MissingResourceException in project languagetool by languagetool-org.

the class ResourceBundleTools method getMessageBundle.

/**
   * Gets the ResourceBundle (i18n strings) for the default language of the user's system.
   */
public static ResourceBundle getMessageBundle() {
    try {
        ResourceBundle bundle = ResourceBundle.getBundle(MESSAGE_BUNDLE);
        ResourceBundle fallbackBundle = ResourceBundle.getBundle(MESSAGE_BUNDLE, Locale.ENGLISH);
        return new ResourceBundleWithFallback(bundle, fallbackBundle);
    } catch (MissingResourceException e) {
        return ResourceBundle.getBundle(MESSAGE_BUNDLE, Locale.ENGLISH);
    }
}
Also used : MissingResourceException(java.util.MissingResourceException) ResourceBundle(java.util.ResourceBundle)

Example 87 with MissingResourceException

use of java.util.MissingResourceException in project Openfire by igniterealtime.

the class LocaleUtils method getLocalizedString.

/**
	 * Returns an internationalized string loaded from a resource bundle from
	 * the passed in plugin, using the passed in Locale.
	 * 
	 * If the plugin name is <tt>null</tt>, the key will be looked up using the
	 * standard resource bundle.
	 * 
	 * If the locale is <tt>null</tt>, the Jive Global locale will be used.
	 * 
	 * @param key
	 *            the key to use for retrieving the string from the appropriate
	 *            resource bundle.
	 * @param pluginName
	 *            the name of the plugin to load the require resource bundle
	 *            from.
	 * @param arguments
	 *            a list of objects to use which are formatted, then inserted
	 *            into the pattern at the appropriate places.
	 * @param locale
	 *            the locale to use for retrieving the appropriate
	 *            locale-specific string.
	 * @param fallback
	 *            if <tt>true</tt>, the global locale used by Openfire will be
	 *            used if the requested locale is not available)
	 * @return the localized string.
	 */
public static String getLocalizedString(String key, String pluginName, List<?> arguments, Locale locale, boolean fallback) {
    if (pluginName == null) {
        return getLocalizedString(key, arguments);
    }
    if (locale == null) {
        locale = JiveGlobals.getLocale();
    }
    String i18nFile = getI18nFile(pluginName);
    // Retrieve classloader from pluginName.
    final XMPPServer xmppServer = XMPPServer.getInstance();
    PluginManager pluginManager = xmppServer.getPluginManager();
    Plugin plugin = pluginManager.getPlugin(pluginName);
    if (plugin == null) {
        throw new NullPointerException("Plugin could not be located: " + pluginName);
    }
    ClassLoader pluginClassLoader = pluginManager.getPluginClassloader(plugin);
    try {
        ResourceBundle bundle = ResourceBundle.getBundle(i18nFile, locale, pluginClassLoader);
        return getLocalizedString(key, locale, arguments, bundle);
    } catch (MissingResourceException mre) {
        Locale jivesLocale = JiveGlobals.getLocale();
        if (fallback && !jivesLocale.equals(locale)) {
            Log.info("Could not find the requested locale. Falling back to default locale.", mre);
            return getLocalizedString(key, pluginName, arguments, jivesLocale, false);
        }
        Log.error(mre.getMessage(), mre);
        return key;
    }
}
Also used : PluginManager(org.jivesoftware.openfire.container.PluginManager) Locale(java.util.Locale) XMPPServer(org.jivesoftware.openfire.XMPPServer) MissingResourceException(java.util.MissingResourceException) ResourceBundle(java.util.ResourceBundle) Plugin(org.jivesoftware.openfire.container.Plugin)

Example 88 with MissingResourceException

use of java.util.MissingResourceException in project checkstyle by checkstyle.

the class LocalizedMessage method getMessage.

/**
     * Gets the translated message.
     * @return the translated message
     */
public String getMessage() {
    String message = getCustomMessage();
    if (message == null) {
        try {
            // Important to use the default class loader, and not the one in
            // the GlobalProperties object. This is because the class loader in
            // the GlobalProperties is specified by the user for resolving
            // custom classes.
            final ResourceBundle resourceBundle = getBundle(bundle);
            final String pattern = resourceBundle.getString(key);
            final MessageFormat formatter = new MessageFormat(pattern, Locale.ROOT);
            message = formatter.format(args);
        } catch (final MissingResourceException ignored) {
            // If the Check author didn't provide i18n resource bundles
            // and logs error messages directly, this will return
            // the author's original message
            final MessageFormat formatter = new MessageFormat(key, Locale.ROOT);
            message = formatter.format(args);
        }
    }
    return message;
}
Also used : MessageFormat(java.text.MessageFormat) MissingResourceException(java.util.MissingResourceException) PropertyResourceBundle(java.util.PropertyResourceBundle) ResourceBundle(java.util.ResourceBundle)

Example 89 with MissingResourceException

use of java.util.MissingResourceException in project Openfire by igniterealtime.

the class DbConnectionManager method setConnectionProvider.

/**
     * Sets the connection provider. The old provider (if it exists) is shut
     * down before the new one is started. A connection provider <b>should
     * not</b> be started before being passed to the connection manager
     * because the manager will call the start() method automatically.
     *
     * @param provider the ConnectionProvider that the manager should obtain
     *                 connections from.
     */
public static void setConnectionProvider(ConnectionProvider provider) {
    synchronized (providerLock) {
        if (connectionProvider != null) {
            connectionProvider.destroy();
            connectionProvider = null;
        }
        connectionProvider = provider;
        connectionProvider.start();
        // Now, get a connection to determine meta data.
        Connection con = null;
        try {
            con = connectionProvider.getConnection();
            setMetaData(con);
            // Check to see if the database schema needs to be upgraded.
            schemaManager.checkOpenfireSchema(con);
        } catch (MissingResourceException mre) {
            Log.error(mre.getMessage());
        } catch (Exception e) {
            Log.error(e.getMessage(), e);
        } finally {
            closeConnection(con);
        }
    }
    // Remember what connection provider we want to use for restarts.
    JiveGlobals.setXMLProperty("connectionProvider.className", provider.getClass().getName());
}
Also used : MissingResourceException(java.util.MissingResourceException) Connection(java.sql.Connection) MissingResourceException(java.util.MissingResourceException) SQLException(java.sql.SQLException)

Example 90 with MissingResourceException

use of java.util.MissingResourceException in project libgdx by libgdx.

the class I18NBundle method createBundleImpl.

private static I18NBundle createBundleImpl(FileHandle baseFileHandle, Locale locale, String encoding) {
    if (baseFileHandle == null || locale == null || encoding == null)
        throw new NullPointerException();
    I18NBundle bundle = null;
    I18NBundle baseBundle = null;
    Locale targetLocale = locale;
    do {
        // Create the candidate locales
        List<Locale> candidateLocales = getCandidateLocales(targetLocale);
        // Load the bundle and its parents recursively
        bundle = loadBundleChain(baseFileHandle, encoding, candidateLocales, 0, baseBundle);
        // Check the loaded bundle (if any)
        if (bundle != null) {
            // WTH? GWT can't access bundle.locale directly
            Locale bundleLocale = bundle.getLocale();
            boolean isBaseBundle = bundleLocale.equals(ROOT_LOCALE);
            if (!isBaseBundle || bundleLocale.equals(locale)) {
                // Found the bundle for the requested locale
                break;
            }
            if (candidateLocales.size() == 1 && bundleLocale.equals(candidateLocales.get(0))) {
                // Found the bundle for the only candidate locale
                break;
            }
            if (isBaseBundle && baseBundle == null) {
                // Store the base bundle and keep on processing the remaining fallback locales
                baseBundle = bundle;
            }
        }
        // Set next fallback locale
        targetLocale = getFallbackLocale(targetLocale);
    } while (targetLocale != null);
    if (bundle == null) {
        if (baseBundle == null) {
            // No bundle found
            throw new MissingResourceException("Can't find bundle for base file handle " + baseFileHandle.path() + ", locale " + locale, baseFileHandle + "_" + locale, "");
        }
        // Set the base bundle to be returned
        bundle = baseBundle;
    }
    return bundle;
}
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