/**
* 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.product.menu.theme.contributor.internal;
import com.liferay.portal.kernel.model.User;
import com.liferay.portal.kernel.template.TemplateContextContributor;
import com.liferay.portal.kernel.theme.ThemeDisplay;
import com.liferay.portal.kernel.util.GetterUtil;
import com.liferay.portal.kernel.util.SessionClicks;
import com.liferay.portal.kernel.util.StringPool;
import com.liferay.portal.kernel.util.WebKeys;
import com.liferay.product.navigation.product.menu.web.constants.ProductNavigationProductMenuWebKeys;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import org.osgi.service.component.annotations.Component;
/**
* @author Julio Camarero
*/
@Component(
immediate = true,
property = {"type=" + TemplateContextContributor.TYPE_THEME},
service = TemplateContextContributor.class
)
public class ProductMenuTemplateContextContributor
implements TemplateContextContributor {
@Override
public void prepare(
Map<String, Object> contextObjects, HttpServletRequest request) {
if (!isShowProductMenu(request)) {
return;
}
String cssClass = GetterUtil.getString(
contextObjects.get("bodyCssClass"));
String productMenuState = SessionClicks.get(
request,
ProductNavigationProductMenuWebKeys.
PRODUCT_NAVIGATION_PRODUCT_MENU_STATE,
"closed");
contextObjects.put(
"bodyCssClass", cssClass + StringPool.SPACE + productMenuState);
contextObjects.put("liferay_product_menu_state", productMenuState);
}
protected boolean isShowProductMenu(HttpServletRequest request) {
ThemeDisplay themeDisplay = (ThemeDisplay)request.getAttribute(
WebKeys.THEME_DISPLAY);
if (themeDisplay.isImpersonated()) {
return true;
}
if (!themeDisplay.isSignedIn()) {
return false;
}
User user = themeDisplay.getUser();
if (!user.isSetupComplete()) {
return false;
}
return true;
}
}