当前位置: 首页>>代码示例>>Java>>正文


Java ResourceBundle.getKeys方法代码示例

本文整理汇总了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);
		}
	}
}
 
开发者ID:mango-tree,项目名称:UNIST-pixel-dungeon,代码行数:26,代码来源:Messages.java

示例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;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:21,代码来源:Bug4640234.java

示例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);
}
 
开发者ID:BITPlan,项目名称:can4eve,代码行数:25,代码来源:TestI18n.java

示例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);
 }
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:10,代码来源:OpenListResourceBundle.java

示例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
  }
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:31,代码来源:Installer.java

示例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));
            }
        }
    }
 
开发者ID:BennyThink,项目名称:qcloudClient,代码行数:43,代码来源:JSONObject.java

示例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;
}
 
开发者ID:daima,项目名称:solo-spring,代码行数:35,代码来源:LangPropsService.java

示例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));
            }
        }
    }
 
开发者ID:GloriousEggroll,项目名称:quorrabot,代码行数:38,代码来源:JSONObject.java

示例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));
            }
        }
    }
 
开发者ID:starn,项目名称:encdroidMC,代码行数:43,代码来源:JSONObject.java

示例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));
    }
  }
}
 
开发者ID:ampool,项目名称:monarch,代码行数:40,代码来源:JSONObject.java

示例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);
    }
  }
}
 
开发者ID:apache,项目名称:myfaces-trinidad,代码行数:29,代码来源:TranslationsResourceLoader.java

示例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);
  }
}
 
开发者ID:apache,项目名称:myfaces-trinidad,代码行数:32,代码来源:MessageBundleTest.java

示例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;
}
 
开发者ID:tranleduy2000,项目名称:javaide,代码行数:9,代码来源:CreateSymbols.java

示例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;
}
 
开发者ID:funkemunky,项目名称:HCFCore,代码行数:20,代码来源:MapUtils.java

示例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));
        }

    }

}
 
开发者ID:will-gilbert,项目名称:OSWf-OSWorkflow-fork,代码行数:32,代码来源:Locality.java


注:本文中的java.util.ResourceBundle.getKeys方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。