Java Code Examples for java.util.ResourceBundle#clearCache()

The following examples show how to use java.util.ResourceBundle#clearCache() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ResourceBundleDAOImpl.java    From arcusplatform with Apache License 2.0 6 votes vote down vote up
@Override
public void saveBundle(final String bundleName, final Locale locale, Map<String, String> localizedValues) {
   Preconditions.checkArgument(!StringUtils.isBlank(bundleName), "bundleName must not be blank");
   Preconditions.checkNotNull(locale, "locale must not be null");

   if(localizedValues.isEmpty()) {
      return;
   }

   localizedValues = new HashMap<String,String>(localizedValues);
   final BatchStatement batch = new BatchStatement();

   localizedValues.forEach((k,v) -> {
      batch.add(new BoundStatement(saveBundleStmt).bind(bundleName, sanitizeLocale(locale), k, v));
   });

   try(Timer.Context ctxt = saveBundleTimer.time()) {
      session.execute(batch);
   }

   // make sure the cache is flushed for the bundle
   // TODO:  this works for this node, but we have no way of notifying the cluster to flush the cache
   ResourceBundle.clearCache();
}
 
Example 2
Source File: LabelsBundlesTest.java    From ripme with MIT License 6 votes vote down vote up
@Test
void testKeyCount() {
    ResourceBundle defaultBundle = Utils.getResourceBundle(null);
    HashMap<String, ArrayList<String>> dictionary = new HashMap<>();
    for (String lang : Utils.getSupportedLanguages()) {
        ResourceBundle.clearCache();
        if (lang.equals(DEFAULT_LANG))
            continue;
        ResourceBundle selectedLang = Utils.getResourceBundle(lang);
        for (final Enumeration<String> keys = defaultBundle.getKeys(); keys.hasMoreElements();) {
            String element = keys.nextElement();
            if (selectedLang.containsKey(element)
                    && !selectedLang.getString(element).equals(defaultBundle.getString(element))) {
                if (dictionary.get(lang) == null)
                    dictionary.put(lang, new ArrayList<>());
                dictionary.get(lang).add(element);
            }
        }
    }

    dictionary.keySet().forEach(d -> {
        logger.warn(String.format("Keys missing in %s", d));
        dictionary.get(d).forEach(v -> logger.warn(v));
        logger.warn("\n");
    });
}
 
Example 3
Source File: SiteManagementHandler.java    From drftpd with GNU General Public License v2.0 6 votes vote down vote up
public CommandResponse doSITE_RELOAD(CommandRequest request) {
    try {
        GlobalContext.getGlobalContext().getSectionManager().reload();
        GlobalContext.getGlobalContext().reloadFtpConfig();
        GlobalContext.getGlobalContext().getSlaveSelectionManager().reload();
        // Send event to every plugins
        GlobalContext.getEventService().publish(new ReloadEvent());
    } catch (IOException e) {
        logger.log(Level.FATAL, "Error reloading config", e);
        return new CommandResponse(200, e.getMessage());
    }

    // Clear base system classloader also
    ResourceBundle.clearCache(ClassLoader.getSystemClassLoader());
    return StandardCommandManager.genericResponse("RESPONSE_200_COMMAND_OK");
}
 
Example 4
Source File: ResourceBundleHelper.java    From ph-commons with Apache License 2.0 5 votes vote down vote up
/**
 * Clear the complete resource bundle cache using the specified class loader!
 *
 * @param aClassLoader
 *        The class loader to be used. May not be <code>null</code>.
 */
public static void clearCache (@Nonnull final ClassLoader aClassLoader)
{
  ResourceBundle.clearCache (aClassLoader);
  if (LOGGER.isDebugEnabled ())
    LOGGER.debug ("Cache was cleared: " + ResourceBundle.class.getName () + "; classloader=" + aClassLoader);
}
 
Example 5
Source File: Functions.java    From MLib with GNU General Public License v3.0 5 votes vote down vote up
@Deprecated
public static String getBuildNr() {
    String TOKEN_VERSION = "VERSION";
    try {
        ResourceBundle.clearCache();
        ResourceBundle rb = ResourceBundle.getBundle(RBVERSION);
        if (rb.containsKey(TOKEN_VERSION)) {
            return new Version(rb.getString(TOKEN_VERSION)).toString();
        }
    } catch (Exception e) {
        Log.errorLog(134679898, e);
    }
    return new Version("").toString();
}
 
Example 6
Source File: I18n.java    From tech-gallery with Apache License 2.0 5 votes vote down vote up
/**
 * Get the message in the file for the respective language.
 * @param string message.
 * @return translated message.
 */
public String t(String string) {
  Locale locale = new Locale(language, country);
  ResourceBundle.clearCache();
  ResourceBundle translation = ResourceBundle.getBundle("i18n/Tech_Gallery", locale);
  return translation.getString(string);
}
 
Example 7
Source File: I18nService.java    From lutece-core with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Reset the caches
 * 
 * @since 5.1
 */
public static void resetCache( )
{
    ResourceBundle.clearCache( );

    if ( _overrideLoader != null )
    {
        ResourceBundle.clearCache( _overrideLoader );
    }

    _resourceBundleCache.clear( );
}
 
