use of java.util.PropertyResourceBundle in project killbill by killbill.
the class DefaultCatalogTranslationTest method getBundle.
private ResourceBundle getBundle(final Locale locale) throws IOException, URISyntaxException {
final String propertiesFileNameWithCountry = "org/killbill/billing/util/template/translation/CatalogTranslation" + "_" + locale.getLanguage() + "_" + locale.getCountry() + ".properties";
final InputStream inputStream = UriAccessor.accessUri(propertiesFileNameWithCountry);
if (inputStream == null) {
return null;
} else {
return new PropertyResourceBundle(inputStream);
}
}
use of java.util.PropertyResourceBundle in project dbeaver by serge-rider.
the class SQLTemplateStore method readIncludedTemplates.
private void readIncludedTemplates(String contributorId, Collection<TemplatePersistenceData> templates, String file, String translations) throws IOException {
if (file != null) {
Bundle plugin = Platform.getBundle(contributorId);
URL url = FileLocator.find(plugin, Path.fromOSString(file), null);
if (url != null) {
ResourceBundle bundle = null;
if (translations != null) {
URL bundleURL = FileLocator.find(plugin, Path.fromOSString(translations), null);
if (bundleURL != null) {
InputStream bundleStream = bundleURL.openStream();
try {
bundle = new PropertyResourceBundle(bundleStream);
} finally {
ContentUtils.close(bundleStream);
}
}
}
InputStream stream = new BufferedInputStream(url.openStream());
try {
TemplateReaderWriter reader = new TemplateReaderWriter();
TemplatePersistenceData[] datas = reader.read(stream, bundle);
for (TemplatePersistenceData data : datas) {
if (data.isCustom()) {
if (data.getId() == null)
log.error("No template id specified");
else
log.error("Template " + data.getTemplate().getName() + " deleted");
} else if (validateTemplate(data.getTemplate())) {
templates.add(data);
}
}
} finally {
ContentUtils.close(stream);
}
}
}
}
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 intellij-community by JetBrains.
the class ConfigImportHelper method getPropertyFromLaxFile.
@Nullable
private static String getPropertyFromLaxFile(@NotNull File file, @NotNull String propertyName) {
if (file.getName().endsWith(".properties")) {
try {
PropertyResourceBundle bundle;
InputStream fis = new BufferedInputStream(new FileInputStream(file));
try {
bundle = new PropertyResourceBundle(fis);
} finally {
fis.close();
}
if (bundle.containsKey(propertyName)) {
return bundle.getString(propertyName);
}
return null;
} catch (IOException e) {
return null;
}
}
final String fileContent = getContent(file);
// try to find custom config path
final String propertyValue = findProperty(propertyName, fileContent);
if (!StringUtil.isEmpty(propertyValue)) {
return propertyValue;
}
return null;
}
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);
}
Aggregations