本文整理匯總了Java中java.util.ResourceBundle.keySet方法的典型用法代碼示例。如果您正苦於以下問題:Java ResourceBundle.keySet方法的具體用法?Java ResourceBundle.keySet怎麽用?Java ResourceBundle.keySet使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.util.ResourceBundle
的用法示例。
在下文中一共展示了ResourceBundle.keySet方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getKey
import java.util.ResourceBundle; //導入方法依賴的package包/類
private static String getKey(String item, Locale locale, String baseName) {
ResourceBundle resourceBundle = ResourceBundle.getBundle(baseName, locale, new XMLResourceBundleControl());
String itemTyped = correctItemName(item);
String bestMatch = null;
int diffScore = Integer.MAX_VALUE;
for (String key : resourceBundle.keySet()) {
String itemName = correctItemName(resourceBundle.getString(key));
if (itemTyped.equals(itemName)) {
return key;
} else {
int score = compareFuzzy(itemName, itemTyped);
if (score < diffScore) {
diffScore = score;
bestMatch = key;
}
}
}
if (scoreIsGood(itemTyped, diffScore)) {
return bestMatch;
} else {
throw new RuntimeException(String.format("Can't find %s in %s %s", item, baseName, locale.toLanguageTag()));
}
}
示例2: getMessagesValues
import java.util.ResourceBundle; //導入方法依賴的package包/類
public static List<String> getMessagesValues(Locale locale, String keyPrefix) {
ResourceBundle rb = loadLocalResourceBundle(locale);
List<String> res = new ArrayList<>();
for (String key : rb.keySet()) {
if (key.startsWith(keyPrefix)) {
res.add(key);
}
}
Collections.sort(res);
return res;
}
示例3: getKeysFromFile
import java.util.ResourceBundle; //導入方法依賴的package包/類
private Set<String> getKeysFromFile(
Map<String, ResourceBundle> defaultMessageProperties,
Map<String, Properties> localizedProperties, String locale,
String sheetName) {
if (BaseBean.LABEL_USERINTERFACE_TRANSLARIONS.equals(sheetName)) {
ResourceBundle bundle = defaultMessageProperties.get(locale);
if (bundle != null) {
return bundle.keySet();
}
} else {
return loadKeySetFromProperties(localizedProperties, locale
+ StandardLanguage.COLUMN_HEADING_SUFFIX);
}
return new HashSet<String>();
}
示例4: logEnvironment
import java.util.ResourceBundle; //導入方法依賴的package包/類
private static void logEnvironment(Logger logger) {
ResourceBundle res = ResourceBundle.getBundle("fr.inra.maiage.bibliome.alvisnlp.core.app.cli.LogEnvironment");
for (String var : res.keySet()) {
String value = System.getenv(var);
if (value == null)
continue;
String label = res.getString(var);
logger.config(label + ": " + value);
}
}
示例5: service
import java.util.ResourceBundle; //導入方法依賴的package包/類
@Override
protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException
{
final String path = req.getPathInfo();
if( path.equals("/refresh") )
{
languageService.refreshBundles();
resp.setContentType("text/plain");
ServletOutputStream out = resp.getOutputStream();
out.print("Bundles refreshed");
out.close();
return;
}
Matcher m = Pattern.compile("^/([a-zA-Z_]*)/([a-zA-Z-]+)\\.properties$").matcher(path);
if( !m.matches() || m.groupCount() != 2 )
{
throw new ServletException("Bundle Group name is invalid: " + path);
}
final ResourceBundle resourceBundle = languageService.getResourceBundle(LocaleUtils.parseLocale(m.group(1)),
m.group(2));
final Properties text = new Properties();
for( String key : resourceBundle.keySet() )
{
text.put(key, resourceBundle.getString(key));
}
resp.setContentType("text/plain");
resp.setHeader("Content-Disposition", "inline; filename=" + path + ".properties");
text.store(resp.getOutputStream(), null);
}
示例6: testReadResource1
import java.util.ResourceBundle; //導入方法依賴的package包/類
public void testReadResource1() {
ResourceBundle bundle = ResourceBundle.getBundle("sun.security.util.Resources");
Set<String> strings = bundle.keySet();
System.out.println(strings);
Enumeration<String> keys = bundle.getKeys();
int i = 0;
while (keys.hasMoreElements()) {
String s = keys.nextElement();
System.out.println(i + ": " + s);
i++;
}
}
示例7: loadPropertiesFromBundle
import java.util.ResourceBundle; //導入方法依賴的package包/類
/**
* Loads properties based on a resource bundle name.
*
* @param bundleName the resource bundle name.
*
* @return loaded properties from the named resource bundle.
*/
public static Properties loadPropertiesFromBundle(String bundleName) {
ResourceBundle rb = ResourceBundle.getBundle(bundleName);
Properties properties = new Properties();
for (String key : rb.keySet()) {
String value = rb.getString(key);
properties.put(key, value);
}
return properties;
}
示例8: handleKeySet
import java.util.ResourceBundle; //導入方法依賴的package包/類
@Override
protected Set<String> handleKeySet() {
if (keys == null) {
ResourceBundle info = getBreakIteratorInfo();
Set<String> k = info.keySet();
k.removeAll(NON_DATA_KEYS);
synchronized (this) {
if (keys == null) {
keys = k;
}
}
}
return keys;
}
示例9: displayValues
import java.util.ResourceBundle; //導入方法依賴的package包/類
public void displayValues(ResourceBundle bundle) {
for (String k : bundle.keySet()) {
String v = bundle.getString(k);
System.out.println("i18n: " + k + "=" + v);
}
}