/** * 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.AssetRendererFactory; import com.liferay.asset.kernel.model.BaseJSPAssetRenderer; import com.liferay.message.boards.kernel.model.MBCategory; import com.liferay.message.boards.web.constants.MBPortletKeys; import com.liferay.portal.kernel.exception.PortalException; import com.liferay.portal.kernel.model.Group; import com.liferay.portal.kernel.portlet.LiferayPortletRequest; import com.liferay.portal.kernel.portlet.LiferayPortletResponse; import com.liferay.portal.kernel.security.permission.ActionKeys; import com.liferay.portal.kernel.security.permission.PermissionChecker; import com.liferay.portal.kernel.service.GroupLocalServiceUtil; import com.liferay.portal.kernel.util.PortalUtil; import com.liferay.portal.kernel.util.WebKeys; import com.liferay.portlet.messageboards.service.permission.MBCategoryPermission; import java.util.Locale; import javax.portlet.PortletRequest; import javax.portlet.PortletResponse; import javax.portlet.PortletURL; import javax.portlet.WindowState; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; /** * @author Julio Camarero * @author Juan Fernández * @author Sergio González * @author Jonathan Lee */ public class MBCategoryAssetRenderer extends BaseJSPAssetRenderer<MBCategory> { public MBCategoryAssetRenderer(MBCategory category) { _category = category; } @Override public MBCategory getAssetObject() { return _category; } @Override public String getClassName() { return MBCategory.class.getName(); } @Override public long getClassPK() { return _category.getCategoryId(); } @Override public long getGroupId() { return _category.getGroupId(); } @Override public String getJspPath(HttpServletRequest request, String template) { if (template.equals(TEMPLATE_ABSTRACT) || template.equals(TEMPLATE_FULL_CONTENT)) { return "/message_boards/asset/" + template + ".jsp"; } else { return null; } } @Override public int getStatus() { return _category.getStatus(); } @Override public String getSummary( PortletRequest portletRequest, PortletResponse portletResponse) { return _category.getDescription(); } @Override public String getTitle(Locale locale) { return _category.getName(); } @Override public PortletURL getURLEdit( LiferayPortletRequest liferayPortletRequest, LiferayPortletResponse liferayPortletResponse) throws Exception { Group group = GroupLocalServiceUtil.fetchGroup(_category.getGroupId()); PortletURL portletURL = PortalUtil.getControlPanelPortletURL( liferayPortletRequest, group, MBPortletKeys.MESSAGE_BOARDS, 0, 0, PortletRequest.RENDER_PHASE); portletURL.setParameter( "mvcRenderCommandName", "/message_boards/edit_category"); portletURL.setParameter( "mbCategoryId", String.valueOf(_category.getCategoryId())); return portletURL; } @Override public String getURLView( LiferayPortletResponse liferayPortletResponse, WindowState windowState) throws Exception { AssetRendererFactory<MBCategory> assetRendererFactory = getAssetRendererFactory(); PortletURL portletURL = assetRendererFactory.getURLView( liferayPortletResponse, windowState); portletURL.setParameter( "mvcRenderCommandName", "/message_boards/view_category"); portletURL.setParameter( "mbCategoryId", String.valueOf(_category.getCategoryId())); portletURL.setWindowState(windowState); return portletURL.toString(); } @Override public String getURLViewInContext( LiferayPortletRequest liferayPortletRequest, LiferayPortletResponse liferayPortletResponse, String noSuchEntryRedirect) { return getURLViewInContext( liferayPortletRequest, noSuchEntryRedirect, "/message_boards/find_category", "mbCategoryId", _category.getCategoryId()); } @Override public long getUserId() { return _category.getUserId(); } @Override public String getUserName() { return _category.getUserName(); } @Override public String getUuid() { return _category.getUuid(); } @Override public boolean hasEditPermission(PermissionChecker permissionChecker) throws PortalException { return MBCategoryPermission.contains( permissionChecker, _category, ActionKeys.UPDATE); } @Override public boolean hasViewPermission(PermissionChecker permissionChecker) throws PortalException { return MBCategoryPermission.contains( permissionChecker, _category, ActionKeys.VIEW); } @Override public boolean include( HttpServletRequest request, HttpServletResponse response, String template) throws Exception { request.setAttribute(WebKeys.MESSAGE_BOARDS_CATEGORY, _category); return super.include(request, response, template); } private final MBCategory _category; }