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