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