001    /**
002     * Copyright (c) 2000-present 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.taglib.ui;
016    
017    import com.liferay.portal.kernel.exception.PortalException;
018    import com.liferay.portal.kernel.log.Log;
019    import com.liferay.portal.kernel.log.LogFactoryUtil;
020    import com.liferay.portal.model.Contact;
021    import com.liferay.portal.model.User;
022    import com.liferay.portal.util.PortalUtil;
023    import com.liferay.taglib.util.IncludeTag;
024    
025    import javax.servlet.http.HttpServletRequest;
026    
027    /**
028     * @author Pei-Jung Lan
029     */
030    public class UserNameFieldsTag extends IncludeTag {
031    
032            public void setBean(Object bean) {
033                    _bean = bean;
034            }
035    
036            public void setContact(Contact contact) {
037                    _contact = contact;
038            }
039    
040            public void setUser(User user) {
041                    _user = user;
042            }
043    
044            @Override
045            protected void cleanUp() {
046                    _bean = null;
047                    _contact = null;
048                    _user = null;
049            }
050    
051            @Override
052            protected String getPage() {
053                    return _PAGE;
054            }
055    
056            protected User getUser() {
057                    if (_user == null) {
058                            try {
059                                    return PortalUtil.getSelectedUser(request);
060                            }
061                            catch (PortalException pe) {
062                                    _log.error(pe, pe);
063                            }
064                    }
065    
066                    return _user;
067            }
068    
069            @Override
070            protected void setAttributes(HttpServletRequest request) {
071                    if (_bean == null) {
072                            _bean = pageContext.getAttribute("aui:model-context:bean");
073                    }
074    
075                    request.setAttribute("liferay-ui:user-name-fields:bean", _bean);
076                    request.setAttribute("liferay-ui:user-name-fields:contact", _contact);
077                    request.setAttribute("liferay-ui:user-name-fields:user", getUser());
078            }
079    
080            private static final String _PAGE =
081                    "/html/taglib/ui/user_name_fields/page.jsp";
082    
083            private static final Log _log = LogFactoryUtil.getLog(
084                    UserNameFieldsTag.class);
085    
086            private Object _bean;
087            private Contact _contact;
088            private User _user;
089    
090    }