Search in sources :

Example 1 with ResourceBundle

use of java.util.ResourceBundle 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 2 with ResourceBundle

use of java.util.ResourceBundle in project tomcat by apache.

the class TestResourceBundleELResolver method testGetType03.

/**
     * Tests that null will be returned when base is ResourceBundle. Checks that
     * the propertyResolved is true.
     */
@Test
public void testGetType03() {
    ResourceBundleELResolver resolver = new ResourceBundleELResolver();
    ELContext context = new StandardELContext(ELManager.getExpressionFactory());
    ResourceBundle resourceBundle = new TesterResourceBundle();
    Class<?> result = resolver.getType(context, resourceBundle, "key1");
    Assert.assertNull(result);
    Assert.assertTrue(context.isPropertyResolved());
}
Also used : ResourceBundle(java.util.ResourceBundle) ListResourceBundle(java.util.ListResourceBundle) Test(org.junit.Test)

Example 3 with ResourceBundle

use of java.util.ResourceBundle in project tomcat by apache.

the class TestResourceBundleELResolver method testGetValue03.

/**
     * Tests that a valid property is resolved.
     */
@Test
public void testGetValue03() {
    ResourceBundleELResolver resolver = new ResourceBundleELResolver();
    ELContext context = new StandardELContext(ELManager.getExpressionFactory());
    ResourceBundle resourceBundle = new TesterResourceBundle();
    Object result = resolver.getValue(context, resourceBundle, "key1");
    Assert.assertEquals("value1", result);
    Assert.assertTrue(context.isPropertyResolved());
    result = resolver.getValue(context, resourceBundle, "unknown-key");
    Assert.assertEquals("???unknown-key???", result);
    Assert.assertTrue(context.isPropertyResolved());
    result = resolver.getValue(context, resourceBundle, null);
    Assert.assertNull(result);
    Assert.assertTrue(context.isPropertyResolved());
}
Also used : ResourceBundle(java.util.ResourceBundle) ListResourceBundle(java.util.ListResourceBundle) Test(org.junit.Test)

Example 4 with ResourceBundle

use of java.util.ResourceBundle in project cryptomator by cryptomator.

the class LocalizationTest method testStringFormatIsValid.

@Test
public void testStringFormatIsValid() throws IOException {
    ResourceBundle ref = loadLanguage(RESOURCE_FOLDER_PATH + REF_FILE_NAME);
    boolean allGood = true;
    for (String langFileName : LANG_FILE_NAMES) {
        ResourceBundle lang = loadLanguage(RESOURCE_FOLDER_PATH + langFileName);
        allGood &= allStringFormatSpecifiersMatchReferenceLanguage(ref, lang, langFileName);
    }
    Assert.assertTrue(allGood);
}
Also used : PropertyResourceBundle(java.util.PropertyResourceBundle) ResourceBundle(java.util.ResourceBundle) Test(org.junit.Test)

Example 5 with ResourceBundle

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

the class LocalizedMessage method getBundle.

/**
     * Find a ResourceBundle for a given bundle name. Uses the classloader
     * of the class emitting this message, to be sure to get the correct
     * bundle.
     * @param bundleName the bundle name
     * @return a ResourceBundle
     */
private ResourceBundle getBundle(String bundleName) {
    synchronized (BUNDLE_CACHE) {
        ResourceBundle resourceBundle = BUNDLE_CACHE.get(bundleName);
        if (resourceBundle == null) {
            resourceBundle = ResourceBundle.getBundle(bundleName, sLocale, sourceClass.getClassLoader(), new Utf8Control());
            BUNDLE_CACHE.put(bundleName, resourceBundle);
        }
        return resourceBundle;
    }
}
Also used : PropertyResourceBundle(java.util.PropertyResourceBundle) ResourceBundle(java.util.ResourceBundle)

Aggregations

ResourceBundle (java.util.ResourceBundle)1254 Locale (java.util.Locale)189 MissingResourceException (java.util.MissingResourceException)167 Test (org.junit.Test)107 ArrayList (java.util.ArrayList)74 IOException (java.io.IOException)71 HashMap (java.util.HashMap)70 PropertyResourceBundle (java.util.PropertyResourceBundle)62 File (java.io.File)49 URL (java.net.URL)49 InputStream (java.io.InputStream)45 Map (java.util.Map)45 EncodeControl (megamek.common.util.EncodeControl)36 GridBagConstraints (java.awt.GridBagConstraints)34 GridBagLayout (java.awt.GridBagLayout)34 Enumeration (java.util.Enumeration)34 ListResourceBundle (java.util.ListResourceBundle)31 HashSet (java.util.HashSet)30 Test (org.junit.jupiter.api.Test)30 ActionMessage (org.apache.struts.action.ActionMessage)29