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