com.clusterra.pmbok.document.ExposedResourceBundleMessageSource Maven / Gradle / Ivy
/*
* Copyright (c) 2014.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.clusterra.pmbok.document;
import org.springframework.context.support.ResourceBundleMessageSource;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
import java.util.ResourceBundle;
import java.util.Set;
import java.util.TreeMap;
/**
* Created by dkuchugurov on 20.03.14.
*/
public class ExposedResourceBundleMessageSource extends ResourceBundleMessageSource {
private Map> cachedData = new HashMap<>();
public Set getKeys(String baseName, Locale locale) {
ResourceBundle bundle = getResourceBundle(baseName, locale);
return bundle.keySet();
}
public Map getKeyValues(String basename, Locale locale) {
String cacheKey = basename + locale.getCountry();
if (cachedData.containsKey(cacheKey)) {
return cachedData.get(cacheKey);
}
ResourceBundle bundle = getResourceBundle(basename, locale);
TreeMap treeMap = new TreeMap<>();
for (String key : bundle.keySet()) {
treeMap.put(key, getMessage(key, null, locale));
}
cachedData.put(cacheKey, treeMap);
return treeMap;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy