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;
}
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;
}
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);
}
}
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;
}
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, "");
}
}
}
Aggregations