001    /**
002     * Copyright (c) 2000-2013 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
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 int getStatus() {
067                    return _user.getStatus();
068            }
069    
070            @Override
071            public String getSummary(Locale locale) {
072                    return _user.getComments();
073            }
074    
075            @Override
076            public String getTitle(Locale locale) {
077                    return _user.getFullName();
078            }
079    
080            @Override
081            public PortletURL getURLEdit(
082                            LiferayPortletRequest liferayPortletRequest,
083                            LiferayPortletResponse liferayPortletResponse)
084                    throws Exception {
085    
086                    PortletURL portletURL = liferayPortletResponse.createLiferayPortletURL(
087                            getControlPanelPlid(liferayPortletRequest), PortletKeys.USERS_ADMIN,
088                            PortletRequest.RENDER_PHASE);
089    
090                    portletURL.setParameter("struts_action", "/users_admin/edit_user");
091                    portletURL.setParameter("p_u_i_d", String.valueOf(_user.getUserId()));
092    
093                    return portletURL;
094            }
095    
096            @Override
097            public String getUrlTitle() {
098                    return _user.getScreenName();
099            }
100    
101            @Override
102            public String getURLViewInContext(
103                    LiferayPortletRequest liferayPortletRequest,
104                    LiferayPortletResponse liferayPortletResponse,
105                    String noSuchEntryRedirect) {
106    
107                    ThemeDisplay themeDisplay =
108                            (ThemeDisplay)liferayPortletRequest.getAttribute(
109                                    WebKeys.THEME_DISPLAY);
110    
111                    try {
112                            return _user.getDisplayURL(themeDisplay);
113                    }
114                    catch (Exception e) {
115                    }
116    
117                    return noSuchEntryRedirect;
118            }
119    
120            @Override
121            public long getUserId() {
122                    return _user.getUserId();
123            }
124    
125            @Override
126            public String getUserName() {
127                    return _user.getFullName();
128            }
129    
130            @Override
131            public String getUuid() {
132                    return _user.getUuid();
133            }
134    
135            @Override
136            public boolean hasEditPermission(PermissionChecker permissionChecker) {
137                    return UserPermissionUtil.contains(
138                            permissionChecker, _user.getUserId(), ActionKeys.UPDATE);
139            }
140    
141            @Override
142            public boolean hasViewPermission(PermissionChecker permissionChecker) {
143                    return UserPermissionUtil.contains(
144                            permissionChecker, _user.getUserId(), ActionKeys.VIEW);
145            }
146    
147            @Override
148            public boolean isPrintable() {
149                    return false;
150            }
151    
152            @Override
153            public String render(
154                            RenderRequest renderRequest, RenderResponse renderResponse,
155                            String template)
156                    throws Exception {
157    
158                    if (template.equals(TEMPLATE_ABSTRACT) ||
159                            template.equals(TEMPLATE_FULL_CONTENT)) {
160    
161                            renderRequest.setAttribute(WebKeys.USER, _user);
162    
163                            return "/html/portlet/directory/asset/abstract.jsp";
164                    }
165                    else {
166                            return null;
167                    }
168            }
169    
170            @Override
171            protected String getIconPath(ThemeDisplay themeDisplay) {
172                    return themeDisplay.getPathThemeImages() + "/common/user_icon.png";
173            }
174    
175            private User _user;
176    
177    }