001    /**
002     * Copyright (c) 2000-2011 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
013     */
014    
015    package com.liferay.portlet.messageboards.asset;
016    
017    import com.liferay.portal.kernel.exception.PortalException;
018    import com.liferay.portal.kernel.exception.SystemException;
019    import com.liferay.portal.security.permission.PermissionChecker;
020    import com.liferay.portal.theme.ThemeDisplay;
021    import com.liferay.portlet.asset.model.AssetRenderer;
022    import com.liferay.portlet.asset.model.BaseAssetRendererFactory;
023    import com.liferay.portlet.messageboards.model.MBCategory;
024    import com.liferay.portlet.messageboards.service.MBCategoryLocalServiceUtil;
025    import com.liferay.portlet.messageboards.service.permission.MBCategoryPermission;
026    
027    /**
028     * @author Julio Camarero
029     * @author Juan Fernández
030     * @author Raymond Augé
031     * @author Sergio González
032     * @author Jonathan Lee
033     */
034    public class MBCategoryAssetRendererFactory extends BaseAssetRendererFactory {
035    
036            public static final String CLASS_NAME = MBCategory.class.getName();
037    
038            public static final String TYPE = "category";
039    
040            public AssetRenderer getAssetRenderer(long classPK, int type)
041                    throws PortalException, SystemException {
042    
043                    MBCategory category = MBCategoryLocalServiceUtil.getMBCategory(classPK);
044    
045                    return new MBCategoryAssetRenderer(category);
046            }
047    
048            public String getClassName() {
049                    return CLASS_NAME;
050            }
051    
052            public String getType() {
053                    return TYPE;
054            }
055    
056            @Override
057            public boolean hasPermission(
058                            PermissionChecker permissionChecker, long classPK, String actionId)
059                    throws Exception {
060    
061                    MBCategory category = MBCategoryLocalServiceUtil.getMBCategory(classPK);
062    
063                    return MBCategoryPermission.contains(
064                            permissionChecker, category, actionId);
065            }
066    
067            @Override
068            public boolean isCategorizable() {
069                    return false;
070            }
071    
072            @Override
073            protected String getIconPath(ThemeDisplay themeDisplay) {
074                    return themeDisplay.getPathThemeImages() + "/common/conversation.png";
075            }
076    
077    }