Search in sources :

Example 6 with ListResourceBundle

use of java.util.ListResourceBundle in project jdk8u_jdk by JetBrains.

the class NewResourcesNames method loadClass.

/**
     * Loads a resources using JRE and returns the names
     */
private static Set<String> loadClass(String clazz) throws Exception {
    ListResourceBundle lrb = (ListResourceBundle) Class.forName(clazz).newInstance();
    Set<String> keys = lrb.keySet();
    Map<String, String> newold = new HashMap<String, String>();
    boolean dup = false;
    // Check if normalize() creates dup entries. This is crucial.
    for (String k : keys) {
        String key = normalize(k);
        if (newold.containsKey(key)) {
            err("Dup found for " + key + ":");
            err("[" + newold.get(key) + "]");
            err("[" + k + "]");
            dup = true;
        }
        newold.put(key, k);
    }
    if (dup)
        throw new Exception();
    return keys;
}
Also used : HashMap(java.util.HashMap) ListResourceBundle(java.util.ListResourceBundle)

Example 7 with ListResourceBundle

use of java.util.ListResourceBundle in project sling by apache.

the class MockSlingHttpServletRequestTest method testResourceBundleFromProvider.

@Test
public void testResourceBundleFromProvider() {
    ResourceBundleProvider provider = mock(ResourceBundleProvider.class);
    bundleContext.registerService(ResourceBundleProvider.class.getName(), provider, null);
    when(provider.getResourceBundle("base1", Locale.US)).thenReturn(new ListResourceBundle() {

        @Override
        protected Object[][] getContents() {
            return new Object[][] { { "key1", "value1" } };
        }
    });
    ResourceBundle bundle = request.getResourceBundle("base1", Locale.US);
    assertNotNull(bundle);
    assertEquals("value1", bundle.getString("key1"));
    ResourceBundle bundle2 = request.getResourceBundle("base2", Locale.US);
    assertNotNull(bundle2);
    assertFalse(bundle2.getKeys().hasMoreElements());
}
Also used : ResourceBundleProvider(org.apache.sling.i18n.ResourceBundleProvider) ListResourceBundle(java.util.ListResourceBundle) ListResourceBundle(java.util.ListResourceBundle) ResourceBundle(java.util.ResourceBundle) Test(org.junit.Test)

Aggregations

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