本文整理汇总了Java中java.util.ResourceBundle.getKeys方法的典型用法代码示例。如果您正苦于以下问题:Java ResourceBundle.getKeys方法的具体用法?Java ResourceBundle.getKeys怎么用?Java ResourceBundle.getKeys使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.util.ResourceBundle
的用法示例。
在下文中一共展示了ResourceBundle.getKeys方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setup
import java.util.ResourceBundle; //导入方法依赖的package包/类
public static void setup( Languages lang ){
strings = new HashMap<>();
Messages.lang = lang;
Locale locale = new Locale(lang.code());
for (String file : prop_files) {
ResourceBundle bundle = ResourceBundle.getBundle( file, locale);
Enumeration<String> keys = bundle.getKeys();
while (keys.hasMoreElements()) {
String key = keys.nextElement();
String value = bundle.getString(key);
//android 2.2 doesn't use UTF-8 by default, need to force it.
if (android.os.Build.VERSION.SDK_INT == 8) {
try {
value = new String(value.getBytes("ISO-8859-1"), "UTF-8");
} catch (Exception e) {
UNISTPixelDungeon.reportException(e);
}
}
strings.put(key, value);
}
}
}
示例2: getList
import java.util.ResourceBundle; //导入方法依赖的package包/类
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;
}
示例3: testPropertiesAreFields
import java.util.ResourceBundle; //导入方法依赖的package包/类
@Test
public void testPropertiesAreFields() throws Exception {
boolean show = true;
List<String> fieldList = new ArrayList<String>();
for (Field field : I18n.class.getFields()) {
fieldList.add(field.getName());
}
int errors = 0;
for (String locale : locales) {
ResourceBundle bundle = Translator.initialize("can4eve", locale);
Enumeration<String> keys = bundle.getKeys();
while (keys.hasMoreElements()) {
String key = keys.nextElement();
String constantName = asUnderScore(key);
if (!fieldList.contains(constantName)) {
errors++;
if (show)
System.out.println(" public static final String " + constantName
+ "=\"" + key + "\"; //" + bundle.getString(key));
}
}
}
assertEquals(0, errors);
}
示例4: getKeys
import java.util.ResourceBundle; //导入方法依赖的package包/类
/**
* Implementation of ResourceBundle.getKeys.
*/
@Override
public Enumeration<String> getKeys() {
ResourceBundle parentBundle = this.parent;
return new ResourceBundleEnumeration(handleKeySet(),
(parentBundle != null) ? parentBundle.getKeys() : null);
}
示例5: loadEngineProperties
import java.util.ResourceBundle; //导入方法依赖的package包/类
private void loadEngineProperties() {
LogManager.logEntry("loading engine properties"); // NOI18N
try {
LogManager.logIndent("loading engine properties");
ResourceBundle bundle = ResourceBundle.getBundle(
EngineResources.ENGINE_PROPERTIES_BUNDLE);
Enumeration <String> keys = bundle.getKeys();
while (keys.hasMoreElements()) {
final String key = keys.nextElement();
final String value = bundle.getString(key);
LogManager.log("loading " + key + " => " + value); // NOI18N
final String currentValue = System.getProperty(key);
if(currentValue!=null) {
LogManager.log("... already defined, using existing value: " + currentValue); // NOI18N
} else {
System.setProperty(key,value);
}
}
} catch (MissingResourceException e) {
LogManager.log("... no engine properties file, skip loading engine properties");
}
LogManager.unindent();
LogManager.logExit("... finished loading engine properties"); // NOI18N
}
示例6: JSONObject
import java.util.ResourceBundle; //导入方法依赖的package包/类
/**
* 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));
}
}
}
示例7: getAll
import java.util.ResourceBundle; //导入方法依赖的package包/类
public Map<String, String> getAll(final Locale locale) {
Map<String, String> ret = LANGS.get(locale);
if (null == ret) {
ret = new HashMap<>();
ResourceBundle langBundle;
try {
langBundle = ResourceBundle.getBundle(Keys.LANGUAGE, locale);
} catch (final MissingResourceException e) {
logger.warn("{}, using default locale[{}] instead",
new Object[] { e.getMessage(), Latkes.getLocale() });
try {
langBundle = ResourceBundle.getBundle(Keys.LANGUAGE, Latkes.getLocale());
} catch (final MissingResourceException ex) {
logger.warn("{}, using default lang.properties instead", new Object[] { e.getMessage() });
langBundle = ResourceBundle.getBundle(Keys.LANGUAGE);
}
}
final Enumeration<String> keys = langBundle.getKeys();
while (keys.hasMoreElements()) {
final String key = keys.nextElement();
final String value = replaceVars(langBundle.getString(key));
ret.put(key, value);
}
LANGS.put(locale, ret);
}
return ret;
}
示例8: JSONObject
import java.util.ResourceBundle; //导入方法依赖的package包/类
/**
* 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));
}
}
}
示例9: JSONObject
import java.util.ResourceBundle; //导入方法依赖的package包/类
/**
* 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 keys = bundle.getKeys();
while (keys.hasMoreElements()) {
Object key = keys.nextElement();
if (key instanceof String) {
// 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));
}
}
}
示例10: JSONObject
import java.util.ResourceBundle; //导入方法依赖的package包/类
/**
* 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 keys = bundle.getKeys();
while (keys.hasMoreElements()) {
Object key = keys.nextElement();
if (key instanceof String) {
// 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));
}
}
}
示例11: _addMessagesToMap
import java.util.ResourceBundle; //导入方法依赖的package包/类
private void _addMessagesToMap(
Map<String, String> map,
ResourceBundle bundle,
boolean onlyReplaceExisting)
{
Enumeration<String> keys = bundle.getKeys();
while (keys.hasMoreElements())
{
String key = keys.nextElement();
String value = null;
if(onlyReplaceExisting)
{
// just add only those key/value pairs, that already
// were present in the original bundle, to not sent
// down never used (custom) messages
if(map.containsKey(key))
{
value = bundle.getString(key);
map.put(key, value);
}
}
else
{
value = bundle.getString(key);
map.put(key, value);
}
}
}
示例12: setUpAndValidateDefaultBundle
import java.util.ResourceBundle; //导入方法依赖的package包/类
private static void setUpAndValidateDefaultBundle(
BundleContext context)
{
ResourceBundle bundle = context.getLoadedBundle();
_LOG.fine("Testing default bundle:{0}",context.getLoadedBundleName());
Enumeration<String> en = bundle.getKeys();
while (en.hasMoreElements())
{
String key = en.nextElement();
Object value = bundle.getObject(key);
assertNotNull(value);
String valueStr = value.toString().trim();
if (valueStr.length() == 0)
{
String errorMsg
= "Error while testing bundle " + context.getBundleName() + "\n" +
"check value for key " +
key + " " +
"Null or zero length string is not allowed";
_LOG.severe(errorMsg);
fail(errorMsg);
}
_validateBundleValue(context, valueStr, key);
_DEF_BUNDLE_PARAMS.put(key, _getPlaceHolders(value.toString()));
_DEF_BUNDLE_KEYS.add(key);
}
}
示例13: getLegacyPackages
import java.util.ResourceBundle; //导入方法依赖的package包/类
static Set<String> getLegacyPackages() {
ResourceBundle legacyBundle
= ResourceBundle.getBundle("com.sun.tools.javac.resources.legacy");
Set<String> keys = new HashSet<String>();
for (Enumeration<String> e = legacyBundle.getKeys(); e.hasMoreElements(); )
keys.add(e.nextElement());
return keys;
}
示例14: toMap
import java.util.ResourceBundle; //导入方法依赖的package包/类
/**
* Creates a new HashMap using data copied from a ResourceBundle.
*
* @param resourceBundle the resource bundle to convert, may not be null
* @return the hashmap containing the data
* @throws NullPointerException if the bundle is null
*/
public static Map<String, Object> toMap(final ResourceBundle resourceBundle) {
final Enumeration<String> enumeration = resourceBundle.getKeys();
final Map<String, Object> map = new HashMap<String, Object>();
while (enumeration.hasMoreElements()) {
final String key = enumeration.nextElement();
final Object value = resourceBundle.getObject(key);
map.put(key, value);
}
return map;
}
示例15: Locality
import java.util.ResourceBundle; //导入方法依赖的package包/类
public Locality(String resourceFilename) {
String resourceName = resourceFilename;
ResourceBundle bundle = null;
// TODO: Override the properties file name with an external Java property
if (resourceName == null)
resourceName = "locality";
// Look for locality properties in the classpath
try {
bundle = ResourceBundle.getBundle(resourceName);
} catch (MissingResourceException e) {
startupLogger.warn("Application classpath did not have '" + resourceName + "'.properties file");
}
// Read the name/value pairs from the classpath properties file
if(bundle != null) {
Enumeration<String> keys = bundle.getKeys();
while(keys.hasMoreElements()) {
String key = keys.nextElement();
properties.setProperty(key, bundle.getString(key));
}
}
}