Java Code Examples for java.util.ResourceBundle#getKeys()

The following examples show how to use java.util.ResourceBundle#getKeys() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ExtensionTipsAndTricks.java    From zap-extensions with Apache License 2.0 6 votes vote down vote up
private List<String> getTipsAndTricks() {
    if (tipsAndTricks == null) {
        // Need to load them in
        tipsAndTricks = new ArrayList<String>();

        ResourceBundle rb = Constant.messages.getMessageBundle(PREFIX);
        Enumeration<String> enm = rb.getKeys();
        while (enm.hasMoreElements()) {
            String key = enm.nextElement();
            if (key.startsWith(TIPS_PREFIX)) {
                tipsAndTricks.add(/*Constant.messages.getString(key)*/ rb.getString(key));
            }
        }

        if (tipsAndTricks.size() == 0) {
            this.getMenuTipsAndTricks().setEnabled(false);
        }
    }
    return this.tipsAndTricks;
}
 
Example 2
Source File: I18N.java    From document-management-software with GNU Lesser General Public License v3.0 6 votes vote down vote up
public static Map<String, String> getMessages(Locale locale) {
	Map<String, String> map = new HashMap<String, String>();

	for (String b : bundles) {
		try {
			ResourceBundle bundle = ResourceBundle.getBundle(b, locale);
			Enumeration<String> keys = bundle.getKeys();
			while (keys.hasMoreElements()) {
				String key = keys.nextElement();
				if (!bundle.containsKey(key))
					continue;
				String val = bundle.getString(key);
				if (val != null && !val.isEmpty())
					map.put(key, bundle.getString(key));
			}
		} catch (Throwable t) {
		}
	}
	return map;
}
 
Example 3
Source File: LocalizedFormatsTest.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
@Test
public void testAllPropertiesCorrespondToKeys() {
    final String path = LocalizedFormats.class.getName().replaceAll("\\.", "/");
    for (final String language : new String[] { "fr" } ) {
        ResourceBundle bundle =
            ResourceBundle.getBundle("assets/" + path, new Locale(language));
        for (final Enumeration<String> keys = bundle.getKeys(); keys.hasMoreElements();) {
            final String propertyKey = keys.nextElement();
            try {
                Assert.assertNotNull(LocalizedFormats.valueOf(propertyKey));
            } catch (IllegalArgumentException iae) {
                Assert.fail("unknown key \"" + propertyKey + "\" in language " + language);
            }
        }
        Assert.assertEquals(language, bundle.getLocale().getLanguage());
    }

}
 
Example 4
Source File: Bug4640234.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
private static Map<String, String> getList(
        ResourceBundle rs, Boolean getCountryList) {
    char beginChar = 'a';
    char endChar = 'z';
    if (getCountryList) {
        beginChar = 'A';
        endChar = 'Z';
    }

    Map<String, String> hm = new HashMap<String, String>();
    Enumeration<String> keys = rs.getKeys();
    while (keys.hasMoreElements()) {
        String s = keys.nextElement();
        if (s.length() == 2 &&
            s.charAt(0) >= beginChar && s.charAt(0) <= endChar) {
            hm.put(s, rs.getString(s));
        }
    }
    return hm;
}
 
Example 5
Source File: LocalizedFormatsAbstractTest.java    From hipparchus with Apache License 2.0 6 votes vote down vote up
@Test
public void testAllKeysPresentInPropertiesFiles() {
    Class<? extends Enum<?>> c = getFormatsClass();
    final String path = c.getName().replaceAll("\\.", "/");
    for (final String language : new String[] { "fr" } ) {
        ResourceBundle bundle =
            ResourceBundle.getBundle("assets/" + path, new Locale(language), c.getClassLoader());
        for (Localizable message : getValues()) {
            final String messageKey = message.toString();
            boolean keyPresent = false;
            for (final Enumeration<String> keys = bundle.getKeys(); keys.hasMoreElements();) {
                keyPresent |= messageKey.equals(keys.nextElement());
            }
            Assert.assertTrue("missing key \"" + message.toString() + "\" for language " + language,
                              keyPresent);
        }
        Assert.assertEquals(language, bundle.getLocale().getLanguage());
    }

}
 
