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