Search in sources :

Example 66 with PropertyResourceBundle

use of java.util.PropertyResourceBundle in project collect by openforis.

the class ResourceBundleMessageSource method getMessage.

@Override
public String getMessage(Locale locale, String code, Object... args) {
    List<PropertyResourceBundle> resourceBundles = getBundles(locale);
    if (resourceBundles == null || resourceBundles.isEmpty()) {
        return null;
    } else {
        for (PropertyResourceBundle resourceBundle : resourceBundles) {
            if (resourceBundle.containsKey(code)) {
                try {
                    String messageKey = resourceBundle.getString(code);
                    String result = MessageFormat.format(messageKey, args);
                    return result;
                } catch (Exception e) {
                // resource not found
                }
            }
        }
        return null;
    }
}
Also used : PropertyResourceBundle(java.util.PropertyResourceBundle)

Example 67 with PropertyResourceBundle

use of java.util.PropertyResourceBundle in project bisq-core by bisq-network.

the class UTF8Control method newBundle.

public ResourceBundle newBundle(String baseName, @NotNull Locale locale, @NotNull String format, ClassLoader loader, boolean reload) throws IllegalAccessException, InstantiationException, IOException {
    // The below is a copy of the default implementation.
    final String bundleName = toBundleName(baseName, locale);
    final String resourceName = toResourceName(bundleName, "properties");
    ResourceBundle bundle = null;
    InputStream stream = null;
    if (reload) {
        final URL url = loader.getResource(resourceName);
        if (url != null) {
            final 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) PropertyResourceBundle(java.util.PropertyResourceBundle) ResourceBundle(java.util.ResourceBundle) URL(java.net.URL) URLConnection(java.net.URLConnection) PropertyResourceBundle(java.util.PropertyResourceBundle)

Example 68 with PropertyResourceBundle

use of java.util.PropertyResourceBundle in project springboot-javafx-support by roskenet.

the class ResourceBundleControl method newBundle.

@Override
public ResourceBundle newBundle(final String baseName, final Locale locale, final String format, final ClassLoader loader, final boolean reload) throws IllegalAccessException, InstantiationException, IOException {
    final String bundleName = toBundleName(baseName, locale);
    final 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 {
            bundle = new PropertyResourceBundle(new InputStreamReader(stream, charset));
        } 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 69 with PropertyResourceBundle

use of java.util.PropertyResourceBundle in project navajo by Dexels.

the class PropertyFileDescriptionProvider method getResourceBundle.

private ResourceBundle getResourceBundle(Navajo in, Access access) throws IOException {
    String locale = in.getHeader().getHeaderAttribute("locale");
    String sublocale = in.getHeader().getHeaderAttribute("sublocale");
    String props = resourceBundle.getResource(null, "description", access.getTenant(), sublocale, locale);
    PropertyResourceBundle p = null;
    try (InputStream stream = new ByteArrayInputStream(props.getBytes(StandardCharsets.UTF_8))) {
        p = new PropertyResourceBundle(new InputStreamReader(stream, Charset.forName("UTF-8")));
    }
    return p;
}
Also used : InputStreamReader(java.io.InputStreamReader) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) PropertyResourceBundle(java.util.PropertyResourceBundle)

Example 70 with PropertyResourceBundle

use of java.util.PropertyResourceBundle in project navajo by Dexels.

the class NavajoServerInstance method getClientSettingsBundle.

public ResourceBundle getClientSettingsBundle() throws IOException {
    File props = new File(getConfigRoot(), "client.properties");
    if (!props.exists()) {
        logger.warn("Not found.");
        return null;
    }
    FileReader fr = null;
    try {
        fr = new FileReader(props);
        PropertyResourceBundle b = new PropertyResourceBundle(fr);
        return b;
    } finally {
        if (fr != null) {
            fr.close();
        }
    }
}
Also used : FileReader(java.io.FileReader) File(java.io.File) PropertyResourceBundle(java.util.PropertyResourceBundle)

Aggregations

PropertyResourceBundle (java.util.PropertyResourceBundle)71 InputStream (java.io.InputStream)35 ResourceBundle (java.util.ResourceBundle)33 IOException (java.io.IOException)30 URL (java.net.URL)24 InputStreamReader (java.io.InputStreamReader)23 FileInputStream (java.io.FileInputStream)15 URLConnection (java.net.URLConnection)14 MissingResourceException (java.util.MissingResourceException)13 File (java.io.File)12 FileNotFoundException (java.io.FileNotFoundException)8 Locale (java.util.Locale)7 ByteArrayInputStream (java.io.ByteArrayInputStream)5 HashMap (java.util.HashMap)5 MalformedURLException (java.net.MalformedURLException)4 Bundle (org.osgi.framework.Bundle)4 ArrayList (java.util.ArrayList)3 Properties (java.util.Properties)3 TemplatePersistenceData (org.eclipse.jface.text.templates.persistence.TemplatePersistenceData)3 TemplateReaderWriter (org.eclipse.jface.text.templates.persistence.TemplateReaderWriter)3