/**
* 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.product.navigation.control.menu.web.internal;
import com.liferay.portal.kernel.exception.PortalException;
import com.liferay.portal.kernel.model.Layout;
import com.liferay.portal.kernel.model.LayoutTypeController;
import com.liferay.portal.kernel.model.LayoutTypePortlet;
import com.liferay.portal.kernel.security.permission.ActionKeys;
import com.liferay.portal.kernel.service.permission.LayoutPermissionUtil;
import com.liferay.portal.kernel.theme.ThemeDisplay;
import com.liferay.portal.kernel.util.WebKeys;
import com.liferay.product.navigation.control.menu.BaseJSPProductNavigationControlMenuEntry;
import com.liferay.product.navigation.control.menu.ProductNavigationControlMenuEntry;
import com.liferay.product.navigation.control.menu.constants.ProductNavigationControlMenuCategoryKeys;
import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference;
/**
* @author Julio Camarero
*/
@Component(
immediate = true,
property = {
"product.navigation.control.menu.category.key=" + ProductNavigationControlMenuCategoryKeys.USER,
"product.navigation.control.menu.entry.order:Integer=200"
},
service = ProductNavigationControlMenuEntry.class
)
public class AddContentProductNavigationControlMenuEntry
extends BaseJSPProductNavigationControlMenuEntry
implements ProductNavigationControlMenuEntry {
@Override
public String getBodyJspPath() {
return "/entries/add_content_body.jsp";
}
@Override
public String getIconJspPath() {
return "/entries/add_content_icon.jsp";
}
@Override
public boolean isShow(HttpServletRequest request) throws PortalException {
ThemeDisplay themeDisplay = (ThemeDisplay)request.getAttribute(
WebKeys.THEME_DISPLAY);
if (themeDisplay.isStateMaximized()) {
return false;
}
Layout layout = themeDisplay.getLayout();
if (!layout.isTypePortlet()) {
return false;
}
LayoutTypePortlet layoutTypePortlet =
themeDisplay.getLayoutTypePortlet();
LayoutTypeController layoutTypeController =
layoutTypePortlet.getLayoutTypeController();
if (layoutTypeController.isFullPageDisplayable()) {
return false;
}
if (!hasAddContentOrApplicationPermission(themeDisplay)) {
return false;
}
if (!(hasUpdateLayoutPermission(themeDisplay) ||
hasCustomizePermission(themeDisplay))) {
return false;
}
return super.isShow(request);
}
@Override
@Reference(
target = "(osgi.web.symbolicname=com.liferay.product.navigation.control.menu.web)",
unbind = "-"
)
public void setServletContext(ServletContext servletContext) {
super.setServletContext(servletContext);
}
protected boolean hasAddContentOrApplicationPermission(
ThemeDisplay themeDisplay) {
Layout layout = themeDisplay.getLayout();
if (layout.isLayoutPrototypeLinkActive()) {
return false;
}
return true;
}
protected boolean hasCustomizePermission(ThemeDisplay themeDisplay)
throws PortalException {
Layout layout = themeDisplay.getLayout();
LayoutTypePortlet layoutTypePortlet =
themeDisplay.getLayoutTypePortlet();
if (!layout.isTypePortlet() || (layoutTypePortlet == null)) {
return false;
}
if (!layoutTypePortlet.isCustomizable() ||
!layoutTypePortlet.isCustomizedView()) {
return false;
}
if (LayoutPermissionUtil.contains(
themeDisplay.getPermissionChecker(), layout,
ActionKeys.CUSTOMIZE)) {
return true;
}
return false;
}
protected boolean hasUpdateLayoutPermission(ThemeDisplay themeDisplay)
throws PortalException {
return LayoutPermissionUtil.contains(
themeDisplay.getPermissionChecker(), themeDisplay.getLayout(),
ActionKeys.UPDATE);
}
}