use of java.util.PropertyResourceBundle in project che by eclipse.
the class ContributionTemplateStore method readIncludedTemplates.
private void readIncludedTemplates(Collection templates, /*, IConfigurationElement element*/
String file) 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);
URL url = ContributionTemplateStore.class.getResource(file);
if (url != null) {
ResourceBundle bundle = null;
InputStream bundleStream = null;
InputStream stream = null;
try {
// String translations= element.getAttribute(TRANSLATIONS);
// if (translations != null) {
//file.substring(0, file.lastIndexOf('.'));
String props = "/org/eclipse/templates/default-templates.properties";
URL bundleURL = ContributionTemplateStore.class.getResource(props);
if (bundleURL != null) {
bundleStream = bundleURL.openStream();
bundle = new PropertyResourceBundle(bundleStream);
}
// }
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)
JavaPlugin.logErrorMessage("Ignoring template ''" + data.getTemplate().getName() + "'' since it has no id.");
else
JavaPlugin.logErrorMessage("Ignoring template ''" + data.getTemplate().getName() + "'' since it is deleted.");
} else if (validateTemplate(data.getTemplate())) {
templates.add(data);
}
}
} finally {
try {
if (bundleStream != null)
bundleStream.close();
} catch (IOException x) {
} finally {
try {
if (stream != null)
stream.close();
} catch (IOException x) {
}
}
}
}
}
}
use of java.util.PropertyResourceBundle in project commons-gdx by gemserk.
the class ResourceBundleResourceBuilder method build.
@Override
public ResourceBundle build() {
if (bundlesCache == null) {
if (rootFileHandle == null)
throw new RuntimeException("file handle for root ResourceBundle should be specified");
bundlesCache = new HashMap<Locale, ResourceBundle>();
try {
rootResourceBundle = new PropertyResourceBundle(rootFileHandle.read());
} catch (IOException e) {
throw new RuntimeException("failed to create root ResourceBundle from " + rootFileHandle.name(), e);
}
Set<Locale> locales = fileHandles.keySet();
for (Locale locale : locales) {
FileHandle fileHandle = fileHandles.get(locale);
if (equalsFileHandle(fileHandle, rootFileHandle)) {
bundlesCache.put(locale, rootResourceBundle);
continue;
}
try {
ResourceBundle resourceBundle = new PropertyResourceBundleWithParent(fileHandle.read(), rootResourceBundle);
bundlesCache.put(locale, resourceBundle);
} catch (IOException e) {
throw new RuntimeException("failed to create ResourceBundle from " + fileHandle.name(), e);
}
}
}
Locale currentLocale = Locale.getDefault();
ResourceBundle resourceBundle = bundlesCache.get(currentLocale);
if (resourceBundle == null)
return rootResourceBundle;
return resourceBundle;
}
use of java.util.PropertyResourceBundle in project translationstudio8 by heartsome.
the class JavaPropertiesViewerDialog method openFile.
/**
* 打开文件
*/
private void openFile() {
FileDialog fd = new FileDialog(getShell(), SWT.OPEN);
String[] extensions = { "*.properties", "*.*" };
String[] names = { Messages.getString("dialog.JavaPropertiesViewerDialog.names1"), Messages.getString("dialog.JavaPropertiesViewerDialog.names2") };
fd.setFilterNames(names);
fd.setFilterExtensions(extensions);
String fileLocation = fd.open();
if (fileLocation == null) {
return;
}
PropertyResourceBundle bundle;
try {
bundle = new PropertyResourceBundle(new FileInputStream(fileLocation));
Vector<String> vector = getKeys(fileLocation);
Iterator<String> keys = vector.iterator();
List<String[]> data = new LinkedList<String[]>();
while (keys.hasNext()) {
String key = keys.next();
String value = bundle.getString(key);
data.add(new String[] { key, value });
}
tableViewer.setInput(data);
} catch (Exception e) {
LOGGER.error("", e);
}
}
use of java.util.PropertyResourceBundle in project jersey by jersey.
the class OsgiRegistry method getResourceBundle.
/**
* Tries to load resource bundle via OSGi means. No caching involved here,
* as localization properties are being cached in Localizer class already.
*
* @param bundleName name of the resource bundle to load
* @return resource bundle instance if found, null otherwise
*/
public ResourceBundle getResourceBundle(final String bundleName) {
final int lastDotIndex = bundleName.lastIndexOf('.');
final String path = bundleName.substring(0, lastDotIndex).replace('.', '/');
final String propertiesName = bundleName.substring(lastDotIndex + 1, bundleName.length()) + ".properties";
for (final Bundle bundle : bundleContext.getBundles()) {
final Enumeration<URL> entries = findEntries(bundle, path, propertiesName, false);
if (entries != null && entries.hasMoreElements()) {
final URL entryUrl = entries.nextElement();
try {
return new PropertyResourceBundle(entryUrl.openStream());
} catch (final IOException ex) {
if (LOGGER.isLoggable(Level.FINE)) {
// does not make sense to localize this
LOGGER.fine("Exception caught when tried to load resource bundle in OSGi");
}
return null;
}
}
}
return null;
}
use of java.util.PropertyResourceBundle in project killbill by killbill.
the class InvoiceResource method uploadTemplateResource.
private Response uploadTemplateResource(final String templateResource, @Nullable final String localeStr, final boolean deleteIfExists, final TenantKey tenantKey, final String getMethodStr, final String createdBy, final String reason, final String comment, final HttpServletRequest request, final UriInfo uriInfo) throws Exception {
final String tenantKeyStr;
if (localeStr != null) {
// Validation purpose: Will throw bad stream
final InputStream stream = new ByteArrayInputStream(templateResource.getBytes());
new PropertyResourceBundle(stream);
final Locale locale = localeStr != null ? LocaleUtils.toLocale(localeStr) : defaultLocale;
tenantKeyStr = LocaleUtils.localeString(locale, tenantKey.toString());
} else {
tenantKeyStr = tenantKey.toString();
}
final CallContext callContext = context.createContext(createdBy, reason, comment, request);
if (!tenantApi.getTenantValuesForKey(tenantKeyStr, callContext).isEmpty()) {
if (deleteIfExists) {
tenantApi.deleteTenantKey(tenantKeyStr, callContext);
} else {
return Response.status(Status.BAD_REQUEST).build();
}
}
tenantApi.addTenantKeyValue(tenantKeyStr, templateResource, callContext);
return uriBuilder.buildResponse(uriInfo, InvoiceResource.class, getMethodStr, localeStr, request);
}
Aggregations