List of usage examples for java.util ResourceBundle keySet
Set keySet
To view the source code for java.util ResourceBundle keySet.
Click Source Link
From source file:fr.hoteia.qalingo.core.service.impl.ReferentialDataServiceImpl.java
private Map<String, String> buildMap(final ResourceBundle bundleByLocale) { Map<String, String> mapByLocale = new HashMap<String, String>(); Set<String> keyList = bundleByLocale.keySet(); for (Iterator<String> iterator = keyList.iterator(); iterator.hasNext();) { final String key = (String) iterator.next(); mapByLocale.put(key, (String) bundleByLocale.getObject(key)); }/*w ww .j a va 2s . c o m*/ return mapByLocale; }
From source file:org.openmrs.module.openhmis.cashier.web.controller.CashierMessageRenderController.java
@RequestMapping(method = RequestMethod.GET) public ModelAndView render(HttpServletRequest request) { // object to store keys from cashier and backboneforms Vector<String> keys = new Vector<String>(); // locate and retrieve cashier messages Locale locale = RequestContextUtils.getLocale(request); ResourceBundle resourceBundle = ResourceBundle.getBundle("messages", locale); // store cashier message keys in the vector object keys.addAll(resourceBundle.keySet()); // retrieve backboneforms messages BackboneMessageRenderController backboneController = new BackboneMessageRenderController(); ModelAndView modelAndView = backboneController.render(request); // store backboneforms message keys in the vector object for (Map.Entry<String, Object> messageKeys : modelAndView.getModel().entrySet()) { Enumeration<String> messageKey = (Enumeration<String>) messageKeys.getValue(); while (messageKey.hasMoreElements()) { String key = messageKey.nextElement(); if (!keys.contains(key)) keys.add(key);//from w w w . j av a2 s. co m } } return new ModelAndView(CashierWebConstants.MESSAGE_PAGE, "keys", keys.elements()); }
From source file:org.openmrs.module.openhmis.inventory.web.controller.InventoryMessageRenderController.java
@RequestMapping(method = RequestMethod.GET) public ModelAndView render(HttpServletRequest request) { // object to store keys from inventory and backboneforms Vector<String> keys = new Vector<String>(); Locale locale = RequestContextUtils.getLocale(request); ResourceBundle resourceBundle = ResourceBundle.getBundle("messages", locale); // store inventory message keys in the vector object keys.addAll(resourceBundle.keySet()); // retrieve backboneforms messages BackboneMessageRenderController backboneController = new BackboneMessageRenderController(); ModelAndView modelAndView = backboneController.render(request); // store backboneforms message keys in the vector object for (Map.Entry<String, Object> messageKeys : modelAndView.getModel().entrySet()) { Enumeration<String> messageKey = (Enumeration<String>) messageKeys.getValue(); while (messageKey.hasMoreElements()) { String key = messageKey.nextElement(); if (!keys.contains(key)) keys.add(key);/*from w w w.j a va 2 s. c o m*/ } } return new ModelAndView(ModuleWebConstants.MESSAGE_PAGE, "keys", keys.elements()); }
From source file:org.pentaho.platform.web.servlet.LocalizationServlet.java
/** * Convert a {@see ResourceBundle} into a JSON string. * /*from ww w . j a va2 s.com*/ * @param bundle * Resource bundle to convert * @return Bundle with all key/value pairs as entries in a hash, returned as a JSON string. * @throws org.json.JSONException */ protected String getJsonForBundle(ResourceBundle bundle) throws JSONException { JSONObject cat = new JSONObject(); for (String key : bundle.keySet()) { cat.put(key, bundle.getString(key)); } return cat.toString(); }
From source file:ai.grakn.factory.OrientDBInternalFactory.java
private OrientGraph createIndicesVertex(OrientGraph graph) { ResourceBundle keys = ResourceBundle.getBundle("indices-vertices"); Set<String> labels = keys.keySet(); for (String label : labels) { String[] configs = keys.getString(label).split(","); for (String propertyConfig : configs) { String[] propertyConfigs = propertyConfig.split(":"); Schema.VertexProperty property = Schema.VertexProperty.valueOf(propertyConfigs[0]); boolean isUnique = Boolean.parseBoolean(propertyConfigs[1]); OType orientDataType = getOrientDataType(property); BaseConfiguration indexConfig = new BaseConfiguration(); indexConfig.setProperty("keytype", orientDataType); //TODO: Figure out why this is not working when the Orient Guys say it should //indexConfig.setProperty("metadata.ignoreNullValues", true); if (isUnique) { indexConfig.setProperty("type", "UNIQUE"); }/*from w w w .java2 s.c om*/ if (!graph.getVertexIndexedKeys(label).contains(property.name())) { graph.createVertexIndex(property.name(), label, indexConfig); } } } return graph; }
From source file:com.heliosphere.athena.base.resource.bundle.ResourceBundleManager.java
/** * Registers a resource bundle./*from w w w .j a v a2s . co m*/ * <p> * @param bundleClass Class of the resource bundle to register. * @param bundle Resource bundle to register. * @throws ResourceBundleException Thrown if an error occurred while trying * to register a resource bundle. */ @SuppressWarnings("nls") private static final void register(final Class<? extends IBundle> bundleClass, final ResourceBundle bundle) { ResourceBundle previous = null; try { if (!BUNDLES.containsKey(bundleClass)) { BUNDLES.put(bundleClass, bundle); NAMES.put(bundleClass, bundleClass.getEnumConstants()[0].getKey()); setInitialized(true); String filename = bundleClass.getEnumConstants()[0].getKey() + "_" + locale.toString() + ".properties"; int index = filename.indexOf("."); if (index > -1) { filename = filename.substring(index + 1, filename.length()); } log.debug(getMessage(BundleAthenaBase.ResourceBundleRegistered, bundleClass.getSimpleName(), locale.toString(), Integer.valueOf(bundle.keySet().size()), filename)); } else { /* * Case where the bundle class already exists. If the locale is * the same, do nothing but if the locale is different then * replace it with the new one. */ previous = BUNDLES.get(bundleClass); if (previous.getLocale().equals(bundle.getLocale())) { log.debug(getMessage(BundleAthenaBase.ResourceBundleAlreadyRegistered, bundleClass.getSimpleName(), locale.toString())); } else { BUNDLES.put(bundleClass, bundle); log.debug(getMessage(BundleAthenaBase.ResourceBundleReplaced, bundleClass.getSimpleName(), previous.getLocale().toString(), locale.toString(), Integer.valueOf(bundle.keySet().size()))); } } } catch (final Exception e) { log.error(e.getMessage(), e); throw (ResourceBundleException) e; } }
From source file:com.heliosphere.demeter.base.resource.bundle.ResourceBundleManager.java
/** * Registers a resource bundle.// w ww . ja v a 2 s .com * <p> * @param bundleClass Class of the resource bundle to register. * @param bundle Resource bundle to register. * @throws ResourceBundleException Thrown if an error occurred while trying * to register a resource bundle. */ @SuppressWarnings("nls") private static final void register(final Class<? extends IBundle> bundleClass, final ResourceBundle bundle) { ResourceBundle previous = null; try { if (!BUNDLES.containsKey(bundleClass)) { BUNDLES.put(bundleClass, bundle); NAMES.put(bundleClass, bundleClass.getEnumConstants()[0].getKey()); setInitialized(true); String filename = bundleClass.getEnumConstants()[0].getKey() + "_" + locale.toString() + ".properties"; int index = filename.indexOf("."); if (index > -1) { filename = filename.substring(index + 1, filename.length()); } log.debug(getMessage(BundleDemeterBase.ResourceBundleRegistered, bundleClass.getSimpleName(), locale.toString(), Integer.valueOf(bundle.keySet().size()), filename)); } else { /* * Case where the bundle class already exists. If the locale is * the same, do nothing but if the locale is different then * replace it with the new one. */ previous = BUNDLES.get(bundleClass); if (previous.getLocale().equals(bundle.getLocale())) { log.debug(getMessage(BundleDemeterBase.ResourceBundleAlreadyRegistered, bundleClass.getSimpleName(), locale.toString())); } else { BUNDLES.put(bundleClass, bundle); log.debug(getMessage(BundleDemeterBase.ResourceBundleReplaced, bundleClass.getSimpleName(), previous.getLocale().toString(), locale.toString(), Integer.valueOf(bundle.keySet().size()))); } } } catch (final Exception e) { log.error(e.getMessage(), e); throw (ResourceBundleException) e; } }
From source file:net.sf.yal10n.analyzer.ExploratoryEncodingTest.java
/** * Test to load a reource bundle from a BOM encoded file. * @throws Exception any error//from w ww.ja v a2 s. c om */ @Test public void testResourceBundleWithBOM() throws Exception { ResourceBundle bundle = PropertyResourceBundle.getBundle("UTF8BOM", Locale.ROOT); Assert.assertEquals(3, bundle.keySet().size()); // Assert.assertEquals("first key", bundle.getString("testkey1")); // note: utf-8 bom read as iso-8859-1 Assert.assertEquals("first key", bundle.getString("\u00ef\u00bb\u00bftestkey1")); Assert.assertEquals("second key", bundle.getString("testkey2")); // note: utf-8 read as iso-8859-1 Assert.assertEquals("This file is encoded as UTF-8 with BOM \u00c3\u00a4.", bundle.getString("description")); }
From source file:net.sf.yal10n.analyzer.ExploratoryEncodingTest.java
/** * Test to load a resource bundle from a BOM encoded file that starts with a comment. * @throws Exception any error// w w w . j ava 2 s .c om */ @Test public void testResourceBundleWithBOMandComment() throws Exception { ResourceBundle bundle = PropertyResourceBundle.getBundle("UTF8BOMwithComment", Locale.ROOT); Assert.assertEquals(4, bundle.keySet().size()); Assert.assertEquals("", bundle.getString("\u00ef\u00bb\u00bf#abc")); Assert.assertEquals("first key", bundle.getString("testkey1")); Assert.assertEquals("second key", bundle.getString("testkey2")); // note: utf-8 read as iso-8859-1 Assert.assertEquals("This file is encoded as UTF-8 with BOM \u00c3\u00a4.", bundle.getString("description")); }
From source file:net.sf.yal10n.analyzer.ExploratoryEncodingTest.java
/** * Test to load a resource bundle from a BOM encoded file that starts with a blank line. * @throws Exception any error/*from w w w . j ava2 s . c o m*/ */ @Test public void testResourceBundleWithBOMandBlankLine() throws Exception { ResourceBundle bundle = PropertyResourceBundle.getBundle("UTF8BOMwithBlankLine", Locale.ROOT); Assert.assertEquals(4, bundle.keySet().size()); Assert.assertEquals("first key", bundle.getString("testkey1")); Assert.assertEquals("second key", bundle.getString("testkey2")); // note: utf-8 read as iso-8859-1 Assert.assertEquals("This file is encoded as UTF-8 with BOM \u00c3\u00a4.", bundle.getString("description")); }