/** * 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.site.admin.web.internal.portlet.configuration.icon; import com.liferay.portal.kernel.exception.PortalException; import com.liferay.portal.kernel.language.LanguageUtil; import com.liferay.portal.kernel.log.Log; import com.liferay.portal.kernel.log.LogFactoryUtil; import com.liferay.portal.kernel.model.LayoutSetPrototype; import com.liferay.portal.kernel.portlet.PortletProvider; import com.liferay.portal.kernel.portlet.PortletProviderUtil; import com.liferay.portal.kernel.portlet.configuration.icon.BasePortletConfigurationIcon; import com.liferay.portal.kernel.portlet.configuration.icon.PortletConfigurationIcon; import com.liferay.portal.kernel.security.permission.ActionKeys; import com.liferay.portal.kernel.service.permission.PortalPermissionUtil; import com.liferay.portal.kernel.theme.ThemeDisplay; import com.liferay.portal.kernel.util.StringPool; import com.liferay.portal.kernel.util.WebKeys; import com.liferay.site.admin.web.internal.constants.SiteAdminPortletKeys; import javax.portlet.PortletRequest; import javax.portlet.PortletResponse; import javax.portlet.PortletURL; import org.osgi.service.component.annotations.Component; /** * @author Eudaldo Alonso */ @Component( immediate = true, property = {"javax.portlet.name=" + SiteAdminPortletKeys.SITE_ADMIN}, service = PortletConfigurationIcon.class ) public class ManageSiteTemplatesConfigurationIcon extends BasePortletConfigurationIcon { @Override public String getMessage(PortletRequest portletRequest) { return LanguageUtil.get( getResourceBundle(getLocale(portletRequest)), "manage-site-template"); } @Override public String getURL( PortletRequest portletRequest, PortletResponse portletResponse) { ThemeDisplay themeDisplay = (ThemeDisplay)portletRequest.getAttribute( WebKeys.THEME_DISPLAY); try { PortletURL manageSiteTemplateURL = PortletProviderUtil.getPortletURL( portletRequest, LayoutSetPrototype.class.getName(), PortletProvider.Action.VIEW); if (manageSiteTemplateURL == null) { return StringPool.BLANK; } manageSiteTemplateURL.setParameter( "redirect", themeDisplay.getURLCurrent()); manageSiteTemplateURL.setParameter( "backURL", themeDisplay.getURLCurrent()); return manageSiteTemplateURL.toString(); } catch (PortalException pe) { // LPS-52675 if (_log.isDebugEnabled()) { _log.debug(pe, pe); } } return StringPool.BLANK; } @Override public double getWeight() { return 100; } @Override public boolean isShow(PortletRequest portletRequest) { ThemeDisplay themeDisplay = (ThemeDisplay)portletRequest.getAttribute( WebKeys.THEME_DISPLAY); if (PortalPermissionUtil.contains( themeDisplay.getPermissionChecker(), ActionKeys.ADD_LAYOUT_SET_PROTOTYPE)) { return true; } return false; } private static final Log _log = LogFactoryUtil.getLog( ManageSiteTemplatesConfigurationIcon.class); }