001    /**
002     * Copyright (c) 2000-present 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.exception.PortalException;
018    import com.liferay.portal.kernel.portlet.LiferayPortletRequest;
019    import com.liferay.portal.kernel.portlet.LiferayPortletResponse;
020    import com.liferay.portal.model.Group;
021    import com.liferay.portal.model.User;
022    import com.liferay.portal.security.permission.PermissionChecker;
023    import com.liferay.portal.service.GroupLocalServiceUtil;
024    import com.liferay.portal.service.UserLocalServiceUtil;
025    import com.liferay.portal.service.permission.UserPermissionUtil;
026    import com.liferay.portal.theme.ThemeDisplay;
027    import com.liferay.portlet.asset.model.AssetRenderer;
028    import com.liferay.portlet.asset.model.BaseAssetRendererFactory;
029    
030    import javax.portlet.PortletURL;
031    
032    /**
033     * @author Michael C. Han
034     */
035    public class UserAssetRendererFactory extends BaseAssetRendererFactory {
036    
037            public static final String TYPE = "user";
038    
039            public UserAssetRendererFactory() {
040                    setSelectable(false);
041            }
042    
043            @Override
044            public AssetRenderer getAssetRenderer(long classPK, int type)
045                    throws PortalException {
046    
047                    User user = UserLocalServiceUtil.getUserById(classPK);
048    
049                    UserAssetRenderer userAssetRenderer = new UserAssetRenderer(user);
050    
051                    userAssetRenderer.setAssetRendererType(type);
052    
053                    return userAssetRenderer;
054            }
055    
056            @Override
057            public AssetRenderer getAssetRenderer(long groupId, String urlTitle)
058                    throws PortalException {
059    
060                    Group group = GroupLocalServiceUtil.getGroup(groupId);
061    
062                    User user = UserLocalServiceUtil.getUserByScreenName(
063                            group.getCompanyId(), urlTitle);
064    
065                    return new UserAssetRenderer(user);
066            }
067    
068            @Override
069            public String getClassName() {
070                    return User.class.getName();
071            }
072    
073            @Override
074            public String getIconCssClass() {
075                    return "icon-user";
076            }
077    
078            @Override
079            public String getType() {
080                    return TYPE;
081            }
082    
083            @Override
084            public PortletURL getURLAdd(
085                    LiferayPortletRequest liferayPortletRequest,
086                    LiferayPortletResponse liferayPortletResponse) {
087    
088                    return null;
089            }
090    
091            @Override
092            public boolean hasPermission(
093                            PermissionChecker permissionChecker, long classPK, String actionId)
094                    throws Exception {
095    
096                    return UserPermissionUtil.contains(
097                            permissionChecker, classPK, actionId);
098            }
099    
100            @Override
101            protected String getIconPath(ThemeDisplay themeDisplay) {
102                    return themeDisplay.getPathThemeImages() + "/common/user_icon.png";
103            }
104    
105    }