use of java.util.PropertyResourceBundle in project collect by openforis.
the class ResourceBundleMessageSource method getMessage.
@Override
public String getMessage(Locale locale, String code, Object... args) {
List<PropertyResourceBundle> resourceBundles = getBundles(locale);
if (resourceBundles == null || resourceBundles.isEmpty()) {
return null;
} else {
for (PropertyResourceBundle resourceBundle : resourceBundles) {
if (resourceBundle.containsKey(code)) {
try {
String messageKey = resourceBundle.getString(code);
String result = MessageFormat.format(messageKey, args);
return result;
} catch (Exception e) {
// resource not found
}
}
}
return null;
}
}
use of java.util.PropertyResourceBundle in project bisq-core by bisq-network.
the class UTF8Control method newBundle.
public ResourceBundle newBundle(String baseName, @NotNull Locale locale, @NotNull String format, ClassLoader loader, boolean reload) throws IllegalAccessException, InstantiationException, IOException {
// The below is a copy of the default implementation.
final String bundleName = toBundleName(baseName, locale);
final String resourceName = toResourceName(bundleName, "properties");
ResourceBundle bundle = null;
InputStream stream = null;
if (reload) {
final URL url = loader.getResource(resourceName);
if (url != null) {
final URLConnection connection = url.openConnection();
if (connection != null) {
connection.setUseCaches(false);
stream = connection.getInputStream();
}
}
} else {
stream = loader.getResourceAsStream(resourceName);
}
if (stream != null) {
try {
// Only this line is changed to make it to read properties files as UTF-8.
bundle = new PropertyResourceBundle(new InputStreamReader(stream, "UTF-8"));
} finally {
stream.close();
}
}
return bundle;
}
use of java.util.PropertyResourceBundle in project springboot-javafx-support by roskenet.
the class ResourceBundleControl method newBundle.
@Override
public ResourceBundle newBundle(final String baseName, final Locale locale, final String format, final ClassLoader loader, final boolean reload) throws IllegalAccessException, InstantiationException, IOException {
final String bundleName = toBundleName(baseName, locale);
final String resourceName = toResourceName(bundleName, "properties");
ResourceBundle bundle = null;
InputStream stream = null;
if (reload) {
URL url = loader.getResource(resourceName);
if (url != null) {
URLConnection connection = url.openConnection();
if (connection != null) {
connection.setUseCaches(false);
stream = connection.getInputStream();
}
}
} else {
stream = loader.getResourceAsStream(resourceName);
}
if (stream != null) {
try {
bundle = new PropertyResourceBundle(new InputStreamReader(stream, charset));
} finally {
stream.close();
}
}
return bundle;
}
use of java.util.PropertyResourceBundle in project navajo by Dexels.
the class PropertyFileDescriptionProvider method getResourceBundle.
private ResourceBundle getResourceBundle(Navajo in, Access access) throws IOException {
String locale = in.getHeader().getHeaderAttribute("locale");
String sublocale = in.getHeader().getHeaderAttribute("sublocale");
String props = resourceBundle.getResource(null, "description", access.getTenant(), sublocale, locale);
PropertyResourceBundle p = null;
try (InputStream stream = new ByteArrayInputStream(props.getBytes(StandardCharsets.UTF_8))) {
p = new PropertyResourceBundle(new InputStreamReader(stream, Charset.forName("UTF-8")));
}
return p;
}
use of java.util.PropertyResourceBundle in project navajo by Dexels.
the class NavajoServerInstance method getClientSettingsBundle.
public ResourceBundle getClientSettingsBundle() throws IOException {
File props = new File(getConfigRoot(), "client.properties");
if (!props.exists()) {
logger.warn("Not found.");
return null;
}
FileReader fr = null;
try {
fr = new FileReader(props);
PropertyResourceBundle b = new PropertyResourceBundle(fr);
return b;
} finally {
if (fr != null) {
fr.close();
}
}
}
Aggregations