Example usage for java.util MissingResourceException toString

List of usage examples for java.util MissingResourceException toString

Introduction

In this page you can find the example usage for java.util MissingResourceException toString.

Prototype

public String toString() 

Source Link

Document

Returns a short description of this throwable.

Usage

From source file:org.pentaho.di.i18n.GlobalMessageUtil.java

/**
 * Returns a {@link ResourceBundle} corresponding to the given {@link Locale} package and resource class. Falls-back
 * on the ROOT {@link Locale}, if the {@code fallbackOnRoot} flag is true and the requested Locale is not available.
 *
 * @param locale         the {@link Locale} for which the {@link ResourceBundle} is being requested
 * @param packagePath//from   ww w . j a v a  2  s. c o m
 * @param resourceClass
 * @param fallbackOnRoot if true, and a {@link ResourceBundle} cannot be found for the requested {@link Locale}, falls
 *                       back on the ROOT {@link Locale}
 * @return a {@link ResourceBundle} corresponding to the given {@link Locale} package and resource class
 */
public static ResourceBundle getBundle(final Locale locale, final String packagePath,
        final Class<?> resourceClass, final boolean fallbackOnRoot) {
    final GlobalMessageControl control = new GlobalMessageControl(fallbackOnRoot);
    final String resourceName = control.toResourceName(control.toBundleName(packagePath, locale), "properties");

    ResourceBundle bundle;
    try {
        bundle = ResourceBundle.getBundle(packagePath, locale, resourceClass.getClassLoader(),
                new GlobalMessageControl(fallbackOnRoot));
    } catch (final MissingResourceException e) {
        final StringBuilder msg = new StringBuilder();
        msg.append("Unable to find properties file '").append(resourceName).append("': ").append(e.toString());
        throw new MissingResourceException(msg.toString(), resourceClass.getName(), packagePath);
    }
    return bundle;
}