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 String getClassName() {
047                    return User.class.getName();
048            }
049    
050            @Override
051            public long getClassPK() {
052                    return _user.getPrimaryKey();
053            }
054    
055            @Override
056            public String getDiscussionPath() {
057                    return null;
058            }
059    
060            @Override
061            public long getGroupId() {
062                    return 0;
063            }
064    
065            @Override
066            public String getSummary(Locale locale) {
067                    return _user.getComments();
068            }
069    
070            @Override
071            public String getTitle(Locale locale) {
072                    return _user.getFullName();
073            }
074    
075            @Override
076            public PortletURL getURLEdit(
077                            LiferayPortletRequest liferayPortletRequest,
078                            LiferayPortletResponse liferayPortletResponse)
079                    throws Exception {
080    
081                    PortletURL portletURL = liferayPortletResponse.createLiferayPortletURL(
082                            getControlPanelPlid(liferayPortletRequest), PortletKeys.USERS_ADMIN,
083                            PortletRequest.RENDER_PHASE);
084    
085                    portletURL.setParameter("struts_action", "/users_admin/edit_user");
086                    portletURL.setParameter("p_u_i_d", String.valueOf(_user.getUserId()));
087    
088                    return portletURL;
089            }
090    
091            @Override
092            public String getUrlTitle() {
093                    return _user.getScreenName();
094            }
095    
096            @Override
097            public String getURLViewInContext(
098                    LiferayPortletRequest liferayPortletRequest,
099                    LiferayPortletResponse liferayPortletResponse,
100                    String noSuchEntryRedirect) {
101    
102                    return getURLViewInContext(
103                            liferayPortletRequest, noSuchEntryRedirect, "/directory/find_user",
104                            "p_u_i_d", _user.getUserId());
105            }
106    
107            @Override
108            public long getUserId() {
109                    return _user.getUserId();
110            }
111    
112            @Override
113            public String getUserName() {
114                    return _user.getFullName();
115            }
116    
117            @Override
118            public String getUuid() {
119                    return _user.getUuid();
120            }
121    
122            @Override
123            public boolean hasEditPermission(PermissionChecker permissionChecker) {
124                    return UserPermissionUtil.contains(
125                            permissionChecker, _user.getUserId(), ActionKeys.UPDATE);
126            }
127    
128            @Override
129            public boolean hasViewPermission(PermissionChecker permissionChecker) {
130                    return UserPermissionUtil.contains(
131                            permissionChecker, _user.getUserId(), ActionKeys.VIEW);
132            }
133    
134            @Override
135            public boolean isPrintable() {
136                    return false;
137            }
138    
139            @Override
140            public String render(
141                            RenderRequest renderRequest, RenderResponse renderResponse,
142                            String template)
143                    throws Exception {
144    
145                    if (template.equals(TEMPLATE_ABSTRACT) ||
146                            template.equals(TEMPLATE_FULL_CONTENT)) {
147    
148                            renderRequest.setAttribute(WebKeys.USER, _user);
149    
150                            return "/html/portlet/directory/asset/abstract.jsp";
151                    }
152                    else {
153                            return null;
154                    }
155            }
156    
157            @Override
158            protected String getIconPath(ThemeDisplay themeDisplay) {
159                    return themeDisplay.getPathThemeImages() + "/common/user_icon.png";
160            }
161    
162            private User _user;
163    
164    }