java.util.ResourceBundle.Control Java Examples

The following examples show how to use java.util.ResourceBundle.Control. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: NdkPlugin.java    From proarc with GNU General Public License v3.0 6 votes vote down vote up
private ValueMap<? extends LanguageTermDefinition> readLangs(Locale locale) {
    ArrayList<LangTermValue> langs = new ArrayList<LangTermValue>();
    // to read properties file in UTF-8 use PropertyResourceBundle(Reader)
    Control control = ResourceBundle.Control.getNoFallbackControl(ResourceBundle.Control.FORMAT_PROPERTIES);

    ResourceBundle rb = ResourceBundle.getBundle(BundleName.LANGUAGES_ISO639_2.toString(), locale, control);
    for (String key : rb.keySet()) {
        LangTermValue lt = new LangTermValue();
        lt.setAuthority("iso639-2b");
        lt.setType(CodeOrText.CODE);
        lt.setValue(key);
        lt.setTitle(rb.getString(key));
        langs.add(lt);
    }
    Collections.sort(langs, new LangComparator(locale));
    return new ValueMap<LangTermValue>(BundleName.LANGUAGES_ISO639_2.getValueMapId(), langs);
}
 
Example #2
Source File: ResourceBundleTest.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * @bug 4108126
 */
public void TestGetLocale() {
    // try to find TestResource_fr_CH.  Should get fr_CH as its locale
    ResourceBundle test = ResourceBundle.getBundle("TestResource",
                    new Locale("fr", "CH", ""));
    Locale locale = test.getLocale();
    if (!(locale.getLanguage().equals("fr")) || !(locale.getCountry().equals("CH")))
        errln("Actual locale for TestResource_fr_CH should have been fr_CH, got " + locale);

    // try to find TestResource_fr_BE, which doesn't exist.  Should get fr as its locale
    test = ResourceBundle.getBundle("TestResource",
                    new Locale("fr", "BE", ""));
    locale = test.getLocale();
    if (!(locale.getLanguage().equals("fr")) || !(locale.getCountry().equals("")))
        errln("Actual locale for TestResource_fr_BE should have been fr, got " + locale);

    // try to find TestResource_iw_IL, which doesn't exist.  Should get root locale
    // as its locale
    test = ResourceBundle.getBundle("TestResource",
                    new Locale("iw", "IL", ""),
                    Control.getNoFallbackControl(Control.FORMAT_DEFAULT));
    locale = test.getLocale();
    if (!(locale.getLanguage().equals("")) || !(locale.getCountry().equals("")))
        errln("Actual locale for TestResource_iw_IL should have been the root locale, got "
                        + locale);
}
 
Example #3
Source File: ResourceBundleTest.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * @bug 4108126
 */
public void TestGetLocale() {
    // try to find TestResource_fr_CH.  Should get fr_CH as its locale
    ResourceBundle test = ResourceBundle.getBundle("TestResource",
                    new Locale("fr", "CH", ""));
    Locale locale = test.getLocale();
    if (!(locale.getLanguage().equals("fr")) || !(locale.getCountry().equals("CH")))
        errln("Actual locale for TestResource_fr_CH should have been fr_CH, got " + locale);

    // try to find TestResource_fr_BE, which doesn't exist.  Should get fr as its locale
    test = ResourceBundle.getBundle("TestResource",
                    new Locale("fr", "BE", ""));
    locale = test.getLocale();
    if (!(locale.getLanguage().equals("fr")) || !(locale.getCountry().equals("")))
        errln("Actual locale for TestResource_fr_BE should have been fr, got " + locale);

    // try to find TestResource_iw_IL, which doesn't exist.  Should get root locale
    // as its locale
    test = ResourceBundle.getBundle("TestResource",
                    new Locale("iw", "IL", ""),
                    Control.getNoFallbackControl(Control.FORMAT_DEFAULT));
    locale = test.getLocale();
    if (!(locale.getLanguage().equals("")) || !(locale.getCountry().equals("")))
        errln("Actual locale for TestResource_iw_IL should have been the root locale, got "
                        + locale);
}
 
Example #4
Source File: ResourceBundleTest.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * @bug 4108126
 */
