001    /**
002     * Copyright (c) 2000-2013 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.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(
053                    ThemeDisplayManagedBean.class);
054    
055    }