1   /**
2    * Copyright (c) 2000-2009 Liferay, Inc. All rights reserved.
3    *
4    * Permission is hereby granted, free of charge, to any person obtaining a copy
5    * of this software and associated documentation files (the "Software"), to deal
6    * in the Software without restriction, including without limitation the rights
7    * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8    * copies of the Software, and to permit persons to whom the Software is
9    * furnished to do so, subject to the following conditions:
10   *
11   * The above copyright notice and this permission notice shall be included in
12   * all copies or substantial portions of the Software.
13   *
14   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20   * SOFTWARE.
21   */
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  /**
37   * <a href="LanguageManagedBean.java.html"><b><i>View Source</i></b></a>
38   *
39   * <p>
40   * This class serves as a bridge between the JSF Expression Language (EL) and
41   * Liferay's Language.properties resource bundle.
42   * </p>
43   *
44   * @author Neil Griffin
45   */
46  public class LanguageManagedBean implements Map<String, String> {
47  
48      public void clear() {
49          throw new UnsupportedOperationException();
50      }
51  
52      public boolean containsKey(Object key) {
53          throw new UnsupportedOperationException();
54      }
55  
56      public boolean containsValue(Object value) {
57          throw new UnsupportedOperationException();
58      }
59  
60      public boolean isEmpty() {
61          throw new UnsupportedOperationException();
62      }
63  
64      public Set<Entry<String, String>> entrySet() {
65          throw new UnsupportedOperationException();
66      }
67  
68      public String get(Object key) {
69          String value = null;
70  
71          if (key != null) {
72              FacesContext facesContext = FacesContext.getCurrentInstance();
73  
74              Locale locale = facesContext.getViewRoot().getLocale();
75  
76              if (locale == null) {
77                  locale = facesContext.getApplication().getDefaultLocale();
78              }
79  
80              value = LanguageUtil.get(locale, key.toString());
81  
82              if (_log.isDebugEnabled()) {
83                  _log.debug(
84                      "{locale=" + locale + ", key=" + key + ", value=" + value);
85              }
86          }
87  
88          return value;
89      }
90  
91      public Set<String> keySet() {
92          throw new UnsupportedOperationException();
93      }
94  
95      public String put(String key, String value) {
96          throw new UnsupportedOperationException();
97      }
98  
99      public void putAll(Map<? extends String, ? extends String> map) {
100         throw new UnsupportedOperationException();
101     }
102 
103     public String remove(Object key) {
104         throw new UnsupportedOperationException();
105     }
106 
107     public int size() {
108         throw new UnsupportedOperationException();
109     }
110 
111     public Collection<String> values() {
112         throw new UnsupportedOperationException();
113     }
114 
115     private static Log _log = LogFactoryUtil.getLog(LanguageManagedBean.class);
116 
117 }