public void TestGetLocale() {
    // try to find TestResource_fr_CH.  Should get fr_CH as its locale
    ResourceBundle test = ResourceBundle.getBundle("TestResource",
                    new Locale("fr", "CH", ""));
    Locale locale = test.getLocale();
    if (!(locale.getLanguage().equals("fr")) || !(locale.getCountry().equals("CH")))
        errln("Actual locale for TestResource_fr_CH should have been fr_CH, got " + locale);

    // try to find TestResource_fr_BE, which doesn't exist.  Should get fr as its locale
    test = ResourceBundle.getBundle("TestResource",
                    new Locale("fr", "BE", ""));
    locale = test.getLocale();
    if (!(locale.getLanguage().equals("fr")) || !(locale.getCountry().equals("")))
        errln("Actual locale for TestResource_fr_BE should have been fr, got " + locale);

    // try to find TestResource_iw_IL, which doesn't exist.  Should get root locale
    // as its locale
    test = ResourceBundle.getBundle("TestResource",
                    new Locale("iw", "IL", ""),
                    Control.getNoFallbackControl(Control.FORMAT_DEFAULT));
    locale = test.getLocale();
    if (!(locale.getLanguage().equals("")) || !(locale.getCountry().equals("")))
        errln("Actual locale for TestResource_iw_IL should have been the root locale, got "
                        + locale);
}
 
Example #5
Source File: ResourceBundleTest.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * @bug 4108126
 */
public void TestGetLocale() {
    // try to find TestResource_fr_CH.  Should get fr_CH as its locale
    ResourceBundle test = ResourceBundle.getBundle("TestResource",
                    new Locale("fr", "CH", ""));
    Locale locale = test.getLocale();
    if (!(locale.getLanguage().equals("fr")) || !(locale.getCountry().equals("CH")))
        errln("Actual locale for TestResource_fr_CH should have been fr_CH, got " + locale);

    // try to find TestResource_fr_BE, which doesn't exist.  Should get fr as its locale
    test = ResourceBundle.getBundle("TestResource",
                    new Locale("fr", "BE", ""));
    locale = test.getLocale();
    if (!(locale.getLanguage().equals("fr")) || !(locale.getCountry().equals("")))
        errln("Actual locale for TestResource_fr_BE should have been fr, got " + locale);

    // try to find TestResource_iw_IL, which doesn't exist.  Should get root locale
    // as its locale
    test = ResourceBundle.getBundle("TestResource",
                    new Locale("iw", "IL", ""),
                    Control.getNoFallbackControl(Control.FORMAT_DEFAULT));
    locale = test.getLocale();
    if (!(locale.getLanguage().equals("")) || !(locale.getCountry().equals("")))
        errln("Actual locale for TestResource_iw_IL should have been the root locale, got "
                        + locale);
}
 
Example #6
Source File: ResourceBundleTest.java    From jdk8u-dev-jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * @bug 4108126
 */
public void TestGetLocale() {
    // try to find TestResource_fr_CH.  Should get fr_CH as its locale
    ResourceBundle test = ResourceBundle.getBundle("TestResource",
                    new Locale("fr", "CH", ""));
    Locale locale = test.getLocale();
    if (!(locale.getLanguage().equals("fr")) || !(locale.getCountry().equals("CH")))
        errln("Actual locale for TestResource_fr_CH should have been fr_CH, got " + locale);

    // try to find TestResource_fr_BE, which doesn't exist.  Should get fr as its locale
    test = ResourceBundle.getBundle("TestResource",
                    new Locale("fr", "BE", ""));
    locale = test.getLocale();
    if (!(locale.getLanguage().equals("fr")) || !(locale.getCountry().equals("")))
        errln("Actual locale for TestResource_fr_BE should have been fr, got " + locale);

    // try to find TestResource_iw_IL, which doesn't exist.  Should get root locale
    // as its locale
    test = ResourceBundle.getBundle("TestResource",
                    new Locale("iw", "IL", ""),
                    Control.getNoFallbackControl(Control.FORMAT_DEFAULT));
    locale = test.getLocale();
    if (!(locale.getLanguage().equals("")) || !(locale.getCountry().equals("")))
        errln("Actual locale for TestResource_iw_IL should have been the root locale, got "
                        + locale);
}
 
