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.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 TYPE = "category";
037    
038            @Override
039            public AssetRenderer getAssetRenderer(long classPK, int type)
040                    throws PortalException, SystemException {
041    
042                    MBCategory category = MBCategoryLocalServiceUtil.getMBCategory(classPK);
043    
044                    MBCategoryAssetRenderer mbCategoryAssetRenderer =
045                            new MBCategoryAssetRenderer(category);
046    
047                    mbCategoryAssetRenderer.setAssetRendererType(type);
048    
049                    return mbCategoryAssetRenderer;
050            }
051    
052            @Override
053            public String getClassName() {
054                    return MBCategory.class.getName();
055            }
056    
057            @Override
058            public String getType() {
059                    return TYPE;
060            }
061    
062            @Override
063            public boolean hasPermission(
064                            PermissionChecker permissionChecker, long classPK, String actionId)
065                    throws Exception {
066    
067                    MBCategory category = MBCategoryLocalServiceUtil.getMBCategory(classPK);
068    
069                    return MBCategoryPermission.contains(
070                            permissionChecker, category, actionId);
071            }
072    
073            @Override
074            public boolean isCategorizable() {
075                    return false;
076            }
077    
078            @Override
079            public boolean isSelectable() {
080                    return _SELECTABLE;
081            }
082    
083            @Override
084            protected String getIconPath(ThemeDisplay themeDisplay) {
085                    return themeDisplay.getPathThemeImages() + "/common/conversation.png";
086            }
087    
088            private static final boolean _SELECTABLE = false;
089    
090    }