List of usage examples for java.util ResourceBundle clearCache
@CallerSensitive public static final void clearCache()
From source file:RBPropDemo.java
public static void main(String[] args) { ResourceBundle.clearCache(); String bundleName = "myproj.MyResources"; ResourceBundle myResources = ResourceBundle.getBundle(bundleName, Locale.GERMAN); System.out.println("Key's values:"); System.out.println(myResources.getString("okKey")); System.out.println(myResources.getString("cancelKey")); System.out.println(myResources.getString("submitKey")); System.out.println("\nChecking okKey in resource bundle:"); if (myResources.containsKey("okKey")) { System.out.println("okKey exists! " + " Value = " + myResources.getString("okKey")); } else {/*ww w. ja v a2s. co m*/ System.out.println("The key Doesn't Exist"); } System.out.println("\nGet a set of keys:"); Set<String> keySet = myResources.keySet(); Object[] keys = keySet.toArray(); for (int i = 0; i < keys.length; i++) { System.out.println("Key " + (i + 1) + " = " + keys[i]); } }
From source file:Main.java
public static void main(String[] args) { ResourceBundle bundle = ResourceBundle.getBundle("hello", Locale.US); System.out.println(bundle.getString("hello")); ResourceBundle.clearCache(); }
From source file:org.eclipse.smarthome.binding.homematic.internal.type.MetadataUtils.java
private static void loadBundle(String filename) { descriptionsBundle = ResourceBundle.getBundle(filename, Locale.getDefault()); for (String key : descriptionsBundle.keySet()) { descriptions.put(key, descriptionsBundle.getString(key)); }//from ww w . jav a 2s . c om ResourceBundle.clearCache(); descriptionsBundle = null; }
From source file:org.pentaho.common.ui.services.LocalizationService.java
private ResourceBundle getBundle(String name) { IPluginResourceLoader resLoader = PentahoSystem.get(IPluginResourceLoader.class, null); ResourceBundle bundle = resLoader.getResourceBundle(LocalizationService.class, name); String cache = PentahoSystem.getSystemSetting(SETTINGS_FILE, "cache-messages", "false"); //$NON-NLS-1$ //$NON-NLS-2$ // Check whether we want to clear the bundle cache which is useful to test resource file changes if (cache != null && cache.equals("false")) { //$NON-NLS-1$ ResourceBundle.clearCache(); }/* w w w .j a va2s.co m*/ return bundle; }
From source file:org.opentaps.notes.rest.locale.Messages.java
/** * Returns class initialized with resource bundle of the requested locale.<br> * First we check URL for embed locale identifier that equals to Locale valid string representation.<br> * Example of encoding locale with URL is: <code>/notes/note/fr_fr/noteID</code><br> * If not found we have to check <code>Accept-Language</code> header and select first available language * looking through the list in the natural order. *//*from w w w. j ava2 s .c om*/ public static Messages getInstance(Request request) { List<Locale> localeList = null; // get encoded locale String lang = (String) request.getAttributes().get("lang"); if (!GenericValidator.isBlankOrNull(lang)) { try { Locale locale = new Locale(lang); localeList = Arrays.asList(locale); } catch (NullPointerException e) { //do nothing } } // get languages from Accept-Language if (localeList == null || localeList.size() == 0) { ClientInfo clientInfo = request.getClientInfo(); List<Preference<Language>> preferences = clientInfo.getAcceptedLanguages(); localeList = new ArrayList<Locale>(preferences.size()); for (Preference<Language> pref : preferences) { localeList.add(new Locale(pref.getMetadata().toString())); } } // looking for the first available if (localeList != null && localeList.size() > 0) { ResourceBundle.clearCache(); for (Locale locale : localeList) { try { String langCode = locale.toString().replaceAll("-", "_"); ResourceBundle rb = ResourceBundle.getBundle(BUNDLE_NAME, locale); Locale rbLocale = rb.getLocale(); if (rbLocale == null || GenericValidator.isBlankOrNull(rbLocale.toString())) { rbLocale = Locale.getDefault(); } if (langCode.equalsIgnoreCase(rbLocale.toString())) { return new Messages(rb); } else { continue; } } catch (MissingResourceException e) { Log.logWarning(e.getLocalizedMessage()); continue; } } } return new Messages(ResourceBundle.getBundle(BUNDLE_NAME)); }
From source file:msearch.tool.MSFunktionen.java
public static String getCompileDate() { final ResourceBundle rb; String propToken = "DATE"; String msg = ""; try {/* w w w .ja v a 2s .com*/ ResourceBundle.clearCache(); rb = ResourceBundle.getBundle("version"); msg = rb.getString(propToken); } catch (Exception e) { MSLog.fehlerMeldung(807293847, MSLog.FEHLER_ART_PROG, MSFunktionen.class.getName(), e); } return msg; }
From source file:mSearch.tool.Functions.java
public static String getCompileDate() { final ResourceBundle rb; String propToken = "DATE"; String msg = ""; try {// w w w . j av a2s. c o m ResourceBundle.clearCache(); rb = ResourceBundle.getBundle("version"); msg = rb.getString(propToken); } catch (Exception e) { Log.errorLog(807293847, e); } return msg; }
From source file:msearch.tool.MSFunktionen.java
public static String getBuildNr() { final ResourceBundle rb; String propToken = "BUILD"; String msg = ""; try {//from w ww . ja va2 s . c o m ResourceBundle.clearCache(); rb = ResourceBundle.getBundle("version"); msg = rb.getString(propToken); } catch (Exception e) { MSLog.fehlerMeldung(134679898, MSLog.FEHLER_ART_PROG, MSFunktionen.class.getName(), e); } return msg; }
From source file:mSearch.tool.Functions.java
public static String getBuildNr() { final ResourceBundle rb; String propToken = "BUILD"; String msg = ""; try {/*from w w w . ja va2s.c om*/ ResourceBundle.clearCache(); rb = ResourceBundle.getBundle("version"); msg = rb.getString(propToken); } catch (Exception e) { Log.errorLog(134679898, e); } return msg; }
From source file:org.pentaho.platform.web.servlet.LocalizationServlet.java
/** * Retrieve a {@link java.util.ResourceBundle} from a plugin. * //w w w . j av a 2s . c om * @param pluginId * ID of the plugin to load the resource bundle from * @param name * Resource bundle name that resides in the plugin * @return Resource bundle for the name provided in the plugin referenced by {@code pluginId} * @throws IllegalArgumentException * Invalid plugin Id * @throws java.util.MissingResourceException * Invalid resource bundle name */ protected ResourceBundle getBundle(String pluginId, String name) { IPluginManager pm = PentahoSystem.get(IPluginManager.class); ClassLoader pluginClassLoader = pm.getClassLoader(pluginId); if (pluginClassLoader == null) { throw new IllegalArgumentException(Messages.getInstance() .getErrorString("LocalizationServlet.ERROR_0001_INVALID_PLUGIN_ID", pluginId)); //$NON-NLS-1$ } if (name == null || name.length() == 0) { throw new IllegalArgumentException(Messages.getInstance() .getErrorString("LocalizationServlet.ERROR_0002_INVALID_RESOURCE_NAME", name)); //$NON-NLS-1$ } ResourceBundle bundle = ResourceBundle.getBundle(name, LocaleHelper.getLocale(), pluginClassLoader); // Clear the bundle's cached messages if we shouldn't be caching them if (!isMessageCachingEnabled(pm, pluginId)) { ResourceBundle.clearCache(); } return bundle; }