001    /**
002     * Copyright (c) 2000-2012 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 CLASS_NAME = MBMessage.class.getName();
036    
037            public static final String TYPE = "message";
038    
039            public AssetRenderer getAssetRenderer(long classPK, int type)
040                    throws PortalException, SystemException {
041    
042                    MBMessage message = MBMessageLocalServiceUtil.getMessage(classPK);
043    
044                    return new MBMessageAssetRenderer(message);
045            }
046    
047            public String getClassName() {
048                    return CLASS_NAME;
049            }
050    
051            public String getType() {
052                    return TYPE;
053            }
054    
055            @Override
056            public boolean hasPermission(
057                            PermissionChecker permissionChecker, long classPK, String actionId)
058                    throws Exception {
059    
060                    return MBMessagePermission.contains(
061                            permissionChecker, classPK, actionId);
062            }
063    
064            @Override
065            public boolean isCategorizable() {
066                    return false;
067            }
068    
069            @Override
070            public boolean isLinkable() {
071                    return _LINKABLE;
072            }
073    
074            @Override
075            protected String getIconPath(ThemeDisplay themeDisplay) {
076                    return themeDisplay.getPathThemeImages() + "/common/conversation.png";
077            }
078    
079            private static final boolean _LINKABLE = true;
080    
081    }