001    /**
002     * Copyright (c) 2000-present 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.portlet.LiferayPortletResponse;
019    import com.liferay.portal.kernel.portlet.LiferayPortletURL;
020    import com.liferay.portal.security.permission.PermissionChecker;
021    import com.liferay.portal.theme.ThemeDisplay;
022    import com.liferay.portal.util.PortletKeys;
023    import com.liferay.portlet.asset.model.AssetRenderer;
024    import com.liferay.portlet.asset.model.BaseAssetRendererFactory;
025    import com.liferay.portlet.messageboards.model.MBCategory;
026    import com.liferay.portlet.messageboards.service.MBCategoryLocalServiceUtil;
027    import com.liferay.portlet.messageboards.service.permission.MBCategoryPermission;
028    
029    import javax.portlet.PortletRequest;
030    import javax.portlet.PortletURL;
031    import javax.portlet.WindowState;
032    import javax.portlet.WindowStateException;
033    
034    /**
035     * @author Julio Camarero
036     * @author Juan Fern??ndez
037     * @author Raymond Aug??
038     * @author Sergio Gonz??lez
039     * @author Jonathan Lee
040     */
041    public class MBCategoryAssetRendererFactory extends BaseAssetRendererFactory {
042    
043            public static final String TYPE = "category";
044    
045            public MBCategoryAssetRendererFactory() {
046                    setCategorizable(false);
047                    setSelectable(false);
048            }
049    
050            @Override
051            public AssetRenderer getAssetRenderer(long classPK, int type)
052                    throws PortalException {
053    
054                    MBCategory category = MBCategoryLocalServiceUtil.getMBCategory(classPK);
055    
056                    MBCategoryAssetRenderer mbCategoryAssetRenderer =
057                            new MBCategoryAssetRenderer(category);
058    
059                    mbCategoryAssetRenderer.setAssetRendererType(type);
060    
061                    return mbCategoryAssetRenderer;
062            }
063    
064            @Override
065            public String getClassName() {
066                    return MBCategory.class.getName();
067            }
068    
069            @Override
070            public String getIconCssClass() {
071                    return "icon-comments";
072            }
073    
074            @Override
075            public String getType() {
076                    return TYPE;
077            }
078    
079            @Override
080            public PortletURL getURLView(
081                    LiferayPortletResponse liferayPortletResponse,
082                    WindowState windowState) {
083    
084                    LiferayPortletURL liferayPortletURL =
085                            liferayPortletResponse.createLiferayPortletURL(
086                                    PortletKeys.MESSAGE_BOARDS, PortletRequest.RENDER_PHASE);
087    
088                    try {
089                            liferayPortletURL.setWindowState(windowState);
090                    }
091                    catch (WindowStateException wse) {
092                    }
093    
094                    return liferayPortletURL;
095            }
096    
097            @Override
098            public boolean hasPermission(
099                            PermissionChecker permissionChecker, long classPK, String actionId)
100                    throws Exception {
101    
102                    MBCategory category = MBCategoryLocalServiceUtil.getMBCategory(classPK);
103    
104                    return MBCategoryPermission.contains(
105                            permissionChecker, category, actionId);
106            }
107    
108            @Override
109            protected String getIconPath(ThemeDisplay themeDisplay) {
110                    return themeDisplay.getPathThemeImages() + "/common/conversation.png";
111            }
112    
113    }