001    /**
002     * Copyright (c) 2000-2012 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            public String getAssetRendererFactoryClassName() {
046                    return UserAssetRendererFactory.CLASS_NAME;
047            }
048    
049            public long getClassPK() {
050                    return _user.getPrimaryKey();
051            }
052    
053            @Override
054            public String getDiscussionPath() {
055                    return null;
056            }
057    
058            public long getGroupId() {
059                    return 0;
060            }
061    
062            public String getSummary(Locale locale) {
063                    return _user.getComments();
064            }
065    
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            public long getUserId() {
103                    return _user.getUserId();
104            }
105    
106            public String getUserName() {
107                    return _user.getFullName();
108            }
109    
110            public String getUuid() {
111                    return _user.getUuid();
112            }
113    
114            @Override
115            public boolean hasEditPermission(PermissionChecker permissionChecker) {
116                    return UserPermissionUtil.contains(
117                            permissionChecker, _user.getUserId(), ActionKeys.UPDATE);
118            }
119    
120            @Override
121            public boolean hasViewPermission(PermissionChecker permissionChecker) {
122                    return UserPermissionUtil.contains(
123                            permissionChecker, _user.getUserId(), ActionKeys.VIEW);
124            }
125    
126            @Override
127            public boolean isPrintable() {
128                    return false;
129            }
130    
131            public String render(
132                            RenderRequest renderRequest, RenderResponse renderResponse,
133                            String template)
134                    throws Exception {
135    
136                    if (template.equals(TEMPLATE_ABSTRACT) ||
137                            template.equals(TEMPLATE_FULL_CONTENT)) {
138    
139                            renderRequest.setAttribute(WebKeys.USER, _user);
140    
141                            return "/html/portlet/directory/asset/abstract.jsp";
142                    }
143                    else {
144                            return null;
145                    }
146            }
147    
148            @Override
149            protected String getIconPath(ThemeDisplay themeDisplay) {
150                    return themeDisplay.getPathThemeImages() + "/common/user_icon.png";
151            }
152    
153            private User _user;
154    
155    }