Example #7
Source File: LanguageResourceBundleManager.java    From smarthome with Eclipse Public License 2.0 6 votes vote down vote up
private String getTranslatedText(String resourceName, String key, Locale locale) {
    try {
        // Modify the search order so that the following applies:
        // 1.) baseName + "_" + language + "_" + country
        // 2.) baseName + "_" + language
        // 3.) baseName
        // 4.) null -> leads to a default text
        // Not using the default fallback strategy helps that not the default locale
        // search order is applied between 2.) and 3.).
        ResourceBundle resourceBundle = ResourceBundle.getBundle(resourceName, locale, this.resourceClassLoader,
                Control.getNoFallbackControl(Control.FORMAT_PROPERTIES));

        if (resourceBundle != null) {
            return resourceBundle.getString(key);
        }
    } catch (Exception ex) {
        // nothing to do
    }

    return null;
}
 
Example #8
Source File: SemanticTags.java    From openhab-core with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Determines the semantic entity type of an item, i.e. a sub-type of Location, Equipment or Point.
 *
 * @param item the item to get the semantic type for
 * @return a sub-type of Location, Equipment or Point
 */
public static @Nullable Class<? extends Tag> getSemanticType(Item item) {
    Set<String> tags = item.getTags();
    for (String tag : tags) {
        Class<? extends Tag> type = getById(tag);
        if (type != null && !Property.class.isAssignableFrom(type)) {
            return type;
        }
    }
    // we haven't found any type as a tag, but if there is a Property tag, we can conclude that it is a Point
    if (getProperty(item) != null) {
        StateDescription stateDescription = item.getStateDescription();
        if (stateDescription != null && stateDescription.isReadOnly()) {
            return Measurement.class;
        } else {
            return org.openhab.core.semantics.model.point.Control.class;
        }
    } else {
        return null;
    }
}
 
Example #9
Source File: ResourceBundleTest.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
/**
 * @bug 4108126
 */
public void TestGetLocale() {
    // try to find TestResource_fr_CH.  Should get fr_CH as its locale
    ResourceBundle test = ResourceBundle.getBundle("TestResource",
                    new Locale("fr", "CH", ""));
    Locale locale = test.getLocale();
    if (!(locale.getLanguage().equals("fr")) || !(locale.getCountry().equals("CH")))
        errln("Actual locale for TestResource_fr_CH should have been fr_CH, got " + locale);

    // try to find TestResource_fr_BE, which doesn't exist.  Should get fr as its locale
    test = ResourceBundle.getBundle("TestResource",
                    new Locale("fr", "BE", ""));
    locale = test.getLocale();
    if (!(locale.getLanguage().equals("fr")) || !(locale.getCountry().equals("")))
        errln("Actual locale for TestResource_fr_BE should have been fr, got " + locale);

    // try to find TestResource_iw_IL, which doesn't exist.  Should get root locale
    // as its locale
    test = ResourceBundle.getBundle("TestResource",
                    new Locale("iw", "IL", ""),
                    Control.getNoFallbackControl(Control.FORMAT_DEFAULT));
    locale = test.getLocale();
    if (!(locale.getLanguage().equals("")) || !(locale.getCountry().equals("")))
        errln("Actual locale for TestResource_iw_IL should have been the root locale, got "
                        + locale);
}
 
Example #10
Source File: LanguageResourceBundleManager.java    From openhab-core with Eclipse Public License 2.0 6 votes vote down vote up
private String getTranslatedText(String resourceName, String key, Locale locale) {
    try {
        // Modify the search order so that the following applies:
        // 1.) baseName + "_" + language + "_" + country
        // 2.) baseName + "_" + language
        // 3.) baseName
        // 4.) null -> leads to a default text
        // Not using the default fallback strategy helps that not the default locale
        // search order is applied between 2.) and 3.).
        ResourceBundle resourceBundle = ResourceBundle.getBundle(resourceName, locale, this.resourceClassLoader,
                Control.getNoFallbackControl(Control.FORMAT_PROPERTIES));

        if (resourceBundle != null) {
            return resourceBundle.getString(key);
        }
    } catch (Exception ex) {
        // nothing to do
    }

    return null;
}
 
