Example usage for java.util PropertyResourceBundle getKeys

List of usage examples for java.util PropertyResourceBundle getKeys

Introduction

In this page you can find the example usage for java.util PropertyResourceBundle getKeys.

Prototype

public Enumeration<String> getKeys() 

Source Link

Document

Returns an Enumeration of the keys contained in this ResourceBundle and its parent bundles.

Usage

From source file:Main.java

public static void main(String[] args) throws Exception {
    // Prepare content for simulating property files
    String fileContent = "s1=1\n" + "s2=Main\n" + "s3=Fri Jan 31";
    InputStream propStream = new StringBufferInputStream(fileContent);

    PropertyResourceBundle bundle = new PropertyResourceBundle(propStream);

    // Get resource keys
    Enumeration keys = bundle.getKeys();
    while (keys.hasMoreElements()) {
        System.out.println("Bundle key: " + keys.nextElement());
    }/*w  ww  .j  ava  2 s.c  om*/
}

From source file:com.chilmers.configbootstrapper.ConfigServletContextListener.java

/**
 * Loads system properties from the application configuration
 *  /*from  ww w .ja  v a  2s.com*/
 * @param configBundle The application configuration
 */
protected void loadApplicationConfigurationSystemProperties(PropertyResourceBundle configBundle) {
    logToSystemOut("Checking for system properties in application configuration");
    Enumeration<String> keys = configBundle.getKeys();

    while (keys.hasMoreElements()) {

        String key = keys.nextElement();

        if (key.startsWith(CONFIG_SYSTEM_PROPERTY_PREFIX)) {
            String systemPropertyKey = key.substring(CONFIG_SYSTEM_PROPERTY_PREFIX.length());

            if (systemPropertyKey.length() > 0) {
                setSystemProperty(systemPropertyKey, configBundle.getString(key));
            }
        }
    }
}

From source file:no.kantega.commons.util.LocaleLabels.java

public static Enumeration getKeys(String bundleName, Locale locale) {
    String loc = locale.getLanguage() + "_" + locale.getCountry();
    if (isNotBlank(locale.getVariant())) {
        loc += "_" + locale.getVariant();
    }/*from w ww  . jav  a  2 s . co m*/

    PropertyResourceBundle bundle = getBundle(bundleName, loc);
    if (bundle == null) {
        return null;
    }
    return bundle.getKeys();
}

From source file:org.eclipse.birt.report.utility.ParameterAccessor.java

/**
 * Returns the application properties/*  www  . ja  v  a  2s  .  co m*/
 * 
 * @param context
 * @param props
 * @return
 */
public synchronized static Map initViewerProps(ServletContext context, Map props) {
    // initialize map
    if (props == null)
        props = new HashMap();

    // get config file
    String file = context.getInitParameter(INIT_PARAM_CONFIG_FILE);
    if (file == null || file.trim().length() <= 0)
        file = IBirtConstants.DEFAULT_VIEWER_CONFIG_FILE;

    try {

        InputStream is = null;
        if (isRelativePath(file)) {
            // realtive path
            if (!file.startsWith("/")) //$NON-NLS-1$
                file = "/" + file; //$NON-NLS-1$

            is = context.getResourceAsStream(file);
        } else {
            // absolute path
            is = new FileInputStream(file);
        }

        // parse the properties file
        PropertyResourceBundle bundle = new PropertyResourceBundle(is);
        if (bundle != null) {
            Enumeration<String> keys = bundle.getKeys();
            while (keys != null && keys.hasMoreElements()) {
                String key = keys.nextElement();
                String value = (String) bundle.getObject(key);
                if (key != null && value != null)
                    props.put(key, value);
            }
        }
    } catch (Exception e) {
    }

    return props;
}

From source file:org.pentaho.platform.plugin.services.importer.LocaleFilesProcessor.java

public Properties loadProperties(InputStream inputStream) throws IOException {
    assert inputStream != null;
    final Properties properties = new Properties();
    final PropertyResourceBundle rb = new PropertyResourceBundle(inputStream);
    final Enumeration<?> keyEnum = rb.getKeys();
    while (keyEnum.hasMoreElements()) {
        final Object key = keyEnum.nextElement();
        assert key != null;
        final String sKey = String.valueOf(key);
        properties.put(sKey, rb.getObject(sKey));
    }/*  www.  j  a v a  2s .  c o m*/
    return properties;
}