Search in sources :

Example 6 with PropertyResourceBundle

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) {
                    }
                }
            }
        }
    }
}
Also used : TemplatePersistenceData(org.eclipse.che.jface.text.templates.persistence.TemplatePersistenceData) BufferedInputStream(java.io.BufferedInputStream) BufferedInputStream(java.io.BufferedInputStream) InputStream(java.io.InputStream) PropertyResourceBundle(java.util.PropertyResourceBundle) ResourceBundle(java.util.ResourceBundle) TemplateReaderWriter(org.eclipse.che.jface.text.templates.persistence.TemplateReaderWriter) IOException(java.io.IOException) URL(java.net.URL) PropertyResourceBundle(java.util.PropertyResourceBundle)

Example 7 with PropertyResourceBundle

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;
}
Also used : Locale(java.util.Locale) FileHandle(com.badlogic.gdx.files.FileHandle) ResourceBundle(java.util.ResourceBundle) PropertyResourceBundle(java.util.PropertyResourceBundle) IOException(java.io.IOException) PropertyResourceBundle(java.util.PropertyResourceBundle)

Example 8 with PropertyResourceBundle

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);
    }
}
Also used : FileDialog(org.eclipse.swt.widgets.FileDialog) FileInputStream(java.io.FileInputStream) LinkedList(java.util.LinkedList) IOException(java.io.IOException) PropertyResourceBundle(java.util.PropertyResourceBundle)

Example 9 with PropertyResourceBundle

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;
}
Also used : ResourceBundle(java.util.ResourceBundle) Bundle(org.osgi.framework.Bundle) PropertyResourceBundle(java.util.PropertyResourceBundle) IOException(java.io.IOException) URL(java.net.URL) PropertyResourceBundle(java.util.PropertyResourceBundle)

Example 10 with PropertyResourceBundle

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);
}
Also used : Locale(java.util.Locale) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) CallContext(org.killbill.billing.util.callcontext.CallContext) PropertyResourceBundle(java.util.PropertyResourceBundle)

Aggregations

PropertyResourceBundle (java.util.PropertyResourceBundle)18 ResourceBundle (java.util.ResourceBundle)10 InputStream (java.io.InputStream)9 URL (java.net.URL)8 IOException (java.io.IOException)6 InputStreamReader (java.io.InputStreamReader)5 URLConnection (java.net.URLConnection)4 Locale (java.util.Locale)4 MissingResourceException (java.util.MissingResourceException)3 FileInputStream (java.io.FileInputStream)2 Bundle (org.osgi.framework.Bundle)2 FileHandle (com.badlogic.gdx.files.FileHandle)1 PrinterJob (java.awt.print.PrinterJob)1 BufferedInputStream (java.io.BufferedInputStream)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 File (java.io.File)1 Reader (java.io.Reader)1 MalformedURLException (java.net.MalformedURLException)1 Connection (java.sql.Connection)1 SQLException (java.sql.SQLException)1