Example #11
Source File: ResourceBundleTest.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
/**
 * @bug 4108126
 */
public void TestGetLocale() {
    // try to find TestResource_fr_CH.  Should get fr_CH as its locale
    ResourceBundle test = ResourceBundle.getBundle("TestResource",
                    new Locale("fr", "CH", ""));
    Locale locale = test.getLocale();
    if (!(locale.getLanguage().equals("fr")) || !(locale.getCountry().equals("CH")))
        errln("Actual locale for TestResource_fr_CH should have been fr_CH, got " + locale);

    // try to find TestResource_fr_BE, which doesn't exist.  Should get fr as its locale
    test = ResourceBundle.getBundle("TestResource",
                    new Locale("fr", "BE", ""));
    locale = test.getLocale();
    if (!(locale.getLanguage().equals("fr")) || !(locale.getCountry().equals("")))
        errln("Actual locale for TestResource_fr_BE should have been fr, got " + locale);

    // try to find TestResource_iw_IL, which doesn't exist.  Should get root locale
    // as its locale
    test = ResourceBundle.getBundle("TestResource",
                    new Locale("iw", "IL", ""),
                    Control.getNoFallbackControl(Control.FORMAT_DEFAULT));
    locale = test.getLocale();
    if (!(locale.getLanguage().equals("")) || !(locale.getCountry().equals("")))
        errln("Actual locale for TestResource_iw_IL should have been the root locale, got "
                        + locale);
}
 
Example #12
Source File: ResourceBundleTest.java    From jdk8u_jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * @bug 4108126
 */
public void TestGetLocale() {
    // try to find TestResource_fr_CH.  Should get fr_CH as its locale
    ResourceBundle test = ResourceBundle.getBundle("TestResource",
                    new Locale("fr", "CH", ""));
    Locale locale = test.getLocale();
    if (!(locale.getLanguage().equals("fr")) || !(locale.getCountry().equals("CH")))
        errln("Actual locale for TestResource_fr_CH should have been fr_CH, got " + locale);

    // try to find TestResource_fr_BE, which doesn't exist.  Should get fr as its locale
    test = ResourceBundle.getBundle("TestResource",
                    new Locale("fr", "BE", ""));
    locale = test.getLocale();
    if (!(locale.getLanguage().equals("fr")) || !(locale.getCountry().equals("")))
        errln("Actual locale for TestResource_fr_BE should have been fr, got " + locale);

    // try to find TestResource_iw_IL, which doesn't exist.  Should get root locale
    // as its locale
    test = ResourceBundle.getBundle("TestResource",
                    new Locale("iw", "IL", ""),
                    Control.getNoFallbackControl(Control.FORMAT_DEFAULT));
    locale = test.getLocale();
    if (!(locale.getLanguage().equals("")) || !(locale.getCountry().equals("")))
        errln("Actual locale for TestResource_iw_IL should have been the root locale, got "
                        + locale);
}
 
Example #13
Source File: ResourceBundleTest.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * @bug 4108126
 */
public void TestGetLocale() {
    // try to find TestResource_fr_CH.  Should get fr_CH as its locale
    ResourceBundle test = ResourceBundle.getBundle("TestResource",
                    new Locale("fr", "CH", ""));
    Locale locale = test.getLocale();
    if (!(locale.getLanguage().equals("fr")) || !(locale.getCountry().equals("CH")))
        errln("Actual locale for TestResource_fr_CH should have been fr_CH, got " + locale);

    // try to find TestResource_fr_BE, which doesn't exist.  Should get fr as its locale
    test = ResourceBundle.getBundle("TestResource",
                    new Locale("fr", "BE", ""));
    locale = test.getLocale();
    if (!(locale.getLanguage().equals("fr")) || !(locale.getCountry().equals("")))
        errln("Actual locale for TestResource_fr_BE should have been fr, got " + locale);

    // try to find TestResource_iw_IL, which doesn't exist.  Should get root locale
    // as its locale
    test = ResourceBundle.getBundle("TestResource",
                    new Locale("iw", "IL", ""),
                    Control.getNoFallbackControl(Control.FORMAT_DEFAULT));
    locale = test.getLocale();
    if (!(locale.getLanguage().equals("")) || !(locale.getCountry().equals("")))
        errln("Actual locale for TestResource_iw_IL should have been the root locale, got "
                        + locale);
}
 
