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