Example 6
Source File: Main.java    From Vert.X-generator with MIT License 5 votes vote down vote up
/**
 * 根据Locale加载控件文本
 * 
 * @param locale
 */
public static void loadLanguage(Locale locale) {
	ResourceBundle resourceBundle = ResourceBundle.getBundle("config/language/language", locale);
	Enumeration<String> keys = resourceBundle.getKeys();
	while (keys.hasMoreElements()) {
		String key = keys.nextElement();
		if (LANGUAGE.get(key) == null) {
			LANGUAGE.put(key, new SimpleStringProperty(resourceBundle.getString(key)));
		} else {
			LANGUAGE.get(key).set(resourceBundle.getString(key));
		}
	}
}
 
Example 7
Source File: JSONObject.java    From nettythrift with Apache License 2.0 5 votes vote down vote up
/**
 * Construct a JSONObject from a ResourceBundle.
 *
 * @param baseName
 *            The ResourceBundle base name.
 * @param locale
 *            The Locale to load the ResourceBundle for.
 * @throws JSONException
 *             If any JSONExceptions are detected.
 */
public JSONObject(String baseName, Locale locale) throws JSONException {
	this();
	ResourceBundle bundle = ResourceBundle.getBundle(baseName, locale,
			Thread.currentThread().getContextClassLoader());

	// Iterate through the keys in the bundle.

	Enumeration<String> keys = bundle.getKeys();
	while (keys.hasMoreElements()) {
		Object key = keys.nextElement();
		if (key != null) {

			// Go through the path, ensuring that there is a nested
			// JSONObject for each
			// segment except the last. Add the value using the last
			// segment's name into
			// the deepest nested JSONObject.

			String[] path = ((String) key).split("\\.");
			int last = path.length - 1;
			JSONObject target = this;
			for (int i = 0; i < last; i += 1) {
				String segment = path[i];
				JSONObject nextTarget = target.optJSONObject(segment);
				if (nextTarget == null) {
					nextTarget = new JSONObject();
					target.put(segment, nextTarget);
				}
				target = nextTarget;
			}
			target.put(path[last], bundle.getString((String) key));
		}
	}
}
 
Example 8
Source File: GenerateKeyList.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public static void dumpResourceBundle(String pathName, ResourceBundle bundle,
                PrintStream out) throws Exception {
    Enumeration keys = bundle.getKeys();
    while(keys.hasMoreElements()) {
        String key = (String)(keys.nextElement());
        dumpResource(pathName + "/" + key, bundle.getObject(key), out);
    }
}
 
Example 9
Source File: OpenListResourceBundle.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Implementation of ResourceBundle.getKeys.
 */
@Override
public Enumeration<String> getKeys() {
    ResourceBundle parentBundle = this.parent;
    return new ResourceBundleEnumeration(handleKeySet(),
            (parentBundle != null) ? parentBundle.getKeys() : null);
 }
 
Example 10
Source File: GenerateKeyList.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
public static void dumpResourceBundle(String pathName, ResourceBundle bundle,
                PrintStream out) throws Exception {
    Enumeration keys = bundle.getKeys();
    while(keys.hasMoreElements()) {
        String key = (String)(keys.nextElement());
        dumpResource(pathName + "/" + key, bundle.getObject(key), out);
    }
}
 
Example 11
Source File: UIDefaults.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns a Map of the known resources for the given locale.
 */
private Map<String, Object> getResourceCache(Locale l) {
    Map<String, Object> values = resourceCache.get(l);

    if (values == null) {
        values = new TextAndMnemonicHashMap();
        for (int i=resourceBundles.size()-1; i >= 0; i--) {
            String bundleName = resourceBundles.get(i);
            try {
                Control c = CoreResourceBundleControl.getRBControlInstance(bundleName);
                ResourceBundle b;
                if (c != null) {
                    b = ResourceBundle.getBundle(bundleName, l, c);
                } else {
                    b = ResourceBundle.getBundle(bundleName, l);
                }
                Enumeration keys = b.getKeys();

                while (keys.hasMoreElements()) {
                    String key = (String)keys.nextElement();

                    if (values.get(key) == null) {
                        Object value = b.getObject(key);

                        values.put(key, value);
                    }
                }
            } catch( MissingResourceException mre ) {
                // Keep looking
            }
        }
        resourceCache.put(l, values);
    }
    return values;
}
 