Example #14
Source File: ResourceBundleTest.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * @bug 4108126
 */
public void TestGetLocale() {
    // try to find TestResource_fr_CH.  Should get fr_CH as its locale
    ResourceBundle test = ResourceBundle.getBundle("TestResource",
                    new Locale("fr", "CH", ""));
    Locale locale = test.getLocale();
    if (!(locale.getLanguage().equals("fr")) || !(locale.getCountry().equals("CH")))
        errln("Actual locale for TestResource_fr_CH should have been fr_CH, got " + locale);

    // try to find TestResource_fr_BE, which doesn't exist.  Should get fr as its locale
    test = ResourceBundle.getBundle("TestResource",
                    new Locale("fr", "BE", ""));
    locale = test.getLocale();
    if (!(locale.getLanguage().equals("fr")) || !(locale.getCountry().equals("")))
        errln("Actual locale for TestResource_fr_BE should have been fr, got " + locale);

    // try to find TestResource_iw_IL, which doesn't exist.  Should get root locale
    // as its locale
    test = ResourceBundle.getBundle("TestResource",
                    new Locale("iw", "IL", ""),
                    Control.getNoFallbackControl(Control.FORMAT_DEFAULT));
    locale = test.getLocale();
    if (!(locale.getLanguage().equals("")) || !(locale.getCountry().equals("")))
        errln("Actual locale for TestResource_iw_IL should have been the root locale, got "
                        + locale);
}
 
Example #15
Source File: ResourceBundleTest.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * @bug 4108126
 */
public void TestGetLocale() {
    // try to find TestResource_fr_CH.  Should get fr_CH as its locale
    ResourceBundle test = ResourceBundle.getBundle("TestResource",
                    new Locale("fr", "CH", ""));
    Locale locale = test.getLocale();
    if (!(locale.getLanguage().equals("fr")) || !(locale.getCountry().equals("CH")))
        errln("Actual locale for TestResource_fr_CH should have been fr_CH, got " + locale);

    // try to find TestResource_fr_BE, which doesn't exist.  Should get fr as its locale
    test = ResourceBundle.getBundle("TestResource",
                    new Locale("fr", "BE", ""));
    locale = test.getLocale();
    if (!(locale.getLanguage().equals("fr")) || !(locale.getCountry().equals("")))
        errln("Actual locale for TestResource_fr_BE should have been fr, got " + locale);

    // try to find TestResource_iw_IL, which doesn't exist.  Should get root locale
    // as its locale
    test = ResourceBundle.getBundle("TestResource",
                    new Locale("iw", "IL", ""),
                    Control.getNoFallbackControl(Control.FORMAT_DEFAULT));
    locale = test.getLocale();
    if (!(locale.getLanguage().equals("")) || !(locale.getCountry().equals("")))
        errln("Actual locale for TestResource_iw_IL should have been the root locale, got "
                        + locale);
}
 
Example #16
Source File: JRPropertiesUtil.java    From jasperreports with GNU Lesser General Public License v3.0 6 votes vote down vote up
public String getLocalizedProperty(String property, Locale locale)
{
	Control control = Control.getControl(Control.FORMAT_PROPERTIES);
	String value = null;
	
	// we're not looking at the fallback locale to be consistent with JRResourcesUtil.loadResourceBundle
	List<Locale> locales = control.getCandidateLocales(property, locale);
	for (Locale candidate : locales)
	{
		String candidateString = candidate.toString();
		String candidateProperty = candidateString.isEmpty() ? property : (property + "_" + candidateString);
		String candidateValue = getProperty(candidateProperty);
		if (candidateValue != null)// test for empty?
		{
			value = candidateValue;
			break;
		}
	}
	return value;
}
 
Example #17
Source File: ResourceBundleTest.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
/**
 * @bug 4108126
 */