Example 8
Source File: Functions.java    From MLib with GNU General Public License v3.0 5 votes vote down vote up
public static Version getProgVersion() {
    String TOKEN_VERSION = "VERSION";
    try {
        ResourceBundle.clearCache();
        ResourceBundle rb = ResourceBundle.getBundle(RBVERSION);
        if (rb.containsKey(TOKEN_VERSION)) {
            return new Version(rb.getString(TOKEN_VERSION));
        }
    } catch (Exception e) {
        Log.errorLog(134679898, e);
    }
    return new Version("");
}
 
Example 9
Source File: MetadataUtils.java    From smarthome with Eclipse Public License 2.0 5 votes vote down vote up
private static void loadBundle(String filename) {
    descriptionsBundle = ResourceBundle.getBundle(filename, Locale.getDefault());
    for (String key : descriptionsBundle.keySet()) {
        descriptions.put(key, descriptionsBundle.getString(key));
    }
    ResourceBundle.clearCache();
    descriptionsBundle = null;
}
 
Example 10
Source File: WebUtil.java    From ctsms with GNU Lesser General Public License v2.1 5 votes vote down vote up
public static void clearResourceBundleCache() throws Exception {
	WebUtil.getServiceLocator().getToolsService().clearResourceBundleCache();
	//https://stackoverflow.com/questions/4325164/how-to-reload-resource-bundle-in-web-application
	ResourceBundle.clearCache(Thread.currentThread().getContextClassLoader());
	Iterator<ApplicationResourceBundle> it = ApplicationAssociate.getCurrentInstance().getResourceBundles().values().iterator();
	while (it.hasNext()) {
		ApplicationResourceBundle appBundle = it.next();
		Map<Locale, ResourceBundle> resources = CommonUtil.getDeclaredFieldValue(appBundle, "resources");
		resources.clear();
	}
}
 
Example 11
Source File: I18N.java    From bladecoder-adventure-engine with Apache License 2.0 5 votes vote down vote up
public ResourceBundle getBundle(String filename, boolean clearCache) {
	ResourceBundle rb = null;

	try {
		if (clearCache)
			ResourceBundle.clearCache();

		rb = ResourceBundle.getBundle(filename, locale, new I18NControl(ENCODING));
	} catch (Exception e) {
		EngineLogger.error("ERROR LOADING BUNDLE: " + filename);
	}

	return rb;
}
 
Example 12
Source File: HelloWorldBaseServlet.java    From HotswapAgentExamples with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Return content of testWatch.properties. It should be resolved to target/classes until
 * resources-watch/testWatch.properties is modified, then it should return the new value.
 */
protected String getHelloResourceWatch() {
    ResourceBundle.clearCache();
    return ResourceBundle.getBundle("testWatch").getString("hello");
}
 
Example 13
Source File: LanguageResourceBundleManager.java    From openhab-core with Eclipse Public License 2.0 4 votes vote down vote up
/**
 * Releases any cached resources which were managed by this class from the {@link ResourceBundle}.
 */
public void clearCache() {
    ResourceBundle.clearCache(this.resourceClassLoader);
}
 
Example 14
Source File: Compile.java    From ctsms with GNU Lesser General Public License v2.1 4 votes vote down vote up
public static void clearResourceBundleCache() {
	if (classLoader != null) {
		ResourceBundle.clearCache(classLoader);
	}
}
 
Example 15
Source File: Messages.java    From MetarParser with MIT License 4 votes vote down vote up
/**
 * Sets the locale of the bundle.
 *
 * @param locale the locale to set.
 */
public void setLocale(final Locale locale) {
    Locale.setDefault(locale);
    ResourceBundle.clearCache();
    fResourceBundle = ResourceBundle.getBundle(BUNDLE_NAME, locale);
}
 
Example 16
Source File: I18nFactory.java    From Shuffle-Move with GNU General Public License v3.0 4 votes vote down vote up
public static void clearCache() {
   ResourceBundle.clearCache();
}
 
Example 17
Source File: HelloWorldBaseServlet.java    From HotswapAgentExamples with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Return basic resource, it should be handled from target/extra directory.
 */
protected String getHelloResource() {
    ResourceBundle.clearCache();
    return ResourceBundle.getBundle("test").getString("hello");
}
 
Example 18
Source File: HelloWorldBaseServlet.java    From HotswapAgentExamples with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Return content of testWatch.properties. It should be resolved to target/classes until
 * resources-watch/testWatch.properties is modified, then it should return the new value.
 */
protected String getHelloResourceWatch() {
    ResourceBundle.clearCache();
    return ResourceBundle.getBundle("testWatch").getString("hello");
}
 
Example 19
Source File: HelloWorldBaseServlet.java    From HotswapAgentExamples with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Return basic resource, it should be handled from target/extra directory.
 */
protected String getHelloResource() {
    ResourceBundle.clearCache();
    return ResourceBundle.getBundle("test").getString("hello");
}
 
Example 20
Source File: ResourceBundleMessageSourceTests.java    From spring-analysis-note with MIT License 4 votes vote down vote up
@After
public void tearDown() {
	ResourceBundle.clearCache();
}