Example usage for java.util ResourceBundle getKeys

List of usage examples for java.util ResourceBundle getKeys

Introduction

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

Prototype

public abstract Enumeration<String> getKeys();

Source Link

Document

Returns an enumeration of the keys.

Usage

From source file:Main.java

public static void main(String[] args) {
    ResourceBundle bundle = ResourceBundle.getBundle("hello", Locale.US);
    Enumeration<String> keys = bundle.getKeys();
    ArrayList<String> temp = new ArrayList<String>();

    for (Enumeration<String> e = keys; keys.hasMoreElements();) {
        String key = e.nextElement();
        if (key.startsWith("java2s")) {
            temp.add(key);/*from w  w w  .jav  a2  s  . c o  m*/
        }
    }

    String[] result = new String[temp.size()];

    for (int i = 0; i < temp.size(); i++) {
        result[i] = bundle.getString(temp.get(i));
    }
    System.out.println(Arrays.toString(result));
}

From source file:MainResourceBundle.java

public static void main(String[] args) {

    // create a new ResourceBundle with specified locale
    ResourceBundle bundle = MainResourceBundle.getBundle("hello", Locale.US);

    // print the keys
    Enumeration<String> enumeration = bundle.getKeys();
    while (enumeration.hasMoreElements()) {
        System.out.println(enumeration.nextElement());
    }// w  ww  .  j a v a 2 s  .  c  o  m

}

From source file:Main.java

public static void main(String[] args) {

    ResourceBundle bundle = ResourceBundle.getBundle("hello", Locale.US);

    System.out.println(bundle.getString("hello"));

    Enumeration<String> enumeration = bundle.getKeys();

    while (enumeration.hasMoreElements()) {
        System.out.println(enumeration.nextElement());
    }//w  w w.  ja v a  2 s .  c o m

}

From source file:Main.java

static Properties convertResourceBundleToProperties(ResourceBundle resource) {
    Properties properties = new Properties();

    Enumeration<String> keys = resource.getKeys();
    while (keys.hasMoreElements()) {
        String key = keys.nextElement();
        properties.put(key, resource.getString(key));
    }/*from ww w . j  a va2  s .c o m*/

    return properties;
}

From source file:Main.java

public static Properties convertResourceBundleToProperties(ResourceBundle resource) {
    Properties properties = new Properties();

    Enumeration<String> keys = resource.getKeys();
    while (keys.hasMoreElements()) {
        String key = keys.nextElement();
        properties.put(key, resource.getString(key));
        //System.out.println("key: '" + key + "' value: '" + properties.get(key) + "'");
    }/*ww  w .  ja va 2 s  .c o  m*/

    return properties;
}

From source file:PropertiesDemo.java

static void iterateKeys(Locale currentLocale) {

    ResourceBundle labels = ResourceBundle.getBundle("LabelsBundle", currentLocale);

    Enumeration bundleKeys = labels.getKeys();

    while (bundleKeys.hasMoreElements()) {
        String key = (String) bundleKeys.nextElement();
        String value = labels.getString(key);
        System.out.println("key = " + key + ", " + "value = " + value);
    }//ww  w. j  a va  2  s .co m

}

From source file:PropertyLoader.java

public static Properties loadProperties(String name, ClassLoader loader) throws Exception {
    if (name.startsWith("/"))
        name = name.substring(1);//  ww  w .j  av a 2 s.co m
    if (name.endsWith(SUFFIX))
        name = name.substring(0, name.length() - SUFFIX.length());
    Properties result = new Properties();
    InputStream in = null;
    if (loader == null)
        loader = ClassLoader.getSystemClassLoader();
    if (LOAD_AS_RESOURCE_BUNDLE) {
        name = name.replace('/', '.');
        ResourceBundle rb = ResourceBundle.getBundle(name, Locale.getDefault(), loader);
        for (Enumeration keys = rb.getKeys(); keys.hasMoreElements();) {
            result.put((String) keys.nextElement(), rb.getString((String) keys.nextElement()));
        }
    } else {
        name = name.replace('.', '/');
        if (!name.endsWith(SUFFIX))
            name = name.concat(SUFFIX);
        in = loader.getResourceAsStream(name);
        if (in != null) {
            result = new Properties();
            result.load(in); // can throw IOException
        }
    }
    in.close();
    return result;
}

From source file:Main.java

public static final List<String> getListFromBundle(ResourceBundle rb, String prefix) {
    String name = null;/* w ww  . j a  v a  2s .  c o  m*/
    List<String> ret = new LinkedList<String>();
    Enumeration<String> names = rb.getKeys();
    while (names.hasMoreElements()) {
        name = names.nextElement();
        if (name != null && name.startsWith(prefix) && isInteger(name.substring(name.length() - 1))) {
            ret.add(rb.getString(name));
        }
    }
    Collections.sort(ret);
    return ret;
}

From source file:com.willwinder.universalgcodesender.i18n.Localization.java

private static int getKeyCount(ResourceBundle b) {
    Enumeration<String> keyEnum = b.getKeys();

    int ret = 0;/*from  www . ja va2 s. co  m*/
    while (keyEnum.hasMoreElements()) {
        keyEnum.nextElement();
        ret++;
    }

    return ret;
}

From source file:py.una.pol.karaku.test.test.ValidationMessagesTest.java

@BeforeClass
public static void before() {

    Locale locale = new Locale("es", "PY");
    ResourceBundle toAdd = ResourceBundle.getBundle("language.validation.karaku", locale);
    Enumeration<String> en = toAdd.getKeys();
    keys = new HashSet<String>();
    while (en.hasMoreElements()) {

        keys.add("{" + en.nextElement() + "}");

    }//from   w ww . j  av  a 2 s  . c  o m

}