java.util.ResourceBundle#getKeys ( )源码实例Demo

下面列出了java.util.ResourceBundle#getKeys ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: document-management-software   文件: I18N.java
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;
}
 
源代码2 项目: hipparchus   文件: LocalizedFormatsAbstractTest.java
@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());
    }

}
 
源代码3 项目: jdk8u-jdk   文件: Bug4640234.java
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;
}
 
源代码4 项目: astor   文件: LocalizedFormatsTest.java
@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());
    }

}
 
源代码5 项目: zap-extensions   文件: ExtensionTipsAndTricks.java
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;
}
 
源代码6 项目: openjdk-8   文件: UIDefaults.java
/**
 * 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;
}
 
源代码7 项目: sakai   文件: MessageBundleServiceImpl.java
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;
}
 
源代码8 项目: sakai   文件: MessageBundleServiceImpl.java
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;
}
 
源代码9 项目: attic-rave   文件: MessageBundleController.java
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;
}
 
源代码10 项目: jdk8u-jdk   文件: UIDefaults.java
/**
 * 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;
}
 
源代码11 项目: browserprint   文件: JSONObject.java
/**
     * 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));
            }
        }
    }
 
源代码12 项目: openjdk-jdk9   文件: UIDefaults.java
/**
 * 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;
}
 
源代码13 项目: openjdk-8-source   文件: OpenListResourceBundle.java
/**
 * Implementation of ResourceBundle.getKeys.
 */
@Override
public Enumeration<String> getKeys() {
    ResourceBundle parentBundle = this.parent;
    return new ResourceBundleEnumeration(handleKeySet(),
            (parentBundle != null) ? parentBundle.getKeys() : null);
 }
 
源代码14 项目: JMCCC   文件: JSONObject.java
/**
 * 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));
		}
	}
}
 
源代码15 项目: Vert.X-generator   文件: Main.java
/**
 * 根据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));
		}
	}
}
 
源代码16 项目: openjdk-8   文件: GenerateKeyList.java
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);
    }
}
 
源代码17 项目: jdk8u-jdk   文件: OpenListResourceBundle.java
/**
 * Implementation of ResourceBundle.getKeys.
 */
@Override
public Enumeration<String> getKeys() {
    ResourceBundle parentBundle = this.parent;
    return new ResourceBundleEnumeration(handleKeySet(),
            (parentBundle != null) ? parentBundle.getKeys() : null);
 }
 
源代码18 项目: openjdk-jdk9   文件: GenerateKeyList.java
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);
    }
}
 
源代码19 项目: nettythrift   文件: JSONObject.java
/**
 * 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));
		}
	}
}
 
源代码20 项目: ermasterr   文件: DBManagerBase.java
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;
}