Search in sources :

Example 1 with UTF8Control

use of org.orcid.utils.UTF8Control in project ORCID-Source by ORCID.

the class BaseController method getJavascriptMessages.

@ModelAttribute("jsMessagesJson")
public String getJavascriptMessages(HttpServletRequest request) {
    Locale locale = RequestContextUtils.getLocale(request);
    org.orcid.pojo.Local lPojo = new org.orcid.pojo.Local();
    lPojo.setLocale(locale.toString());
    ResourceBundle definitiveProperties = ResourceBundle.getBundle("i18n/javascript", defaultLocale, new UTF8Control());
    Map<String, String> definitivePropertyMap = OrcidStringUtils.resourceBundleToMap(definitiveProperties);
    ResourceBundle resources = ResourceBundle.getBundle("i18n/javascript", locale, new UTF8Control());
    Map<String, String> localPropertyMap = OrcidStringUtils.resourceBundleToMap(resources);
    if (!defaultLocale.equals(locale)) {
        for (String propertyKey : definitivePropertyMap.keySet()) {
            String property = localPropertyMap.get(propertyKey);
            if (StringUtils.isBlank(property)) {
                localPropertyMap.put(propertyKey, definitivePropertyMap.get(propertyKey));
            }
        }
    }
    lPojo.setMessages(localPropertyMap);
    String messages = "";
    try {
        messages = StringEscapeUtils.escapeEcmaScript(new ObjectMapper().writeValueAsString(lPojo));
    } catch (IOException e) {
        LOGGER.error("getJavascriptMessages error:" + e.toString(), e);
    }
    return messages;
}
Also used : Locale(java.util.Locale) ResourceBundle(java.util.ResourceBundle) IOException(java.io.IOException) UTF8Control(org.orcid.utils.UTF8Control) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) ModelAttribute(org.springframework.web.bind.annotation.ModelAttribute)

Example 2 with UTF8Control

use of org.orcid.utils.UTF8Control in project ORCID-Source by ORCID.

the class LocaleManagerImpl method getJavascriptMessages.

@Cacheable(value = "locale-messages", key = "#locale.toString().concat('-javascript')")
public org.orcid.pojo.Local getJavascriptMessages(Locale locale) {
    org.orcid.pojo.Local lPojo = new org.orcid.pojo.Local();
    lPojo.setLocale(locale.toString());
    ResourceBundle resource = ResourceBundle.getBundle("i18n/javascript", locale, new UTF8Control());
    lPojo.setMessages(OrcidStringUtils.resourceBundleToMap(resource));
    return lPojo;
}
Also used : ResourceBundle(java.util.ResourceBundle) UTF8Control(org.orcid.utils.UTF8Control) Cacheable(org.springframework.cache.annotation.Cacheable)

Example 3 with UTF8Control

use of org.orcid.utils.UTF8Control in project ORCID-Source by ORCID.

the class LocaleManagerImpl method getCountries.

/*
     * Get country names from i18n files
     */
@Cacheable(value = "locale-messages", key = "#locale.toString().concat('-countries-map')")
public Map<String, String> getCountries(Locale locale) {
    ResourceBundle resource = ResourceBundle.getBundle("i18n/messages", locale, new UTF8Control());
    Map<String, String> dbCountries = countryManager.retrieveCountriesAndIsoCodes();
    Map<String, String> countries = new LinkedHashMap<String, String>();
    for (String key : dbCountries.keySet()) {
        countries.put(key, resource.getString(buildInternationalizationKey(CountryIsoEntity.class, key)));
    }
    FunctionsOverCollections.sortMapsByValues(countries);
    return countries;
}
Also used : ResourceBundle(java.util.ResourceBundle) UTF8Control(org.orcid.utils.UTF8Control) LinkedHashMap(java.util.LinkedHashMap) Cacheable(org.springframework.cache.annotation.Cacheable)

Aggregations

ResourceBundle (java.util.ResourceBundle)3 UTF8Control (org.orcid.utils.UTF8Control)3 Cacheable (org.springframework.cache.annotation.Cacheable)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 IOException (java.io.IOException)1 LinkedHashMap (java.util.LinkedHashMap)1 Locale (java.util.Locale)1 ModelAttribute (org.springframework.web.bind.annotation.ModelAttribute)1