Search in sources :

Example 1 with MCRConfigurationInputStream

use of org.mycore.common.config.MCRConfigurationInputStream in project mycore by MyCoRe-Org.

the class MCRCombinedResourceBundleControl method newBundle.

@Override
public ResourceBundle newBundle(String baseName, Locale locale, String format, ClassLoader loader, boolean reload) throws IllegalAccessException, InstantiationException, IOException {
    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug("New bundle: {}, locale {}", baseName, locale);
    }
    if (locale.equals(Locale.ROOT)) {
        // MCR-1064 fallback should be default language, if property key does not exist
        locale = defaultLocale;
    }
    String bundleName = baseName.substring(baseName.indexOf(':') + 1);
    String filename = CONTROL_HELPER.toBundleName(bundleName, locale) + ".properties";
    try (MCRConfigurationInputStream propertyStream = new MCRConfigurationInputStream(filename)) {
        if (propertyStream.isEmpty()) {
            throw new MissingResourceException(// className
            "Can't find bundle for base name " + baseName + ", locale " + locale, // className
            bundleName + "_" + locale, "");
        }
        return new PropertyResourceBundle(propertyStream);
    }
}
Also used : MCRConfigurationInputStream(org.mycore.common.config.MCRConfigurationInputStream) MissingResourceException(java.util.MissingResourceException) PropertyResourceBundle(java.util.PropertyResourceBundle)

Aggregations

MissingResourceException (java.util.MissingResourceException)1 PropertyResourceBundle (java.util.PropertyResourceBundle)1 MCRConfigurationInputStream (org.mycore.common.config.MCRConfigurationInputStream)1