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.portlet.directory.asset;
016    
017    import com.liferay.portal.kernel.portlet.LiferayPortletRequest;
018    import com.liferay.portal.kernel.portlet.LiferayPortletResponse;
019    import com.liferay.portal.model.User;
020    import com.liferay.portal.security.permission.ActionKeys;
021    import com.liferay.portal.security.permission.PermissionChecker;
022    import com.liferay.portal.service.permission.UserPermissionUtil;
023    import com.liferay.portal.theme.ThemeDisplay;
024    import com.liferay.portal.util.PortletKeys;
025    import com.liferay.portal.util.WebKeys;
026    import com.liferay.portlet.asset.model.BaseAssetRenderer;
027    
028    import java.util.Locale;
029    
030    import javax.portlet.PortletRequest;
031    import javax.portlet.PortletURL;
032    import javax.portlet.RenderRequest;
033    import javax.portlet.RenderResponse;
034    
035    /**
036     * @author Michael C. Han
037     * @author Sergio Gonz??lez
038     */
039    public class UserAssetRenderer extends BaseAssetRenderer {
040    
041            public UserAssetRenderer(User user) {
042                    _user = user;
043            }
044    
045            @Override
046            public long getClassPK() {
047                    return _user.getPrimaryKey();
048            }
049    
050            @Override
051            public String getDiscussionPath() {
052                    return null;
053            }
054    
055            @Override
056            public long getGroupId() {
057                    return 0;
058            }
059    
060            @Override
061            public String getSummary(Locale locale) {
062                    return _user.getComments();
063            }
064    
065            @Override
066            public String getTitle(Locale locale) {
067                    return _user.getFullName();
068            }
069    
070            @Override
071            public PortletURL getURLEdit(
072                            LiferayPortletRequest liferayPortletRequest,
073                            LiferayPortletResponse liferayPortletResponse)
074                    throws Exception {
075    
076                    PortletURL portletURL = liferayPortletResponse.createLiferayPortletURL(
077                            getControlPanelPlid(liferayPortletRequest), PortletKeys.USERS_ADMIN,
078                            PortletRequest.RENDER_PHASE);
079    
080                    portletURL.setParameter("struts_action", "/users_admin/edit_user");
081                    portletURL.setParameter("p_u_i_d", String.valueOf(_user.getUserId()));
082    
083                    return portletURL;
084            }
085    
086            @Override
087            public String getUrlTitle() {
088                    return _user.getScreenName();
089            }
090    
091            @Override
092            public String getURLViewInContext(
093                    LiferayPortletRequest liferayPortletRequest,
094                    LiferayPortletResponse liferayPortletResponse,
095                    String noSuchEntryRedirect) {
096    
097                    return getURLViewInContext(
098                            liferayPortletRequest, noSuchEntryRedirect, "/directory/find_user",
099                            "p_u_i_d", _user.getUserId());
100            }
101    
102            @Override
103            public long getUserId() {
104                    return _user.getUserId();
105            }
106    
107            @Override
108            public String getUserName() {
109                    return _user.getFullName();
110            }
111    
112            @Override
113            public String getUuid() {
114                    return _user.getUuid();
115            }
116    
117            @Override
118            public boolean hasEditPermission(PermissionChecker permissionChecker) {
119                    return UserPermissionUtil.contains(
120                            permissionChecker, _user.getUserId(), ActionKeys.UPDATE);
121            }
122    
123            @Override
124            public boolean hasViewPermission(PermissionChecker permissionChecker) {
125                    return UserPermissionUtil.contains(
126                            permissionChecker, _user.getUserId(), ActionKeys.VIEW);
127            }
128    
129            @Override
130            public boolean isPrintable() {
131                    return false;
132            }
133    
134            @Override
135            public String render(
136                            RenderRequest renderRequest, RenderResponse renderResponse,
137                            String template)
138                    throws Exception {
139    
140                    if (template.equals(TEMPLATE_ABSTRACT) ||
141                            template.equals(TEMPLATE_FULL_CONTENT)) {
142    
143                            renderRequest.setAttribute(WebKeys.USER, _user);
144    
145                            return "/html/portlet/directory/asset/abstract.jsp";
146                    }
147                    else {
148                            return null;
149                    }
150            }
151    
152            @Override
153            protected String getIconPath(ThemeDisplay themeDisplay) {
154                    return themeDisplay.getPathThemeImages() + "/common/user_icon.png";
155            }
156    
157            private User _user;
158    
159    }