Search in sources :

Example 1 with ListResourceBundle

use of java.util.ListResourceBundle in project commons by twitter.

the class JULBridgeHandlerTest method checkMessageWithResourceBundleIsFormatted.

@Test
public void checkMessageWithResourceBundleIsFormatted() {
    ResourceBundle bundle = new ListResourceBundle() {

        @Override
        protected Object[][] getContents() {
            return new Object[][] { { "test is successful", "le test fonctionne" } };
        }
    };
    LogRecord record = new LogRecord(Level.FINEST, "test is successful");
    record.setResourceBundle(bundle);
    assertThat(JULBridgeHandler.formatMessage(record), is("le test fonctionne"));
}
Also used : LogRecord(java.util.logging.LogRecord) ListResourceBundle(java.util.ListResourceBundle) ListResourceBundle(java.util.ListResourceBundle) ResourceBundle(java.util.ResourceBundle) Test(org.junit.Test)

Example 2 with ListResourceBundle

use of java.util.ListResourceBundle in project j2objc by google.

the class Messages 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 ListResourceBundle,
 * without language suffix.
 * @return the ResourceBundle
 * @throws MissingResourceException
 * @xsl.usage internal
 */
private ListResourceBundle loadResourceBundle(String resourceBundle) throws MissingResourceException {
    m_resourceBundleName = resourceBundle;
    Locale locale = getLocale();
    ListResourceBundle lrb;
    try {
        ResourceBundle rb = ResourceBundle.getBundle(m_resourceBundleName, locale);
        lrb = (ListResourceBundle) rb;
    } catch (MissingResourceException e) {
        try // try to fall back to en_US if we can't load
        {
            // Since we can't find the localized property file,
            // fall back to en_US.
            lrb = (ListResourceBundle) ResourceBundle.getBundle(m_resourceBundleName, 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." + m_resourceBundleName, m_resourceBundleName, "");
        }
    }
    m_resourceBundle = lrb;
    return lrb;
}
Also used : Locale(java.util.Locale) ListResourceBundle(java.util.ListResourceBundle) MissingResourceException(java.util.MissingResourceException) ResourceBundle(java.util.ResourceBundle) ListResourceBundle(java.util.ListResourceBundle)

Example 3 with ListResourceBundle

use of java.util.ListResourceBundle in project j2objc by google.

the class ListResourceBundleTest method test_handleGetObjectLjava_lang_String.

@SuppressWarnings("unchecked")
public void test_handleGetObjectLjava_lang_String() {
    ListResourceBundle bundle;
    String name = "tests.support.Support_TestResource";
    Locale.setDefault(new Locale("en", "US"));
    bundle = (ListResourceBundle) ResourceBundle.getBundle(name, new Locale("fr", "FR", "VAR"));
    Enumeration keys = bundle.getKeys();
    String keyValue = null;
    Vector result = new Vector();
    while (keys.hasMoreElements()) {
        result.addElement(bundle.handleGetObject((String) keys.nextElement()));
    }
    assertEquals(9, result.size());
    assertTrue(result.contains(null));
    assertTrue(result.contains("frFRVARValue4"));
    assertTrue(result.contains("frFRVARChildValue1"));
    assertTrue(result.contains("frFRVARChildValue2"));
    assertTrue(result.contains("frFRVARChildValue3"));
    assertTrue(result.remove(null));
    assertTrue(result.remove(null));
    assertTrue(result.remove(null));
}
Also used : Locale(java.util.Locale) Enumeration(java.util.Enumeration) ListResourceBundle(java.util.ListResourceBundle) Vector(java.util.Vector)

Example 4 with ListResourceBundle

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

the class ListResourceBundleTest method test_handleGetObjectLjava_lang_String.

public void test_handleGetObjectLjava_lang_String() {
    ListResourceBundle bundle;
    String name = "tests.support.Support_TestResource";
    Locale.setDefault(new Locale("en", "US"));
    bundle = (ListResourceBundle) ResourceBundle.getBundle(name, new Locale("fr", "FR", "VAR"));
    Enumeration keys = bundle.getKeys();
    String keyValue = null;
    Vector result = new Vector();
    while (keys.hasMoreElements()) {
        result.addElement(bundle.handleGetObject((String) keys.nextElement()));
    }
    assertEquals(9, result.size());
    assertTrue(result.contains(null));
    assertTrue(result.contains("frFRVARValue4"));
    assertTrue(result.contains("frFRVARChildValue1"));
    assertTrue(result.contains("frFRVARChildValue2"));
    assertTrue(result.contains("frFRVARChildValue3"));
    assertTrue(result.remove(null));
    assertTrue(result.remove(null));
    assertTrue(result.remove(null));
}
Also used : Locale(java.util.Locale) Enumeration(java.util.Enumeration) ListResourceBundle(java.util.ListResourceBundle) Vector(java.util.Vector)

Example 5 with ListResourceBundle

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

the class Messages 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 ListResourceBundle,
     * without language suffix.
     * @return the ResourceBundle
     * @throws MissingResourceException
     * @xsl.usage internal
     */
private ListResourceBundle loadResourceBundle(String resourceBundle) throws MissingResourceException {
    m_resourceBundleName = resourceBundle;
    Locale locale = getLocale();
    ListResourceBundle lrb;
    try {
        ResourceBundle rb = ResourceBundle.getBundle(m_resourceBundleName, locale);
        lrb = (ListResourceBundle) rb;
    } catch (MissingResourceException e) {
        try // try to fall back to en_US if we can't load
        {
            // Since we can't find the localized property file,
            // fall back to en_US.
            lrb = (ListResourceBundle) ResourceBundle.getBundle(m_resourceBundleName, 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." + m_resourceBundleName, m_resourceBundleName, "");
        }
    }
    m_resourceBundle = lrb;
    return lrb;
}
Also used : Locale(java.util.Locale) ListResourceBundle(java.util.ListResourceBundle) MissingResourceException(java.util.MissingResourceException) ResourceBundle(java.util.ResourceBundle) ListResourceBundle(java.util.ListResourceBundle)

Aggregations

ListResourceBundle (java.util.ListResourceBundle)8 Locale (java.util.Locale)5 ResourceBundle (java.util.ResourceBundle)4 Enumeration (java.util.Enumeration)3 Vector (java.util.Vector)3 MissingResourceException (java.util.MissingResourceException)2 Test (org.junit.Test)2 HashMap (java.util.HashMap)1 LogRecord (java.util.logging.LogRecord)1 ResourceBundleProvider (org.apache.sling.i18n.ResourceBundleProvider)1