public void TestGetLocale() {
    // try to find TestResource_fr_CH.  Should get fr_CH as its locale
    ResourceBundle test = ResourceBundle.getBundle("TestResource",
                    new Locale("fr", "CH", ""));
    Locale locale = test.getLocale();
    if (!(locale.getLanguage().equals("fr")) || !(locale.getCountry().equals("CH")))
        errln("Actual locale for TestResource_fr_CH should have been fr_CH, got " + locale);

    // try to find TestResource_fr_BE, which doesn't exist.  Should get fr as its locale
    test = ResourceBundle.getBundle("TestResource",
                    new Locale("fr", "BE", ""));
    locale = test.getLocale();
    if (!(locale.getLanguage().equals("fr")) || !(locale.getCountry().equals("")))
        errln("Actual locale for TestResource_fr_BE should have been fr, got " + locale);

    // try to find TestResource_iw_IL, which doesn't exist.  Should get root locale
    // as its locale
    test = ResourceBundle.getBundle("TestResource",
                    new Locale("iw", "IL", ""),
                    Control.getNoFallbackControl(Control.FORMAT_DEFAULT));
    locale = test.getLocale();
    if (!(locale.getLanguage().equals("")) || !(locale.getCountry().equals("")))
        errln("Actual locale for TestResource_iw_IL should have been the root locale, got "
                        + locale);
}
 
Example #18
Source File: ResourceBundleTest.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
/**
 * @bug 4108126
 */
public void TestGetLocale() {
    // try to find TestResource_fr_CH.  Should get fr_CH as its locale
    ResourceBundle test = ResourceBundle.getBundle("TestResource",
                    new Locale("fr", "CH", ""));
    Locale locale = test.getLocale();
    if (!(locale.getLanguage().equals("fr")) || !(locale.getCountry().equals("CH")))
        errln("Actual locale for TestResource_fr_CH should have been fr_CH, got " + locale);

    // try to find TestResource_fr_BE, which doesn't exist.  Should get fr as its locale
    test = ResourceBundle.getBundle("TestResource",
                    new Locale("fr", "BE", ""));
    locale = test.getLocale();
    if (!(locale.getLanguage().equals("fr")) || !(locale.getCountry().equals("")))
        errln("Actual locale for TestResource_fr_BE should have been fr, got " + locale);

    // try to find TestResource_iw_IL, which doesn't exist.  Should get root locale
    // as its locale
    test = ResourceBundle.getBundle("TestResource",
                    new Locale("iw", "IL", ""),
                    Control.getNoFallbackControl(Control.FORMAT_DEFAULT));
    locale = test.getLocale();
    if (!(locale.getLanguage().equals("")) || !(locale.getCountry().equals("")))
        errln("Actual locale for TestResource_iw_IL should have been the root locale, got "
                        + locale);
}
 
Example #19
Source File: UIDefaults.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns a Map of the known resources for the given locale.
 */
private Map<String, Object> getResourceCache(Locale l) {
    Map<String, Object> values = resourceCache.get(l);

    if (values == null) {
        values = new TextAndMnemonicHashMap();
        for (int i=resourceBundles.size()-1; i >= 0; i--) {
            String bundleName = resourceBundles.get(i);
            try {
                Control c = CoreResourceBundleControl.getRBControlInstance(bundleName);
                ResourceBundle b;
                if (c != null) {
                    b = ResourceBundle.getBundle(bundleName, l, c);
                } else {
                    b = ResourceBundle.getBundle(bundleName, l);
                }
                Enumeration keys = b.getKeys();

                while (keys.hasMoreElements()) {
                    String key = (String)keys.nextElement();

                    if (values.get(key) == null) {
                        Object value = b.getObject(key);

                        values.put(key, value);
                    }
                }
            } catch( MissingResourceException mre ) {
                // Keep looking
            }
        }
        resourceCache.put(l, values);
    }
    return values;
}
 
