/** * Copyright (c) 2000-present Liferay, Inc. All rights reserved. * * This library is free software; you can redistribute it and/or modify it under * the terms of the GNU Lesser General Public License as published by the Free * Software Foundation; either version 2.1 of the License, or (at your option) * any later version. * * This library is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more * details. */ package com.liferay.message.boards.web.internal.asset; import com.liferay.asset.kernel.model.AssetRenderer; import com.liferay.asset.kernel.model.AssetRendererFactory; import com.liferay.asset.kernel.model.BaseAssetRendererFactory; import com.liferay.message.boards.kernel.model.MBMessage; import com.liferay.message.boards.kernel.service.MBMessageLocalService; import com.liferay.message.boards.web.constants.MBPortletKeys; import com.liferay.portal.kernel.exception.PortalException; import com.liferay.portal.kernel.portlet.LiferayPortletResponse; import com.liferay.portal.kernel.portlet.LiferayPortletURL; import com.liferay.portal.kernel.security.permission.PermissionChecker; import com.liferay.portlet.messageboards.service.permission.MBMessagePermission; import javax.portlet.PortletRequest; import javax.portlet.PortletURL; import javax.portlet.WindowState; import javax.portlet.WindowStateException; import org.osgi.service.component.annotations.Component; import org.osgi.service.component.annotations.Reference; /** * @author Julio Camarero * @author Juan Fernández * @author Raymond Augé * @author Sergio González */ @Component( immediate = true, property = {"javax.portlet.name=" + MBPortletKeys.MESSAGE_BOARDS}, service = AssetRendererFactory.class ) public class MBMessageAssetRendererFactory extends BaseAssetRendererFactory<MBMessage> { public static final String TYPE = "message"; public MBMessageAssetRendererFactory() { setCategorizable(false); setLinkable(true); setPortletId(MBPortletKeys.MESSAGE_BOARDS); setSearchable(true); } @Override public AssetRenderer<MBMessage> getAssetRenderer(long classPK, int type) throws PortalException { MBMessage message = _mbMessageLocalService.getMessage(classPK); MBMessageAssetRenderer mbMessageAssetRenderer = new MBMessageAssetRenderer(message); mbMessageAssetRenderer.setAssetRendererType(type); return mbMessageAssetRenderer; } @Override public String getClassName() { return MBMessage.class.getName(); } @Override public String getIconCssClass() { return "comments"; } @Override public String getType() { return TYPE; } @Override public PortletURL getURLView( LiferayPortletResponse liferayPortletResponse, WindowState windowState) { LiferayPortletURL liferayPortletURL = liferayPortletResponse.createLiferayPortletURL( MBPortletKeys.MESSAGE_BOARDS, PortletRequest.RENDER_PHASE); try { liferayPortletURL.setWindowState(windowState); } catch (WindowStateException wse) { } return liferayPortletURL; } @Override public boolean hasPermission( PermissionChecker permissionChecker, long classPK, String actionId) throws Exception { return MBMessagePermission.contains( permissionChecker, classPK, actionId); } @Reference(unbind = "-") protected void setMBMessageLocalService( MBMessageLocalService mbMessageLocalService) { _mbMessageLocalService = mbMessageLocalService; } private MBMessageLocalService _mbMessageLocalService; }