001    /**
002     * Copyright (c) 2000-2010 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.LiferayPortletRequest;
020    import com.liferay.portal.kernel.portlet.LiferayPortletResponse;
021    import com.liferay.portal.security.permission.PermissionChecker;
022    import com.liferay.portal.theme.ThemeDisplay;
023    import com.liferay.portlet.asset.model.AssetRenderer;
024    import com.liferay.portlet.asset.model.BaseAssetRendererFactory;
025    import com.liferay.portlet.messageboards.model.MBMessage;
026    import com.liferay.portlet.messageboards.service.MBMessageLocalServiceUtil;
027    import com.liferay.portlet.messageboards.service.permission.MBMessagePermission;
028    
029    import javax.portlet.PortletURL;
030    
031    /**
032     * @author Julio Camarero
033     * @author Juan Fernández
034     * @author Raymond Augé
035     */
036    public class MBMessageAssetRendererFactory extends BaseAssetRendererFactory {
037    
038            public static final String CLASS_NAME = MBMessage.class.getName();
039    
040            public static final String TYPE = "message";
041    
042            public AssetRenderer getAssetRenderer(long classPK, int type)
043                    throws PortalException, SystemException {
044    
045                    MBMessage message = MBMessageLocalServiceUtil.getMessage(classPK);
046    
047                    return new MBMessageAssetRenderer(message);
048            }
049    
050            public String getClassName() {
051                    return CLASS_NAME;
052            }
053    
054            public String getType() {
055                    return TYPE;
056            }
057    
058            public PortletURL getURLAdd(
059                    LiferayPortletRequest liferayPortletRequest,
060                    LiferayPortletResponse liferayPortletResponse) {
061    
062                    return null;
063            }
064    
065            public boolean hasPermission(
066                            PermissionChecker permissionChecker, long classPK, String actionId)
067                    throws Exception {
068    
069                    return MBMessagePermission.contains(
070                            permissionChecker, classPK, actionId);
071            }
072    
073            protected String getIconPath(ThemeDisplay themeDisplay) {
074                    return themeDisplay.getPathThemeImages() + "/common/conversation.png";
075            }
076    
077    }