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.security.permission.PermissionChecker;
020    import com.liferay.portal.theme.ThemeDisplay;
021    import com.liferay.portlet.asset.model.AssetRenderer;
022    import com.liferay.portlet.asset.model.BaseAssetRendererFactory;
023    import com.liferay.portlet.messageboards.model.MBMessage;
024    import com.liferay.portlet.messageboards.service.MBMessageLocalServiceUtil;
025    import com.liferay.portlet.messageboards.service.permission.MBMessagePermission;
026    
027    /**
028     * @author Julio Camarero
029     * @author Juan Fern??ndez
030     * @author Raymond Aug??
031     * @author Sergio Gonz??lez
032     */
033    public class MBMessageAssetRendererFactory extends BaseAssetRendererFactory {
034    
035            public static final String TYPE = "message";
036    
037            @Override
038            public AssetRenderer getAssetRenderer(long classPK, int type)
039                    throws PortalException, SystemException {
040    
041                    MBMessage message = MBMessageLocalServiceUtil.getMessage(classPK);
042    
043                    MBMessageAssetRenderer mbMessageAssetRenderer =
044                            new MBMessageAssetRenderer(message);
045    
046                    mbMessageAssetRenderer.setAssetRendererType(type);
047    
048                    return mbMessageAssetRenderer;
049            }
050    
051            @Override
052            public String getClassName() {
053                    return MBMessage.class.getName();
054            }
055    
056            @Override
057            public String getType() {
058                    return TYPE;
059            }
060    
061            @Override
062            public boolean hasPermission(
063                            PermissionChecker permissionChecker, long classPK, String actionId)
064                    throws Exception {
065    
066                    return MBMessagePermission.contains(
067                            permissionChecker, classPK, actionId);
068            }
069    
070            @Override
071            public boolean isCategorizable() {
072                    return false;
073            }
074    
075            @Override
076            public boolean isLinkable() {
077                    return _LINKABLE;
078            }
079    
080            @Override
081            protected String getIconPath(ThemeDisplay themeDisplay) {
082                    return themeDisplay.getPathThemeImages() + "/common/conversation.png";
083            }
084    
085            private static final boolean _LINKABLE = true;
086    
087    }