/**
* 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.layout.admin.web.internal.product.navigation.control.menu;
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.model.Group;
import com.liferay.portal.kernel.model.Layout;
import com.liferay.portal.kernel.model.LayoutSet;
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 com.liferay.sites.kernel.util.SitesUtil;
import java.io.IOException;
import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
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=300"
},
service = ProductNavigationControlMenuEntry.class
)
public class InformationMessagesProductNavigationControlMenuEntry
extends BaseJSPProductNavigationControlMenuEntry
implements ProductNavigationControlMenuEntry {
public static final String INFORMATION_MESSAGES_LINKED_LAYOUT =
"INFORMATION_MESSAGES_LINKED_LAYOUT";
public static final String INFORMATION_MESSAGES_MODIFIED_LAYOUT =
"INFORMATION_MESSAGES_MODIFIED_LAYOUT";
@Override
public String getIconJspPath() {
return "/control/menu/information_messages.jsp";
}
public boolean hasUpdateLayoutPermission(ThemeDisplay themeDisplay)
throws PortalException {
if (LayoutPermissionUtil.contains(
themeDisplay.getPermissionChecker(), themeDisplay.getLayout(),
ActionKeys.UPDATE)) {
return true;
}
return false;
}
@Override
public boolean includeIcon(
HttpServletRequest request, HttpServletResponse response)
throws IOException {
ThemeDisplay themeDisplay = (ThemeDisplay)request.getAttribute(
WebKeys.THEME_DISPLAY);
try {
request.setAttribute(
INFORMATION_MESSAGES_LINKED_LAYOUT,
isLinkedLayout(themeDisplay));
request.setAttribute(
INFORMATION_MESSAGES_MODIFIED_LAYOUT,
isModifiedLayout(themeDisplay));
}
catch (PortalException pe) {
_log.error(pe, pe);
}
return super.includeIcon(request, response);
}
@Override
public boolean isShow(HttpServletRequest request) throws PortalException {
ThemeDisplay themeDisplay = (ThemeDisplay)request.getAttribute(
WebKeys.THEME_DISPLAY);
Layout layout = themeDisplay.getLayout();
if (layout.isTypeControlPanel()) {
return false;
}
if (!isLinkedLayout(themeDisplay) && !isModifiedLayout(themeDisplay)) {
return false;
}
return super.isShow(request);
}
@Override
@Reference(
target = "(osgi.web.symbolicname=com.liferay.layout.admin.web)",
unbind = "-"
)
public void setServletContext(ServletContext servletContext) {
super.setServletContext(servletContext);
}
protected boolean isLinkedLayout(ThemeDisplay themeDisplay)
throws PortalException {
Layout layout = themeDisplay.getLayout();
Group group = layout.getGroup();
if (!SitesUtil.isLayoutUpdateable(layout) ||
(layout.isLayoutPrototypeLinkActive() &&
!group.hasStagingGroup())) {
if (!LayoutPermissionUtil.containsWithoutViewableGroup(
themeDisplay.getPermissionChecker(), layout, false,
ActionKeys.UPDATE)) {
return false;
}
return true;
}
return false;
}
protected boolean isModifiedLayout(ThemeDisplay themeDisplay)
throws PortalException {
Layout layout = themeDisplay.getLayout();
LayoutSet layoutSet = layout.getLayoutSet();
if (!layoutSet.isLayoutSetPrototypeLinkActive() ||
!SitesUtil.isLayoutModifiedSinceLastMerge(layout)) {
return false;
}
if (!hasUpdateLayoutPermission(themeDisplay)) {
return false;
}
return true;
}
private static final Log _log = LogFactoryUtil.getLog(
InformationMessagesProductNavigationControlMenuEntry.class);
}