001
014
015 package com.liferay.util.bridges.jsf.common;
016
017 import com.liferay.portal.kernel.language.LanguageUtil;
018 import com.liferay.portal.kernel.log.Log;
019 import com.liferay.portal.kernel.log.LogFactoryUtil;
020
021 import java.util.Collection;
022 import java.util.Locale;
023 import java.util.Map;
024 import java.util.Set;
025
026 import javax.faces.context.FacesContext;
027
028
036 public class LanguageManagedBean implements Map<String, String> {
037
038 @Override
039 public void clear() {
040 throw new UnsupportedOperationException();
041 }
042
043 @Override
044 public boolean containsKey(Object key) {
045 throw new UnsupportedOperationException();
046 }
047
048 @Override
049 public boolean containsValue(Object value) {
050 throw new UnsupportedOperationException();
051 }
052
053 @Override
054 public Set<Entry<String, String>> entrySet() {
055 throw new UnsupportedOperationException();
056 }
057
058 @Override
059 public String get(Object key) {
060 String value = null;
061
062 if (key != null) {
063 FacesContext facesContext = FacesContext.getCurrentInstance();
064
065 Locale locale = facesContext.getViewRoot().getLocale();
066
067 if (locale == null) {
068 locale = facesContext.getApplication().getDefaultLocale();
069 }
070
071 value = LanguageUtil.get(locale, key.toString());
072
073 if (_log.isDebugEnabled()) {
074 _log.debug(
075 "{locale=" + locale + ", key=" + key + ", value=" + value);
076 }
077 }
078
079 return value;
080 }
081
082 @Override
083 public boolean isEmpty() {
084 throw new UnsupportedOperationException();
085 }
086
087 @Override
088 public Set<String> keySet() {
089 throw new UnsupportedOperationException();
090 }
091
092 @Override
093 public String put(String key, String value) {
094 throw new UnsupportedOperationException();
095 }
096
097 @Override
098 public void putAll(Map<? extends String, ? extends String> map) {
099 throw new UnsupportedOperationException();
100 }
101
102 @Override
103 public String remove(Object key) {
104 throw new UnsupportedOperationException();
105 }
106
107 @Override
108 public int size() {
109 throw new UnsupportedOperationException();
110 }
111
112 @Override
113 public Collection<String> values() {
114 throw new UnsupportedOperationException();
115 }
116
117 private static Log _log = LogFactoryUtil.getLog(LanguageManagedBean.class);
118
119 }