001    /**
002     * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
013     */
014    
015    package com.liferay.util.bridges.jsf.common;
016    
017    import com.liferay.portal.kernel.log.Log;
018    import com.liferay.portal.kernel.log.LogFactoryUtil;
019    import com.liferay.portal.kernel.util.GetterUtil;
020    import com.liferay.portal.model.User;
021    import com.liferay.portal.service.UserLocalServiceUtil;
022    
023    import javax.faces.context.FacesContext;
024    
025    /**
026     * <p>
027     * This class is designed to be a convenient JSF managed bean that can be used
028     * to get portal related information (such as the user's time zone).
029     * </p>
030     *
031     * @author Neil Griffin
032     */
033    public class ThemeDisplayManagedBean {
034    
035            public User getUser() {
036                    FacesContext facesContext = FacesContext.getCurrentInstance();
037    
038                    String remoteUser = facesContext.getExternalContext().getRemoteUser();
039    
040                    try {
041                            long userId = GetterUtil.getLong(remoteUser);
042    
043                            return UserLocalServiceUtil.getUserById(userId);
044                    }
045                    catch (Exception e) {
046                            _log.error(e, e);
047                    }
048    
049                    return null;
050            }
051    
052            private static Log _log = LogFactoryUtil.getLog(User.class);
053    
054    }