/** * 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.portal.action; import com.liferay.portal.kernel.language.LanguageUtil; import com.liferay.portal.kernel.model.Layout; import com.liferay.portal.kernel.portlet.PortletPreferencesFactoryUtil; import com.liferay.portal.kernel.security.permission.ActionKeys; import com.liferay.portal.kernel.security.permission.PermissionChecker; import com.liferay.portal.kernel.service.permission.PortletPermissionUtil; import com.liferay.portal.kernel.theme.ThemeDisplay; import com.liferay.portal.kernel.util.ParamUtil; import com.liferay.portal.kernel.util.WebKeys; import com.liferay.portal.struts.JSONAction; import com.liferay.portlet.InvokerPortletImpl; import javax.portlet.PortletPreferences; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpSession; import org.apache.struts.action.ActionForm; import org.apache.struts.action.ActionMapping; /** * @author Ming-Gih Lam */ public class UpdatePortletTitleAction extends JSONAction { @Override public String getJSON( ActionMapping actionMapping, ActionForm actionForm, HttpServletRequest request, HttpServletResponse response) throws Exception { HttpSession session = request.getSession(); ThemeDisplay themeDisplay = (ThemeDisplay)request.getAttribute( WebKeys.THEME_DISPLAY); Layout layout = themeDisplay.getLayout(); PermissionChecker permissionChecker = themeDisplay.getPermissionChecker(); String portletId = ParamUtil.getString(request, "portletId"); if (!PortletPermissionUtil.contains( permissionChecker, layout, portletId, ActionKeys.CONFIGURATION)) { return null; } String languageId = LanguageUtil.getLanguageId(request); String title = ParamUtil.getString(request, "title"); PortletPreferences portletSetup = PortletPreferencesFactoryUtil.getLayoutPortletSetup( layout, portletId); portletSetup.setValue("portletSetupTitle_" + languageId, title); portletSetup.setValue("portletSetupUseCustomTitle", "true"); portletSetup.store(); InvokerPortletImpl.clearResponse( session, layout.getPrimaryKey(), portletId, LanguageUtil.getLanguageId(request)); return null; } }