1
22
23 package com.liferay.util.bridges.jsf.common;
24
25 import com.liferay.portal.kernel.language.LanguageUtil;
26 import com.liferay.portal.kernel.log.Log;
27 import com.liferay.portal.kernel.log.LogFactoryUtil;
28
29 import java.util.Collection;
30 import java.util.Locale;
31 import java.util.Map;
32 import java.util.Set;
33
34 import javax.faces.context.FacesContext;
35
36
47 public class LanguageManagedBean implements Map<String, String> {
48
49 public LanguageManagedBean() {
50
51
53 FacesContext facesContext = FacesContext.getCurrentInstance();
54
55 _companyId = JSFPortletUtil.getCompanyId(facesContext);
56
57 if (_companyId == 0) {
58 _log.error("Unable to determine company id from facesContext");
59 }
60 }
61
62 public void clear() {
63 throw new UnsupportedOperationException();
64 }
65
66 public boolean containsKey(Object key) {
67 throw new UnsupportedOperationException();
68 }
69
70 public boolean containsValue(Object value) {
71 throw new UnsupportedOperationException();
72 }
73
74 public boolean isEmpty() {
75 throw new UnsupportedOperationException();
76 }
77
78 public Set<Entry<String, String>> entrySet() {
79 throw new UnsupportedOperationException();
80 }
81
82 public String get(Object key) {
83 String value = null;
84
85 if (key != null) {
86 FacesContext facesContext = FacesContext.getCurrentInstance();
87
88 Locale locale = facesContext.getViewRoot().getLocale();
89
90 if (locale == null) {
91 locale = facesContext.getApplication().getDefaultLocale();
92 }
93
94 value = LanguageUtil.get(_companyId, locale, key.toString());
95
96 if (_log.isDebugEnabled()) {
97 _log.debug(
98 "{companyId=" + _companyId + ", locale=" + locale +
99 ", key=" + key + ", value=" + value);
100 }
101 }
102
103 return value;
104 }
105
106 public Set<String> keySet() {
107 throw new UnsupportedOperationException();
108 }
109
110 public String put(String key, String value) {
111 throw new UnsupportedOperationException();
112 }
113
114 public void putAll(Map<? extends String, ? extends String> map) {
115 throw new UnsupportedOperationException();
116 }
117
118 public String remove(Object key) {
119 throw new UnsupportedOperationException();
120 }
121
122 public int size() {
123 throw new UnsupportedOperationException();
124 }
125
126 public Collection<String> values() {
127 throw new UnsupportedOperationException();
128 }
129
130 private static Log _log = LogFactoryUtil.getLog(LanguageManagedBean.class);
131
132 private long _companyId = 0;
133
134 }