List of usage examples for java.util ResourceBundle getKeys
public abstract Enumeration<String> getKeys();
From source file:carstore.CarBean.java
/** * <p>For each entry in data, create component and cause it to be * populated with values.</p>/*from w w w . jav a2s .c om*/ */ private void initComponentsFromProperties(FacesContext context, ResourceBundle data) { Application application = context.getApplication(); Enumeration keys = data.getKeys(); String key = null, value = null, componentType = null, valueType = null; UIComponent component = null; // populate the map while (keys.hasMoreElements()) { key = (String) keys.nextElement(); if (key == null) { continue; } // skip secondary keys. if (-1 != key.indexOf("_")) { continue; } value = data.getString(key); componentType = data.getString(key + "_componentType"); valueType = data.getString(key + "_valueType"); if (log.isDebugEnabled()) { log.debug("populating map for " + key + "\n" + "\n\tvalue: " + value + "\n\tcomponentType: " + componentType + "\n\tvalueType: " + valueType); } // create the component for this componentType component = application.createComponent(componentType); populateComponentWithValue(context, component, componentType, value, valueType); components.put(key, component); } }
From source file:org.b3log.latke.service.LangPropsServiceImpl.java
@Override public JSONObject getLabels(final Locale locale) { final JSONObject ret = new JSONObject(); ResourceBundle langBundle; try {//from w w w . j a v a 2 s. com langBundle = ResourceBundle.getBundle(Keys.LANGUAGE, locale); } catch (final MissingResourceException e) { LOGGER.log(Level.WARN, "{0}, using default locale[{1}] instead", new Object[] { e.getMessage(), Latkes.getLocale() }); langBundle = ResourceBundle.getBundle(Keys.LANGUAGE, Latkes.getLocale()); } final Enumeration<String> keys = langBundle.getKeys(); final JSONArray labels = new JSONArray(); ret.put(Label.LABELS, labels); while (keys.hasMoreElements()) { final JSONObject label = new JSONObject(); final String key = keys.nextElement(); label.put(Label.LABEL_ID, key); label.put(Label.LABEL_TEXT, langBundle.getString(key)); labels.put(label); } return ret; }
From source file:it.scoppelletti.programmerpower.security.DefaultRoleManager.java
public Map<String, String> loadRoles(Locale locale) { String desc, role;// w w w .java2 s . c o m ResourceBundle res; Map<String, String> map; Enumeration<String> keys; if (locale == null) { throw new ArgumentNullException("locale"); } map = new TreeMap<String, String>(); try { res = ResourceBundle.getBundle(DefaultRoleManager.BASENAME, locale, myLoader); } catch (MissingResourceException ex) { myLogger.warn(String.format("Resource bundle %1$s not found.", DefaultRoleManager.BASENAME), ex); return map; } keys = res.getKeys(); while (keys.hasMoreElements()) { role = keys.nextElement(); try { desc = res.getString(role); } catch (MissingResourceException ex) { desc = null; } if (Strings.isNullOrEmpty(desc)) { desc = role; } map.put(role, desc); } return map; }
From source file:org.b3log.latke.service.LangPropsService.java
/** * Gets all language properties as labels from lang_(by the specified * locale).properties file. If not found lang_(locale).properties * configurations, using {@link Latkes#getLocale()} instead. * * @param locale the specified locale//ww w. jav a 2s. c om * @return for example, * <pre> * { * "msgs": { * "localeNotFound": * "Unsupported locale, using default locale(zh_CN) instead." * }, * "labels": [ * {"labelId": "projectName", "labelText": "B3log Web"}, * .... * ] * } * </pre> */ public JSONObject getLabels(final Locale locale) { final JSONObject ret = new JSONObject(); ResourceBundle langBundle; try { langBundle = ResourceBundle.getBundle(Keys.LANGUAGE, locale); } catch (final MissingResourceException e) { LOGGER.log(Level.WARNING, "{0}, using default locale[{1}] instead", new Object[] { e.getMessage(), Latkes.getLocale() }); langBundle = ResourceBundle.getBundle(Keys.LANGUAGE, Latkes.getLocale()); } final Enumeration<String> keys = langBundle.getKeys(); final JSONArray labels = new JSONArray(); ret.put(Label.LABELS, labels); while (keys.hasMoreElements()) { final JSONObject label = new JSONObject(); final String key = keys.nextElement(); label.put(Label.LABEL_ID, key); label.put(Label.LABEL_TEXT, langBundle.getString(key)); labels.put(label); } return ret; }
From source file:DateLocaleServlet.java
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, java.io.IOException { //Get the client's Locale Locale locale = request.getLocale(); ResourceBundle bundle = ResourceBundle.getBundle("i18n.WelcomeBundle", locale); String welcome = bundle.getString("Welcome"); String date = DateFormat.getDateTimeInstance(DateFormat.FULL, DateFormat.SHORT, locale).format(new Date()); //Display the locale response.setContentType("text/html"); java.io.PrintWriter out = response.getWriter(); out.println("<html><head><title>" + welcome + "</title></head><body>"); out.println("<h2>" + bundle.getString("Hello") + " " + bundle.getString("and") + " " + welcome + "</h2>"); out.println(date + "<br /><br />"); java.util.Enumeration e = bundle.getKeys(); while (e.hasMoreElements()) { out.println((String) e.nextElement()); out.println("<br /><br />"); }// ww w .j a v a 2 s .c o m out.println("Locale: "); out.println(locale.getLanguage() + "_" + locale.getCountry()); out.println("</body></html>"); }
From source file:edu.ku.brc.specify.prefs.SystemPrefs.java
/** * Constructor.// w w w. j av a 2s .c om */ public SystemPrefs() { createForm("Preferences", "System"); JButton clearCache = form.getCompById("clearcache"); clearCache.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { clearCache(); } }); ValBrowseBtnPanel browse = form.getCompById("7"); if (browse != null) { oldSplashPath = localPrefs.get(SPECIFY_BG_IMG_PATH, null); browse.setValue(oldSplashPath, null); } final ValComboBox localeCBX = form.getCompById("5"); localeCBX.getComboBox().setRenderer(new LocaleRenderer()); localeCBX.setEnabled(false); SwingWorker workerThread = new SwingWorker() { protected int inx = -1; @Override public Object construct() { Vector<Locale> locales = new Vector<Locale>(); Collections.addAll(locales, Locale.getAvailableLocales()); Collections.sort(locales, new Comparator<Locale>() { public int compare(Locale o1, Locale o2) { return o1.getDisplayName().compareTo(o2.getDisplayName()); } }); int i = 0; String language = AppPreferences.getLocalPrefs().get("locale.lang", Locale.getDefault().getLanguage()); String country = AppPreferences.getLocalPrefs().get("locale.country", Locale.getDefault().getCountry()); String variant = AppPreferences.getLocalPrefs().get("locale.var", Locale.getDefault().getVariant()); Locale prefLocale = new Locale(language, country, variant); int justLangIndex = -1; Locale cachedLocale = Locale.getDefault(); for (Locale l : locales) { try { Locale.setDefault(l); ResourceBundle rb = ResourceBundle.getBundle("resources", l); boolean isOK = (l.getLanguage().equals("en") && StringUtils.isEmpty(l.getCountry())) || (l.getLanguage().equals("pt") && l.getCountry().equals("PT")); if (isOK && rb.getKeys().hasMoreElements()) { if (l.getLanguage().equals(prefLocale.getLanguage())) { justLangIndex = i; } if (l.equals(prefLocale)) { inx = i; } localeCBX.getComboBox().addItem(l); i++; } } catch (MissingResourceException ex) { } } if (inx == -1 && justLangIndex > -1) { inx = justLangIndex; } Locale.setDefault(cachedLocale); return null; } @Override public void finished() { UIValidator.setIgnoreAllValidation("SystemPrefs", true); localeCBX.setEnabled(true); localeCBX.getComboBox().setSelectedIndex(inx); JTextField loadingLabel = form.getCompById("6"); if (loadingLabel != null) { loadingLabel.setText(UIRegistry.getResourceString("LOCALE_RESTART_REQUIRED")); } UIValidator.setIgnoreAllValidation("SystemPrefs", false); } }; // start the background task workerThread.start(); ValCheckBox chk = form.getCompById("2"); chk.setValue(localPrefs.getBoolean(VERSION_CHECK, true), "true"); chk = form.getCompById("3"); chk.setValue(remotePrefs.getBoolean(SEND_STATS, true), "true"); chk = form.getCompById("9"); chk.setValue(remotePrefs.getBoolean(SEND_ISA_STATS, true), "true"); chk.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { Collection collection = AppContextMgr.getInstance().getClassObject(Collection.class); if (collection != null) { String isaNumber = collection.getIsaNumber(); if (StringUtils.isNotEmpty(isaNumber) && !((JCheckBox) e.getSource()).isSelected()) { UIRegistry.showLocalizedMsg("ISA_STATS_WARNING"); } } } }); // Not sure why the form isn't picking up the pref automatically /* remove if worldwind is broken*/ValCheckBox useWWChk = form.getCompById(USE_WORLDWIND); /* remove if worldwind is broken*/ValCheckBox hasOGLChk = form.getCompById(SYSTEM_HasOpenGL); /* remove if worldwind is broken*/useWWChk.setValue(localPrefs.getBoolean(USE_WORLDWIND, false), null); /* remove if worldwind is broken*/hasOGLChk.setValue(localPrefs.getBoolean(SYSTEM_HasOpenGL, false), null); /* remove if worldwind is broken*/hasOGLChk.setEnabled(false); //ValCheckBox askCollChk = form.getCompById(ALWAYS_ASK_COLL); //askCollChk.setValue(localPrefs.getBoolean(ALWAYS_ASK_COLL, false), null); }
From source file:org.sakaiproject.util.ResourceLoader.java
protected Map<String, Object> getBundleAsMap(ResourceBundle bundle) { Map<String, Object> bundleMap = new HashMap<String, Object>(); for (Enumeration e = bundle.getKeys(); e.hasMoreElements();) { Object key = e.nextElement(); bundleMap.put((String) key, bundle.getObject((String) key)); }/*from w ww . j a v a 2s . c o m*/ return bundleMap; }
From source file:it.govpay.web.utils.Utils.java
public Map<String, String> getMessagesFromResourceBundle(String bundleName, String keyPrefix, Object params[], Locale locale) {// w w w. ja va 2s.c om Map<String, String> toRet = new HashMap<String, String>(); String text = null; ResourceBundle bundle = ResourceBundle.getBundle(bundleName, locale, this.getCurrentClassLoader(params)); Enumeration<String> keys = bundle.getKeys(); while (keys.hasMoreElements()) { String key = (String) keys.nextElement(); if (key.startsWith(keyPrefix)) { try { text = bundle.getString(key); } catch (MissingResourceException e) { text = MISSING_RESOURCE_START_PLACEHOLDER + key + MISSING_RESOURCE_END_PLACEHOLDER; } if (params != null) { MessageFormat mf = new MessageFormat(text, locale); text = mf.format(params, new StringBuffer(), null).toString(); } toRet.put(key.substring(keyPrefix.length()), text); } } return toRet; }
From source file:com.varaneckas.hawkscope.cfg.ConfigurationFactory.java
/** * Loads {@link Configuration}/* w w w . j av a2 s . com*/ * * @see #configuration */ private void loadConfiguration() { final Map<String, String> cfg = getDefaults(); try { final ResourceBundle data = UTF8ResourceBundle.getBundle(CONFIG_FILE_NAME, new ClassLoader() { @Override protected URL findResource(final String name) { try { final String file = loadConfigFilePath() + "/." + name; log.debug("Resolving config file: " + file); return new File(file).toURI().toURL(); } catch (final MalformedURLException e) { log.error("Failed loading file", e); return null; } } }); final Enumeration<String> keys = data.getKeys(); while (keys.hasMoreElements()) { final String key = keys.nextElement(); cfg.put(key, data.getString(key)); } } catch (final MissingResourceException e) { log.debug("Configuration not found, using defaults. (" + e.getMessage() + ")"); write(new Configuration(cfg)); } configuration = new Configuration(cfg); }
From source file:com.feilong.core.bean.ConvertUtil.java
/** * ??,k/v ?map.//from www . j a v a2s .co m * * <p> * ?:JDK{@link java.util.PropertyResourceBundle}, hashmap??,<br> * log?,<span style="color:red"> TreeMap</span> * </p> * * @param resourceBundle * the resource bundle * @return <code>resourceBundle</code> null, {@link NullPointerException}<br> * <code>resourceBundle</code> key,{@link java.util.Collections#emptyMap()}<br> * ?,?keyvalue? {@link TreeMap}<br> * @see MapUtils#toMap(ResourceBundle) * @since 1.7.3 */ public static Map<String, String> toMap(ResourceBundle resourceBundle) { Validate.notNull(resourceBundle, "resourceBundle can't be null!"); Enumeration<String> keysEnumeration = resourceBundle.getKeys(); if (isNullOrEmpty(keysEnumeration)) { return Collections.emptyMap(); } Map<String, String> map = new TreeMap<String, String>();//log, treeMap while (keysEnumeration.hasMoreElements()) { String key = keysEnumeration.nextElement(); map.put(key, resourceBundle.getString(key)); } return map; }