/**
* 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.MBCategory;
import com.liferay.message.boards.kernel.service.MBCategoryLocalService;
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.MBCategoryPermission;
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
* @author Jonathan Lee
*/
@Component(
immediate = true,
property = {"javax.portlet.name=" + MBPortletKeys.MESSAGE_BOARDS},
service = AssetRendererFactory.class
)
public class MBCategoryAssetRendererFactory
extends BaseAssetRendererFactory<MBCategory> {
public static final String TYPE = "category";
public MBCategoryAssetRendererFactory() {
setCategorizable(false);
setPortletId(MBPortletKeys.MESSAGE_BOARDS);
setSelectable(false);
}
@Override
public AssetRenderer<MBCategory> getAssetRenderer(long classPK, int type)
throws PortalException {
MBCategory category = _mbCategoryLocalService.getMBCategory(classPK);
MBCategoryAssetRenderer mbCategoryAssetRenderer =
new MBCategoryAssetRenderer(category);
mbCategoryAssetRenderer.setAssetRendererType(type);
return mbCategoryAssetRenderer;
}
@Override
public String getClassName() {
return MBCategory.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 {
MBCategory category = _mbCategoryLocalService.getMBCategory(classPK);
return MBCategoryPermission.contains(
permissionChecker, category, actionId);
}
@Reference(unbind = "-")
protected void setMBCategoryLocalService(
MBCategoryLocalService mbCategoryLocalService) {
_mbCategoryLocalService = mbCategoryLocalService;
}
private MBCategoryLocalService _mbCategoryLocalService;
}