1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * This library is free software; you can redistribute it and/or modify it under
5    * the terms of the GNU Lesser General Public License as published by the Free
6    * Software Foundation; either version 2.1 of the License, or (at your option)
7    * any later version.
8    *
9    * This library is distributed in the hope that it will be useful, but WITHOUT
10   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11   * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12   * details.
13   */
14  
15  package com.liferay.util.bridges.jsf.common;
16  
17  import com.liferay.portal.kernel.language.LanguageUtil;
18  import com.liferay.portal.kernel.log.Log;
19  import com.liferay.portal.kernel.log.LogFactoryUtil;
20  
21  import java.util.Collection;
22  import java.util.Locale;
23  import java.util.Map;
24  import java.util.Set;
25  
26  import javax.faces.context.FacesContext;
27  
28  /**
29   * <a href="LanguageManagedBean.java.html"><b><i>View Source</i></b></a>
30   *
31   * <p>
32   * This class serves as a bridge between the JSF Expression Language (EL) and
33   * Liferay's Language.properties resource bundle.
34   * </p>
35   *
36   * @author Neil Griffin
37   */
38  public class LanguageManagedBean implements Map<String, String> {
39  
40      public void clear() {
41          throw new UnsupportedOperationException();
42      }
43  
44      public boolean containsKey(Object key) {
45          throw new UnsupportedOperationException();
46      }
47  
48      public boolean containsValue(Object value) {
49          throw new UnsupportedOperationException();
50      }
51  
52      public boolean isEmpty() {
53          throw new UnsupportedOperationException();
54      }
55  
56      public Set<Entry<String, String>> entrySet() {
57          throw new UnsupportedOperationException();
58      }
59  
60      public String get(Object key) {
61          String value = null;
62  
63          if (key != null) {
64              FacesContext facesContext = FacesContext.getCurrentInstance();
65  
66              Locale locale = facesContext.getViewRoot().getLocale();
67  
68              if (locale == null) {
69                  locale = facesContext.getApplication().getDefaultLocale();
70              }
71  
72              value = LanguageUtil.get(locale, key.toString());
73  
74              if (_log.isDebugEnabled()) {
75                  _log.debug(
76                      "{locale=" + locale + ", key=" + key + ", value=" + value);
77              }
78          }
79  
80          return value;
81      }
82  
83      public Set<String> keySet() {
84          throw new UnsupportedOperationException();
85      }
86  
87      public String put(String key, String value) {
88          throw new UnsupportedOperationException();
89      }
90  
91      public void putAll(Map<? extends String, ? extends String> map) {
92          throw new UnsupportedOperationException();
93      }
94  
95      public String remove(Object key) {
96          throw new UnsupportedOperationException();
97      }
98  
99      public int size() {
100         throw new UnsupportedOperationException();
101     }
102 
103     public Collection<String> values() {
104         throw new UnsupportedOperationException();
105     }
106 
107     private static Log _log = LogFactoryUtil.getLog(LanguageManagedBean.class);
108 
109 }