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