001
014
015 package com.liferay.portal.language;
016
017 import com.liferay.portal.kernel.util.PropertiesUtil;
018
019 import java.io.IOException;
020 import java.io.InputStream;
021
022 import java.util.Collections;
023 import java.util.Enumeration;
024 import java.util.HashMap;
025 import java.util.Map;
026 import java.util.Properties;
027 import java.util.ResourceBundle;
028 import java.util.Set;
029
030
034 public class LiferayResourceBundle extends ResourceBundle {
035
036 public LiferayResourceBundle(InputStream inputStream, String charsetName)
037 throws IOException {
038
039 this(null, inputStream, charsetName);
040 }
041
042 public LiferayResourceBundle(
043 ResourceBundle parentResourceBundle, InputStream inputStream,
044 String charsetName)
045 throws IOException {
046
047 setParent(parentResourceBundle);
048
049 _map = new HashMap<>();
050
051 Properties properties = PropertiesUtil.load(inputStream, charsetName);
052
053 LanguageResources.fixValues(_map, properties);
054 }
055
056 public LiferayResourceBundle(String string) throws IOException {
057 _map = new HashMap<>();
058
059 Properties properties = PropertiesUtil.load(string);
060
061 LanguageResources.fixValues(_map, properties);
062 }
063
064 @Override
065 public Enumeration<String> getKeys() {
066 Set<String> keys = _map.keySet();
067
068 if (parent == null) {
069 return Collections.enumeration(keys);
070 }
071
072 return new ResourceBundleEnumeration(keys, parent.getKeys());
073 }
074
075 @Override
076 public Object handleGetObject(String key) {
077 if (key == null) {
078 throw new NullPointerException();
079 }
080
081 return _map.get(key);
082 }
083
084 @Override
085 protected Set<String> handleKeySet() {
086 return _map.keySet();
087 }
088
089 private final Map<String, String> _map;
090
091 }