Search in sources :

Example 11 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)

Example 12 with MissingResourceException

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

Example 13 with MissingResourceException

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

Example 14 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 15 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)

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