Example 12
Source File: JSONObject.java    From JMCCC with MIT License 5 votes vote down vote up
/**
 * Construct a JSONObject from a ResourceBundle.
 *
 * @param baseName The ResourceBundle base name.
 * @param locale The Locale to load the ResourceBundle for.
 * @throws JSONException If any JSONExceptions are detected.
 */
public JSONObject(String baseName, Locale locale) throws JSONException {
	this();
	ResourceBundle bundle = ResourceBundle.getBundle(baseName, locale,
			Thread.currentThread().getContextClassLoader());

	// Iterate through the keys in the bundle.

	Enumeration<String> keys = bundle.getKeys();
	while (keys.hasMoreElements()) {
		Object key = keys.nextElement();
		if (key != null) {

			// Go through the path, ensuring that there is a nested JSONObject for each
			// segment except the last. Add the value using the last segment's name into
			// the deepest nested JSONObject.

			String[] path = ((String) key).split("\\.");
			int last = path.length - 1;
			JSONObject target = this;
			for (int i = 0; i < last; i += 1) {
				String segment = path[i];
				JSONObject nextTarget = target.optJSONObject(segment);
				if (nextTarget == null) {
					nextTarget = new JSONObject();
					target.put(segment, nextTarget);
				}
				target = nextTarget;
			}
			target.put(path[last], bundle.getString((String) key));
		}
	}
}
 
Example 13
Source File: OpenListResourceBundle.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Implementation of ResourceBundle.getKeys.
 */
@Override
public Enumeration<String> getKeys() {
    ResourceBundle parentBundle = this.parent;
    return new ResourceBundleEnumeration(handleKeySet(),
            (parentBundle != null) ? parentBundle.getKeys() : null);
 }
 
Example 14
Source File: UIDefaults.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns a Map of the known resources for the given locale.
 */
private Map<String, Object> getResourceCache(Locale l) {
    Map<String, Object> values = resourceCache.get(l);

    if (values == null) {
        values = new TextAndMnemonicHashMap();
        for (int i=resourceBundles.size()-1; i >= 0; i--) {
            String bundleName = resourceBundles.get(i);
            try {
                ResourceBundle b;
                if (isDesktopResourceBundle(bundleName)) {
                    // load resource bundle from java.desktop module
                    b = ResourceBundle.getBundle(bundleName, l, UIDefaults.class.getModule());
                } else {
                    b = ResourceBundle.getBundle(bundleName, l, ClassLoader.getSystemClassLoader());
                }
                Enumeration<String> keys = b.getKeys();

                while (keys.hasMoreElements()) {
                    String key = keys.nextElement();

                    if (values.get(key) == null) {
                        Object value = b.getObject(key);

                        values.put(key, value);
                    }
                }
            } catch( MissingResourceException mre ) {
                // Keep looking
            }
        }
        resourceCache.put(l, values);
    }
    return values;
}
 
Example 15
Source File: JSONObject.java    From browserprint with MIT License 5 votes vote down vote up
/**
     * Construct a JSONObject from a ResourceBundle.
     *
     * @param baseName
     *            The ResourceBundle base name.
     * @param locale
     *            The Locale to load the ResourceBundle for.
     * @throws JSONException
     *             If any JSONExceptions are detected.
     */
    public JSONObject(String baseName, Locale locale) throws JSONException {
        this();
        ResourceBundle bundle = ResourceBundle.getBundle(baseName, locale,
                Thread.currentThread().getContextClassLoader());

// Iterate through the keys in the bundle.

        Enumeration<String> keys = bundle.getKeys();
        while (keys.hasMoreElements()) {
            Object key = keys.nextElement();
            if (key != null) {

// Go through the path, ensuring that there is a nested JSONObject for each
// segment except the last. Add the value using the last segment's name into
// the deepest nested JSONObject.

                String[] path = ((String) key).split("\\.");
                int last = path.length - 1;
                JSONObject target = this;
                for (int i = 0; i < last; i += 1) {
                    String segment = path[i];
                    JSONObject nextTarget = target.optJSONObject(segment);
                    if (nextTarget == null) {
                        nextTarget = new JSONObject();
                        target.put(segment, nextTarget);
                    }
                    target = nextTarget;
                }
                target.put(path[last], bundle.getString((String) key));
            }
        }
    }
 