Example #20
Source File: ResourceBundleTest.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
public void TestListResourceBundle() {
    // load up the resource and check to make sure we got the right class
    // (we don't define be_BY or be, so we fall back on the root default)
    ResourceBundle  bundle = ResourceBundle.getBundle("TestResource",
                        new Locale("be", "BY"),
                        Control.getNoFallbackControl(Control.FORMAT_DEFAULT));
    if (!bundle.getClass().getName().equals("TestResource"))
        errln("Expected TestResource, got " + bundle.getClass().getName());

    doListResourceBundleTest(bundle);
}
 
Example #21
Source File: JsonValueMap.java    From proarc with GNU General Public License v3.0 5 votes vote down vote up
private static URL findResource(String basename, Control ctrl, Locale locale) {
    String format = ctrl.getFormats(basename).get(0);
    String resourceName = '/' + ctrl.toResourceName(ctrl.toBundleName(basename, locale), format);
    URL resource = JsonValueMap.class.getResource(resourceName);
    if (resource == null) {
        resourceName = '/' + ctrl.toResourceName(ctrl.toBundleName(basename, Locale.ROOT), format);
        resource = JsonValueMap.class.getResource(resourceName);
    }
    if (resource == null) {
        LOG.log(Level.WARNING, null, new IllegalStateException(
                "Cannot find resource " + basename + ", " + locale));
    }
    return resource;
}
 
Example #22
Source File: UIDefaults.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns a Map of the known resources for the given locale.
 */
private Map<String, Object> getResourceCache(Locale l) {
    Map<String, Object> values = resourceCache.get(l);

    if (values == null) {
        values = new TextAndMnemonicHashMap();
        for (int i=resourceBundles.size()-1; i >= 0; i--) {
            String bundleName = resourceBundles.get(i);
            try {
                Control c = CoreResourceBundleControl.getRBControlInstance(bundleName);
                ResourceBundle b;
                if (c != null) {
                    b = ResourceBundle.getBundle(bundleName, l, c);
                } else {
                    b = ResourceBundle.getBundle(bundleName, l);
                }
                Enumeration keys = b.getKeys();

                while (keys.hasMoreElements()) {
                    String key = (String)keys.nextElement();

                    if (values.get(key) == null) {
                        Object value = b.getObject(key);

                        values.put(key, value);
                    }
                }
            } catch( MissingResourceException mre ) {
                // Keep looking
            }
        }
        resourceCache.put(l, values);
    }
    return values;
}
 
Example #23
Source File: ResourceBundleTest.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
public void TestListResourceBundle() {
    // load up the resource and check to make sure we got the right class
    // (we don't define be_BY or be, so we fall back on the root default)
    ResourceBundle  bundle = ResourceBundle.getBundle("TestResource",
                        new Locale("be", "BY"),
                        Control.getNoFallbackControl(Control.FORMAT_DEFAULT));
    if (!bundle.getClass().getName().equals("TestResource"))
        errln("Expected TestResource, got " + bundle.getClass().getName());

    doListResourceBundleTest(bundle);
}
 
Example #24
Source File: ResourceBundleTest.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
public void TestListResourceBundle() {
    // load up the resource and check to make sure we got the right class
    // (we don't define be_BY or be, so we fall back on the root default)
    ResourceBundle  bundle = ResourceBundle.getBundle("TestResource",
                        new Locale("be", "BY"),
                        Control.getNoFallbackControl(Control.FORMAT_DEFAULT));
    if (!bundle.getClass().getName().equals("TestResource"))
        errln("Expected TestResource, got " + bundle.getClass().getName());

    doListResourceBundleTest(bundle);
}
 
Example #25
Source File: UIDefaults.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns a Map of the known resources for the given locale.
 */
private Map<String, Object> getResourceCache(Locale l) {
    Map<String, Object> values = resourceCache.get(l);

    if (values == null) {
        values = new TextAndMnemonicHashMap();
        for (int i=resourceBundles.size()-1; i >= 0; i--) {
            String bundleName = resourceBundles.get(i);
            try {
                Control c = CoreResourceBundleControl.getRBControlInstance(bundleName);
                ResourceBundle b;
                if (c != null) {
                    b = ResourceBundle.getBundle(bundleName, l, c);
                } else {
                    b = ResourceBundle.getBundle(bundleName, l);
                }
                Enumeration keys = b.getKeys();

                while (keys.hasMoreElements()) {
                    String key = (String)keys.nextElement();

                    if (values.get(key) == null) {
                        Object value = b.getObject(key);

                        values.put(key, value);
                    }
                }
            } catch( MissingResourceException mre ) {
                // Keep looking
            }
        }
        resourceCache.put(l, values);
    }
    return values;
}
 
