use of java.util.PropertyResourceBundle in project jdk8u_jdk by JetBrains.
the class I18NImpl method getString.
/**
* Returns the message string with the specified key from the
* "properties" file in the package containing the class with
* the specified name.
*/
protected static final String getString(String className, String resource_name, String key) {
PropertyResourceBundle bundle = null;
try {
InputStream stream = Class.forName(className).getResourceAsStream(resource_name);
bundle = new PropertyResourceBundle(stream);
} catch (Throwable e) {
// Chain the exception.
throw new RuntimeException(e);
}
return (String) bundle.handleGetObject(key);
}
use of java.util.PropertyResourceBundle in project pentaho-kettle by pentaho.
the class GlobalMessages method getBundle.
public static ResourceBundle getBundle(Locale locale, String packageName, Class<?> resourceClass) throws MissingResourceException {
String filename = buildHashKey(locale, packageName);
filename = "/" + filename.replace('.', '/') + ".properties";
InputStream inputStream = null;
try {
ResourceBundle bundle = locales.get(filename);
if (bundle == null) {
inputStream = resourceClass.getResourceAsStream(filename);
if (inputStream == null) {
// Retry with the system class loader, just in case we are dealing with a messy plug-in.
//
inputStream = ClassLoader.getSystemResourceAsStream(filename);
}
//
if (inputStream != null) {
bundle = new PropertyResourceBundle(new InputStreamReader(inputStream, "UTF-8"));
locales.put(filename, bundle);
} else {
throw new MissingResourceException("Unable to find properties file [" + filename + "]", locale.toString(), packageName);
}
}
return bundle;
} catch (IOException e) {
throw new MissingResourceException("Unable to find properties file [" + filename + "] : " + e.toString(), locale.toString(), packageName);
} finally {
if (inputStream != null) {
try {
inputStream.close();
} catch (Exception e) {
// ignore this
}
}
}
}
use of java.util.PropertyResourceBundle in project eclipse.platform.text by eclipse.
the class ContributionTemplateStore method readIncludedTemplates.
private void readIncludedTemplates(Collection<TemplatePersistenceData> templates, IConfigurationElement element) throws IOException {
String file = element.getAttribute(FILE);
if (file != null) {
Bundle plugin = Platform.getBundle(element.getContributor().getName());
URL url = FileLocator.find(plugin, Path.fromOSString(file), null);
if (url != null) {
ResourceBundle bundle = null;
String translations = element.getAttribute(TRANSLATIONS);
if (translations != null) {
URL bundleURL = FileLocator.find(plugin, Path.fromOSString(translations), null);
if (bundleURL != null) {
try (InputStream bundleStream = bundleURL.openStream()) {
bundle = new PropertyResourceBundle(bundleStream);
}
}
}
try (InputStream stream = new BufferedInputStream(url.openStream())) {
TemplateReaderWriter reader = new TemplateReaderWriter();
TemplatePersistenceData[] datas = reader.read(stream, bundle);
for (int i = 0; i < datas.length; i++) {
TemplatePersistenceData data = datas[i];
if (data.isCustom()) {
if (data.getId() == null)
EditorsPlugin.logErrorMessage(NLSUtility.format(ContributionTemplateMessages.ContributionTemplateStore_ignore_no_id, data.getTemplate().getName()));
else
EditorsPlugin.logErrorMessage(NLSUtility.format(ContributionTemplateMessages.ContributionTemplateStore_ignore_deleted, data.getTemplate().getName()));
} else if (validateTemplate(data.getTemplate())) {
templates.add(data);
}
}
}
}
}
}
use of java.util.PropertyResourceBundle in project ORCID-Source by ORCID.
the class UTF8Control method newBundle.
public ResourceBundle newBundle(String baseName, Locale locale, String format, ClassLoader loader, boolean reload) throws IllegalAccessException, InstantiationException, IOException {
// The below is a copy of the default implementation.
String bundleName = toBundleName(baseName, locale);
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 {
// 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 TranskribusCore by Transkribus.
the class UTF8Control method newBundle.
public ResourceBundle newBundle(String baseName, Locale locale, String format, ClassLoader loader, boolean reload) throws IllegalAccessException, InstantiationException, IOException {
// The below is a copy of the default implementation.
String bundleName = toBundleName(baseName, locale);
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 {
// 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;
}
Aggregations