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 TYPE = "user";
039    
040            @Override
041            public AssetRenderer getAssetRenderer(long classPK, int type)
042                    throws PortalException, SystemException {
043    
044                    User user = UserLocalServiceUtil.getUserById(classPK);
045    
046                    UserAssetRenderer userAssetRenderer = new UserAssetRenderer(user);
047    
048                    userAssetRenderer.setAssetRendererType(type);
049    
050                    return userAssetRenderer;
051            }
052    
053            @Override
054            public AssetRenderer getAssetRenderer(long groupId, String urlTitle)
055                    throws PortalException, SystemException {
056    
057                    Group group = GroupLocalServiceUtil.getGroup(groupId);
058    
059                    User user = UserLocalServiceUtil.getUserByScreenName(
060                            group.getCompanyId(), urlTitle);
061    
062                    return new UserAssetRenderer(user);
063            }
064    
065            @Override
066            public String getClassName() {
067                    return User.class.getName();
068            }
069    
070            @Override
071            public String getType() {
072                    return TYPE;
073            }
074    
075            @Override
076            public PortletURL getURLAdd(
077                    LiferayPortletRequest liferayPortletRequest,
078                    LiferayPortletResponse liferayPortletResponse) {
079    
080                    return null;
081            }
082    
083            @Override
084            public boolean hasPermission(
085                            PermissionChecker permissionChecker, long classPK, String actionId)
086                    throws Exception {
087    
088                    return UserPermissionUtil.contains(
089                            permissionChecker, classPK, actionId);
090            }
091    
092            @Override
093            public boolean isSelectable() {
094                    return _SELECTABLE;
095            }
096    
097            @Override
098            protected String getIconPath(ThemeDisplay themeDisplay) {
099                    return themeDisplay.getPathThemeImages() + "/common/user_icon.png";
100            }
101    
102            private static final boolean _SELECTABLE = false;
103    
104    }