/** * 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.staging.bar.web.internal.product.navigation.control.menu; import com.liferay.portal.kernel.exception.PortalException; import com.liferay.portal.kernel.model.Layout; 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.TOOLS, "product.navigation.control.menu.entry.order:Integer=100" }, service = { ProductNavigationControlMenuEntry.class, StagingProductNavigationControlMenuEntry.class } ) public class StagingProductNavigationControlMenuEntry extends BaseJSPProductNavigationControlMenuEntry implements ProductNavigationControlMenuEntry { @Override public String getIconJspPath() { return "/control_menu/entry.jsp"; } @Override public boolean isShow(HttpServletRequest request) throws PortalException { Boolean show = (Boolean)request.getAttribute(_SHOW); if (show != null) { return show; } show = _isShow(request); request.setAttribute(_SHOW, show); return show; } @Override @Reference( target = "(osgi.web.symbolicname=com.liferay.staging.bar.web)", unbind = "-" ) public void setServletContext(ServletContext servletContext) { super.setServletContext(servletContext); } private boolean _isShow(HttpServletRequest request) throws PortalException { ThemeDisplay themeDisplay = (ThemeDisplay)request.getAttribute( WebKeys.THEME_DISPLAY); Layout layout = themeDisplay.getLayout(); if (layout.isTypeControlPanel()) { return false; } if (!themeDisplay.isShowStagingIcon()) { return false; } return true; } private static final String _SHOW = StagingProductNavigationControlMenuEntry.class + "#_SHOW"; }