com.liferay.wiki.web.internal.search.PagesChecker Maven / Gradle / Ivy
/**
* SPDX-FileCopyrightText: (c) 2000 Liferay, Inc. https://liferay.com
* SPDX-License-Identifier: LGPL-2.1-or-later OR LicenseRef-Liferay-DXP-EULA-2.0.0-2023-06
*/
package com.liferay.wiki.web.internal.search;
import com.liferay.petra.string.StringBundler;
import com.liferay.petra.string.StringPool;
import com.liferay.portal.kernel.dao.search.EmptyOnClickRowChecker;
import com.liferay.portal.kernel.dao.search.RowChecker;
import com.liferay.portal.kernel.exception.PortalException;
import com.liferay.portal.kernel.log.Log;
import com.liferay.portal.kernel.log.LogFactoryUtil;
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.WebKeys;
import com.liferay.wiki.model.WikiPage;
import com.liferay.wiki.service.WikiPageLocalServiceUtil;
import com.liferay.wiki.web.internal.security.permission.resource.WikiPagePermission;
import javax.servlet.http.HttpServletRequest;
/**
* @author Roberto Díaz
*/
public class PagesChecker extends EmptyOnClickRowChecker {
public PagesChecker(
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 httpServletRequest) {
return null;
}
@Override
public String getRowCheckBox(
HttpServletRequest httpServletRequest, boolean checked,
boolean disabled, String primaryKey) {
long pageId = GetterUtil.getLong(primaryKey);
WikiPage page = null;
try {
page = WikiPageLocalServiceUtil.getPageByPageId(pageId);
}
catch (PortalException portalException) {
// LPS-52675
if (_log.isDebugEnabled()) {
_log.debug(portalException);
}
return StringPool.BLANK;
}
boolean showInput = false;
try {
if (WikiPagePermission.contains(
_permissionChecker, page, ActionKeys.DELETE)) {
showInput = true;
}
}
catch (PortalException portalException) {
if (_log.isWarnEnabled()) {
_log.warn(portalException);
}
}
if (!showInput) {
return StringPool.BLANK;
}
StringBundler sb = new StringBundler(5);
sb.append("['");
sb.append(_liferayPortletResponse.getNamespace());
sb.append(RowChecker.ROW_IDS);
String name = WikiPage.class.getSimpleName();
sb.append(name);
sb.append("']");
String checkBoxRowIds = sb.toString();
return getRowCheckBox(
httpServletRequest, checked, disabled,
StringBundler.concat(
_liferayPortletResponse.getNamespace(), RowChecker.ROW_IDS,
name, ""),
page.getTitle(), checkBoxRowIds, "'#" + getAllRowIds() + "'",
StringPool.BLANK);
}
private static final Log _log = LogFactoryUtil.getLog(PagesChecker.class);
private final LiferayPortletResponse _liferayPortletResponse;
private final PermissionChecker _permissionChecker;
}