/** * 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.search; import com.liferay.message.boards.kernel.model.MBCategory; import com.liferay.message.boards.kernel.model.MBThread; import com.liferay.message.boards.kernel.service.MBCategoryLocalServiceUtil; import com.liferay.message.boards.kernel.service.MBThreadLocalServiceUtil; import com.liferay.portal.kernel.dao.search.EmptyOnClickRowChecker; import com.liferay.portal.kernel.dao.search.RowChecker; 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.theme.ThemeDisplay; import com.liferay.portal.kernel.util.GetterUtil; import com.liferay.portal.kernel.util.StringBundler; import com.liferay.portal.kernel.util.StringPool; import com.liferay.portal.kernel.util.WebKeys; import com.liferay.portlet.messageboards.service.permission.MBCategoryPermission; import com.liferay.portlet.messageboards.service.permission.MBMessagePermission; import javax.servlet.http.HttpServletRequest; /** * @author Sergio González */ public class EntriesChecker extends EmptyOnClickRowChecker { public EntriesChecker( LiferayPortletRequest liferayPortletRequest, LiferayPortletResponse liferayPortletResponse) { super(liferayPortletResponse); _liferayPortletResponse = liferayPortletResponse; ThemeDisplay themeDisplay = (ThemeDisplay)liferayPortletRequest.getAttribute( WebKeys.THEME_DISPLAY); _permissionChecker = themeDisplay.getPermissionChecker(); } @Override public String getAllRowsCheckBox() { return null; } @Override public String getAllRowsCheckBox(HttpServletRequest request) { return null; } @Override public String getRowCheckBox( HttpServletRequest request, boolean checked, boolean disabled, String primaryKey) { MBThread thread = null; long entryId = GetterUtil.getLong(primaryKey); MBCategory category = MBCategoryLocalServiceUtil.fetchMBCategory( entryId); if (category == null) { thread = MBThreadLocalServiceUtil.fetchThread(entryId); } if ((category == null) && (thread == null)) { return StringPool.BLANK; } boolean showInput = false; String name = null; if (category != null) { name = MBCategory.class.getSimpleName(); try { if (MBCategoryPermission.contains( _permissionChecker, category, ActionKeys.DELETE)) { showInput = true; } } catch (Exception e) { } } else { name = MBThread.class.getSimpleName(); try { if (MBCategoryPermission.contains( _permissionChecker, thread.getGroupId(), thread.getCategoryId(), ActionKeys.LOCK_THREAD) || MBMessagePermission.contains( _permissionChecker, thread.getRootMessageId(), ActionKeys.DELETE)) { showInput = true; } } catch (Exception e) { } } if (!showInput) { return StringPool.BLANK; } String checkBoxRowIds = getEntryRowIds(); return getRowCheckBox( request, checked, disabled, _liferayPortletResponse.getNamespace() + RowChecker.ROW_IDS + name, primaryKey, checkBoxRowIds, "'#" + getAllRowIds() + "'", StringPool.BLANK); } protected String getEntryRowIds() { StringBundler sb = new StringBundler(9); sb.append("['"); sb.append(_liferayPortletResponse.getNamespace()); sb.append(RowChecker.ROW_IDS); sb.append(MBCategory.class.getSimpleName()); sb.append("', '"); sb.append(_liferayPortletResponse.getNamespace()); sb.append(RowChecker.ROW_IDS); sb.append(MBThread.class.getSimpleName()); sb.append("']"); return sb.toString(); } private final LiferayPortletResponse _liferayPortletResponse; private final PermissionChecker _permissionChecker; }