Example 16
Source File: UIDefaults.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns a Map of the known resources for the given locale.
 */
private Map<String, Object> getResourceCache(Locale l) {
    Map<String, Object> values = resourceCache.get(l);

    if (values == null) {
        values = new TextAndMnemonicHashMap();
        for (int i=resourceBundles.size()-1; i >= 0; i--) {
            String bundleName = resourceBundles.get(i);
            try {
                Control c = CoreResourceBundleControl.getRBControlInstance(bundleName);
                ResourceBundle b;
                if (c != null) {
                    b = ResourceBundle.getBundle(bundleName, l, c);
                } else {
                    b = ResourceBundle.getBundle(bundleName, l);
                }
                Enumeration keys = b.getKeys();

                while (keys.hasMoreElements()) {
                    String key = (String)keys.nextElement();

                    if (values.get(key) == null) {
                        Object value = b.getObject(key);

                        values.put(key, value);
                    }
                }
            } catch( MissingResourceException mre ) {
                // Keep looking
            }
        }
        resourceCache.put(l, values);
    }
    return values;
}
 
Example 17
Source File: MessageBundleController.java    From attic-rave with Apache License 2.0 5 votes vote down vote up
private Map<String, String> convertResourceBundleToClientMessagesMap(ResourceBundle resourceBundle) {
    Map<String, String> map = new HashMap<String, String>();
    Enumeration<String> keys = resourceBundle.getKeys();
    while (keys.hasMoreElements()) {
        String key = keys.nextElement();
        // only load the messages that are specifically used by the client code for performance reasons
        // strip off the _rave_client. part of the key
        if (key.startsWith(CLIENT_MESSAGE_IDENTIFIER)) {
            map.put(key.replaceFirst(CLIENT_MESSAGE_IDENTIFIER, ""), StringEscapeUtils.escapeEcmaScript(resourceBundle.getString(key)));
        }
    }
    return map;
}
 
Example 18
Source File: MessageBundleServiceImpl.java    From sakai with Educational Community License v2.0 5 votes vote down vote up
private Map<String, String> convertResourceBundleToMap(ResourceBundle resource) {
    Map<String, String> map = new HashMap<String, String>();

    Enumeration<String> keys = resource.getKeys();
    while (keys.hasMoreElements()) {
        String key = keys.nextElement();
        map.put(key, resource.getString(key));
    }

    return map;
}
 
Example 19
Source File: MessageBundleServiceImpl.java    From sakai with Educational Community License v2.0 5 votes vote down vote up
private Map<String, String> convertResourceBundleToMap(ResourceBundle resource) {
    Map<String, String> map = new HashMap<String, String>();

    Enumeration<String> keys = resource.getKeys();
    while (keys.hasMoreElements()) {
        String key = keys.nextElement();
        map.put(key, resource.getString(key));
    }

    return map;
}
 
Example 20
Source File: DBManagerBase.java    From ermasterr with Apache License 2.0 3 votes vote down vote up
protected Set<String> getReservedWords() {
    final Set<String> reservedWords = new HashSet<String>();

    final ResourceBundle bundle = ResourceBundle.getBundle(this.getClass().getPackage().getName() + ".reserved_word");

    final Enumeration<String> keys = bundle.getKeys();

    while (keys.hasMoreElements()) {
        reservedWords.add(keys.nextElement().toUpperCase());
    }

    return reservedWords;
}