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.MBMessage;
026    import com.liferay.portlet.messageboards.service.MBMessageLocalServiceUtil;
027    import com.liferay.portlet.messageboards.service.permission.MBMessagePermission;
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     */
040    public class MBMessageAssetRendererFactory extends BaseAssetRendererFactory {
041    
042            public static final String TYPE = "message";
043    
044            public MBMessageAssetRendererFactory() {
045                    setCategorizable(false);
046                    setLinkable(true);
047            }
048    
049            @Override
050            public AssetRenderer getAssetRenderer(long classPK, int type)
051                    throws PortalException {
052    
053                    MBMessage message = MBMessageLocalServiceUtil.getMessage(classPK);
054    
055                    MBMessageAssetRenderer mbMessageAssetRenderer =
056                            new MBMessageAssetRenderer(message);
057    
058                    mbMessageAssetRenderer.setAssetRendererType(type);
059    
060                    return mbMessageAssetRenderer;
061            }
062    
063            @Override
064            public String getClassName() {
065                    return MBMessage.class.getName();
066            }
067    
068            @Override
069            public String getIconCssClass() {
070                    return "icon-comments";
071            }
072    
073            @Override
074            public String getType() {
075                    return TYPE;
076            }
077    
078            @Override
079            public PortletURL getURLView(
080                    LiferayPortletResponse liferayPortletResponse,
081                    WindowState windowState) {
082    
083                    LiferayPortletURL liferayPortletURL =
084                            liferayPortletResponse.createLiferayPortletURL(
085                                    PortletKeys.MESSAGE_BOARDS, PortletRequest.RENDER_PHASE);
086    
087                    try {
088                            liferayPortletURL.setWindowState(windowState);
089                    }
090                    catch (WindowStateException wse) {
091                    }
092    
093                    return liferayPortletURL;
094            }
095    
096            @Override
097            public boolean hasPermission(
098                            PermissionChecker permissionChecker, long classPK, String actionId)
099                    throws Exception {
100    
101                    return MBMessagePermission.contains(
102                            permissionChecker, classPK, actionId);
103            }
104    
105            @Override
106            protected String getIconPath(ThemeDisplay themeDisplay) {
107                    return themeDisplay.getPathThemeImages() + "/common/conversation.png";
108            }
109    
110    }