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, "");
}
}
}
use of java.util.MissingResourceException in project tomcat by apache.
the class Util method message.
static String message(ELContext context, String name, Object... props) {
Locale locale = null;
if (context != null) {
locale = context.getLocale();
}
if (locale == null) {
locale = Locale.getDefault();
if (locale == null) {
return "";
}
}
ResourceBundle bundle = ResourceBundle.getBundle("javax.el.LocalStrings", locale);
try {
String template = bundle.getString(name);
if (props != null) {
template = MessageFormat.format(template, props);
}
return template;
} catch (MissingResourceException e) {
return "Missing Resource: '" + name + "' for Locale " + locale.getDisplayName();
}
}
use of java.util.MissingResourceException in project tomcat by apache.
the class Localizer method getMessage.
/*
* Returns the localized error message corresponding to the given error
* code.
*
* If the given error code is not defined in the resource bundle for
* localized error messages, it is used as the error message.
*
* @param errCode Error code to localize
* @param args Arguments for parametric replacement
*
* @return Localized error message
*/
public static String getMessage(String errCode, Object[] args) {
String errMsg = errCode;
try {
errMsg = bundle.getString(errCode);
if (args != null && args.length > 0) {
MessageFormat formatter = new MessageFormat(errMsg);
errMsg = formatter.format(args);
}
} catch (MissingResourceException e) {
}
return errMsg;
}
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);
}
}
Aggregations