Search in sources :

Example 6 with MissingResourceException

use of java.util.MissingResourceException in project blueocean-plugin by jenkinsci.

the class BlueI18n method getBundle.

@CheckForNull
private JSONObject getBundle(BundleParams bundleParams, Locale locale) {
    PluginWrapper plugin = bundleParams.getPlugin();
    if (plugin == null) {
        return null;
    }
    try {
        ResourceBundle resourceBundle = ResourceBundle.getBundle(bundleParams.bundleName, locale, plugin.classLoader);
        JSONObject bundleJSON = new JSONObject();
        for (String key : resourceBundle.keySet()) {
            bundleJSON.put(key, resourceBundle.getString(key));
        }
        return bundleJSON;
    } catch (MissingResourceException e) {
    // fall through and return null.
    }
    return null;
}
Also used : JSONObject(net.sf.json.JSONObject) MissingResourceException(java.util.MissingResourceException) PluginWrapper(hudson.PluginWrapper) ResourceBundle(java.util.ResourceBundle) CheckForNull(javax.annotation.CheckForNull)

Example 7 with MissingResourceException

use of java.util.MissingResourceException in project SmartAndroidSource by jaychou2012.

the class Entities method loadEntities.

private static Map<String, Character> loadEntities(String filename) {
    Properties properties = new Properties();
    Map<String, Character> entities = new HashMap<String, Character>();
    try {
        InputStream in = Entities.class.getResourceAsStream(filename);
        properties.load(in);
        in.close();
    } catch (IOException e) {
        throw new MissingResourceException("Error loading entities resource: " + e.getMessage(), "Entities", filename);
    }
    for (Map.Entry entry : properties.entrySet()) {
        Character val = Character.valueOf((char) Integer.parseInt((String) entry.getValue(), 16));
        String name = (String) entry.getKey();
        entities.put(name, val);
    }
    return entities;
}
Also used : HashMap(java.util.HashMap) InputStream(java.io.InputStream) MissingResourceException(java.util.MissingResourceException) IOException(java.io.IOException) Properties(java.util.Properties) Map(java.util.Map) HashMap(java.util.HashMap)

Example 8 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 given user interface language.
   */
static ResourceBundle getMessageBundle(Language lang) {
    try {
        ResourceBundle bundle = ResourceBundle.getBundle(MESSAGE_BUNDLE, lang.getLocaleWithCountryAndVariant());
        if (!isValidBundleFor(lang, bundle)) {
            bundle = ResourceBundle.getBundle(MESSAGE_BUNDLE, lang.getLocale());
            if (!isValidBundleFor(lang, bundle)) {
                // happens if 'xx' is requested but only a MessagesBundle_xx_YY.properties exists:
                Language defaultVariant = lang.getDefaultLanguageVariant();
                if (defaultVariant != null && defaultVariant.getCountries().length > 0) {
                    Locale locale = new Locale(defaultVariant.getShortCode(), defaultVariant.getCountries()[0]);
                    bundle = ResourceBundle.getBundle(MESSAGE_BUNDLE, locale);
                }
            }
        }
        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 : Locale(java.util.Locale) MissingResourceException(java.util.MissingResourceException) ResourceBundle(java.util.ResourceBundle)

Example 9 with MissingResourceException

use of java.util.MissingResourceException in project jodd by oblac.

the class ResourceBundleMessageResolver method findResourceBundle.

/**
	 * Finds resource bundle by it's name. Missed and founded resource bundles are cached for
	 * better performances. Returns <code>null</code> if resource bundle is missing.
	 */
public ResourceBundle findResourceBundle(String bundleName, Locale locale) {
    if (bundleName == null) {
        bundleName = fallbackBundlename;
    }
    if (locale == null) {
        locale = fallbackLocale;
    }
    if (!cacheResourceBundles) {
        try {
            return getBundle(bundleName, locale, ClassLoaderUtil.getDefaultClassLoader());
        } catch (MissingResourceException ignore) {
            return null;
        }
    }
    String key = bundleName + '_' + LocaleUtil.resolveLocaleCode(locale);
    try {
        if (!misses.contains(key)) {
            ResourceBundle bundle = notmisses.get(key);
            if (bundle == null) {
                bundle = getBundle(bundleName, locale, ClassLoaderUtil.getDefaultClassLoader());
                notmisses.put(key, bundle);
            }
            return bundle;
        }
    } catch (MissingResourceException ignore) {
        misses.add(key);
    }
    return null;
}
Also used : MissingResourceException(java.util.MissingResourceException) ResourceBundle(java.util.ResourceBundle)

Example 10 with MissingResourceException

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

the class XSLTErrorResources method loadResourceBundle.

/**
   *   Return a named ResourceBundle for a particular locale.  This method mimics the behavior
   *   of ResourceBundle.getBundle().
   *
   *   @param className the name of the class that implements the resource bundle.
   *   @return the ResourceBundle
   *   @throws MissingResourceException
   */
public static final XSLTErrorResources loadResourceBundle(String className) throws MissingResourceException {
    Locale locale = Locale.getDefault();
    String suffix = getResourceSuffix(locale);
    try {
        // first try with the given locale
        return (XSLTErrorResources) ResourceBundle.getBundle(className + suffix, locale);
    } catch (MissingResourceException e) {
        try // try to fall back to en_US if we can't load
        {
            // fall back to en_US.
            return (XSLTErrorResources) ResourceBundle.getBundle(className, new Locale("en", "US"));
        } catch (MissingResourceException e2) {
            // very bad, definitely very bad...not going to get very far
            throw new MissingResourceException("Could not load any resource bundles.", className, "");
        }
    }
}
Also used : Locale(java.util.Locale) MissingResourceException(java.util.MissingResourceException)

Aggregations

MissingResourceException (java.util.MissingResourceException)151 ResourceBundle (java.util.ResourceBundle)77 Locale (java.util.Locale)66 ArrayList (java.util.ArrayList)10 IOException (java.io.IOException)8 MessageFormat (java.text.MessageFormat)8 File (java.io.File)7 HashMap (java.util.HashMap)7 Map (java.util.Map)7 SMSException (com.sun.identity.sm.SMSException)6 PropertyResourceBundle (java.util.PropertyResourceBundle)6 Secure.getString (android.provider.Settings.Secure.getString)5 SSOException (com.iplanet.sso.SSOException)5 InputStream (java.io.InputStream)4 ISResourceBundle (com.sun.identity.common.ISResourceBundle)3 Enumeration (java.util.Enumeration)3 Iterator (java.util.Iterator)3 List (java.util.List)3 Set (java.util.Set)3 AttributeSchema (com.sun.identity.sm.AttributeSchema)2