Example #26
Source File: LocaleServiceProviderPool.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns a list of candidate locales for service look up.
 * @param locale the input locale
 * @return the list of candidate locales for the given locale
 */
static List<Locale> getLookupLocales(Locale locale) {
    // Note: We currently use the default implementation of
    // ResourceBundle.Control.getCandidateLocales. The result
    // returned by getCandidateLocales are already normalized
    // (no extensions) for service look up.
    List<Locale> lookupLocales = Control.getNoFallbackControl(Control.FORMAT_DEFAULT)
                                        .getCandidateLocales("", locale);
    return lookupLocales;
}
 
Example #27
Source File: ResourceBundleTest.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
public void TestListResourceBundle() {
    // load up the resource and check to make sure we got the right class
    // (we don't define be_BY or be, so we fall back on the root default)
    ResourceBundle  bundle = ResourceBundle.getBundle("TestResource",
                        new Locale("be", "BY"),
                        Control.getNoFallbackControl(Control.FORMAT_DEFAULT));
    if (!bundle.getClass().getName().equals("TestResource"))
        errln("Expected TestResource, got " + bundle.getClass().getName());

    doListResourceBundleTest(bundle);
}
 
Example #28
Source File: UIDefaults.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns a Map of the known resources for the given locale.
 */
private Map<String, Object> getResourceCache(Locale l) {
    Map<String, Object> values = resourceCache.get(l);

    if (values == null) {
        values = new TextAndMnemonicHashMap();
        for (int i=resourceBundles.size()-1; i >= 0; i--) {
            String bundleName = resourceBundles.get(i);
            try {
                Control c = CoreResourceBundleControl.getRBControlInstance(bundleName);
                ResourceBundle b;
                if (c != null) {
                    b = ResourceBundle.getBundle(bundleName, l, c);
                } else {
                    b = ResourceBundle.getBundle(bundleName, l);
                }
                Enumeration keys = b.getKeys();

                while (keys.hasMoreElements()) {
                    String key = (String)keys.nextElement();

                    if (values.get(key) == null) {
                        Object value = b.getObject(key);

                        values.put(key, value);
                    }
                }
            } catch( MissingResourceException mre ) {
                // Keep looking
            }
        }
        resourceCache.put(l, values);
    }
    return values;
}
 
Example #29
Source File: ErrorResources.java    From sinavi-jfw with Apache License 2.0 5 votes vote down vote up
/**
 * リソースファイルよりメッセージを取得します。
 * もし、指定されたキーでメッセージが解決できない場合はキーを返します。
 * @param key エラーメッセージのキー
 * @param locale ロケール
 * @return エラーメッセージ
 */
public static String find(String key, Locale locale) {
    if (Strings.isEmpty(key)) return key;
    String msg = key;
    try {
        msg = ResourceBundle.getBundle(RESOURCE_NAME, locale != null ? locale : Locale.getDefault(),
            new ErrorMessageCacheControl(Control.FORMAT_PROPERTIES)).getString(key);
    } catch (MissingResourceException e) {
        if (L.isDebugEnabled()) {
            L.debug(Strings.substitute(R.getString("D-REST-JERSEY-UTIL#0001"), Maps.hash("key", key)));
        }
    }
    return msg;
}
 
Example #30
Source File: ResourceBundleTest.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
public void TestListResourceBundle() {
    // load up the resource and check to make sure we got the right class
    // (we don't define be_BY or be, so we fall back on the root default)
    ResourceBundle  bundle = ResourceBundle.getBundle("TestResource",
                        new Locale("be", "BY"),
                        Control.getNoFallbackControl(Control.FORMAT_DEFAULT));
    if (!bundle.getClass().getName().equals("TestResource"))
        errln("Expected TestResource, got " + bundle.getClass().getName());

    doListResourceBundleTest(bundle);
}