use of java.util.ResourceBundle in project tomcat by apache.
the class Util method message.
static String message(ELContext context, String name, Object... props) {
Locale locale = null;
if (context != null) {
locale = context.getLocale();
}
if (locale == null) {
locale = Locale.getDefault();
if (locale == null) {
return "";
}
}
ResourceBundle bundle = ResourceBundle.getBundle("javax.el.LocalStrings", locale);
try {
String template = bundle.getString(name);
if (props != null) {
template = MessageFormat.format(template, props);
}
return template;
} catch (MissingResourceException e) {
return "Missing Resource: '" + name + "' for Locale " + locale.getDisplayName();
}
}
use of java.util.ResourceBundle in project tomcat by apache.
the class TestResourceBundleELResolver method testGetType03.
/**
* Tests that null will be returned when base is ResourceBundle. Checks that
* the propertyResolved is true.
*/
@Test
public void testGetType03() {
ResourceBundleELResolver resolver = new ResourceBundleELResolver();
ELContext context = new StandardELContext(ELManager.getExpressionFactory());
ResourceBundle resourceBundle = new TesterResourceBundle();
Class<?> result = resolver.getType(context, resourceBundle, "key1");
Assert.assertNull(result);
Assert.assertTrue(context.isPropertyResolved());
}
use of java.util.ResourceBundle in project tomcat by apache.
the class TestResourceBundleELResolver method testGetValue03.
/**
* Tests that a valid property is resolved.
*/
@Test
public void testGetValue03() {
ResourceBundleELResolver resolver = new ResourceBundleELResolver();
ELContext context = new StandardELContext(ELManager.getExpressionFactory());
ResourceBundle resourceBundle = new TesterResourceBundle();
Object result = resolver.getValue(context, resourceBundle, "key1");
Assert.assertEquals("value1", result);
Assert.assertTrue(context.isPropertyResolved());
result = resolver.getValue(context, resourceBundle, "unknown-key");
Assert.assertEquals("???unknown-key???", result);
Assert.assertTrue(context.isPropertyResolved());
result = resolver.getValue(context, resourceBundle, null);
Assert.assertNull(result);
Assert.assertTrue(context.isPropertyResolved());
}
use of java.util.ResourceBundle in project cryptomator by cryptomator.
the class LocalizationTest method testStringFormatIsValid.
@Test
public void testStringFormatIsValid() throws IOException {
ResourceBundle ref = loadLanguage(RESOURCE_FOLDER_PATH + REF_FILE_NAME);
boolean allGood = true;
for (String langFileName : LANG_FILE_NAMES) {
ResourceBundle lang = loadLanguage(RESOURCE_FOLDER_PATH + langFileName);
allGood &= allStringFormatSpecifiersMatchReferenceLanguage(ref, lang, langFileName);
}
Assert.assertTrue(allGood);
}
use of java.util.ResourceBundle in project checkstyle by checkstyle.
the class LocalizedMessage method getBundle.
/**
* Find a ResourceBundle for a given bundle name. Uses the classloader
* of the class emitting this message, to be sure to get the correct
* bundle.
* @param bundleName the bundle name
* @return a ResourceBundle
*/
private ResourceBundle getBundle(String bundleName) {
synchronized (BUNDLE_CACHE) {
ResourceBundle resourceBundle = BUNDLE_CACHE.get(bundleName);
if (resourceBundle == null) {
resourceBundle = ResourceBundle.getBundle(bundleName, sLocale, sourceClass.getClassLoader(), new Utf8Control());
BUNDLE_CACHE.put(bundleName, resourceBundle);
}
return resourceBundle;
}
}
Aggregations