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