001    /**
002     * Copyright (c) 2000-2011 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
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    }