001    /**
002     * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
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    /**
029     * <p>
030     * This class serves as a bridge between the JSF Expression Language (EL) and
031     * Liferay's Language.properties resource bundle.
032     * </p>
033     *
034     * @author Neil Griffin
035     */
036    public class LanguageManagedBean implements Map<String, String> {
037    
038            public void clear() {
039                    throw new UnsupportedOperationException();
040            }
041    
042            public boolean containsKey(Object key) {
043                    throw new UnsupportedOperationException();
044            }
045    
046            public boolean containsValue(Object value) {
047                    throw new UnsupportedOperationException();
048            }
049    
050            public boolean isEmpty() {
051                    throw new UnsupportedOperationException();
052            }
053    
054            public Set<Entry<String, String>> entrySet() {
055                    throw new UnsupportedOperationException();
056            }
057    
058            public String get(Object key) {
059                    String value = null;
060    
061                    if (key != null) {
062                            FacesContext facesContext = FacesContext.getCurrentInstance();
063    
064                            Locale locale = facesContext.getViewRoot().getLocale();
065    
066                            if (locale == null) {
067                                    locale = facesContext.getApplication().getDefaultLocale();
068                            }
069    
070                            value = LanguageUtil.get(locale, key.toString());
071    
072                            if (_log.isDebugEnabled()) {
073                                    _log.debug(
074                                            "{locale=" + locale + ", key=" + key + ", value=" + value);
075                            }
076                    }
077    
078                    return value;
079            }
080    
081            public Set<String> keySet() {
082                    throw new UnsupportedOperationException();
083            }
084    
085            public String put(String key, String value) {
086                    throw new UnsupportedOperationException();
087            }
088    
089            public void putAll(Map<? extends String, ? extends String> map) {
090                    throw new UnsupportedOperationException();
091            }
092    
093            public String remove(Object key) {
094                    throw new UnsupportedOperationException();
095            }
096    
097            public int size() {
098                    throw new UnsupportedOperationException();
099            }
100    
101            public Collection<String> values() {
102                    throw new UnsupportedOperationException();
103            }
104    
105            private static Log _log = LogFactoryUtil.getLog(LanguageManagedBean.class);
106    
107    }