Search in sources :

Example 11 with PropertyResourceBundle

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);
    }
}
Also used : InputStream(java.io.InputStream) PropertyResourceBundle(java.util.PropertyResourceBundle)

Example 12 with PropertyResourceBundle

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);
            }
        }
    }
}
Also used : TemplatePersistenceData(org.eclipse.jface.text.templates.persistence.TemplatePersistenceData) ResourceBundle(java.util.ResourceBundle) Bundle(org.osgi.framework.Bundle) PropertyResourceBundle(java.util.PropertyResourceBundle) ResourceBundle(java.util.ResourceBundle) PropertyResourceBundle(java.util.PropertyResourceBundle) TemplateReaderWriter(org.eclipse.jface.text.templates.persistence.TemplateReaderWriter) URL(java.net.URL) PropertyResourceBundle(java.util.PropertyResourceBundle)

Example 13 with PropertyResourceBundle

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;
}
Also used : InputStreamReader(java.io.InputStreamReader) InputStream(java.io.InputStream) ResourceBundle(java.util.ResourceBundle) PropertyResourceBundle(java.util.PropertyResourceBundle) URL(java.net.URL) URLConnection(java.net.URLConnection) PropertyResourceBundle(java.util.PropertyResourceBundle)

Example 14 with PropertyResourceBundle

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;
}
Also used : PropertyResourceBundle(java.util.PropertyResourceBundle) Nullable(org.jetbrains.annotations.Nullable)

Example 15 with PropertyResourceBundle

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);
}
Also used : InputStream(java.io.InputStream) 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