com.liferay.portlet.portletconfiguration.action.UpdateTitleAction.java Source code

Java tutorial

Introduction

Here is the source code for com.liferay.portlet.portletconfiguration.action.UpdateTitleAction.java

Source

/**
 * Copyright (c) 2000-2012 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.portlet.portletconfiguration.action;

import com.liferay.portal.kernel.language.LanguageUtil;
import com.liferay.portal.kernel.util.ParamUtil;
import com.liferay.portal.model.Layout;
import com.liferay.portal.security.permission.ActionKeys;
import com.liferay.portal.security.permission.PermissionChecker;
import com.liferay.portal.service.permission.PortletPermissionUtil;
import com.liferay.portal.struts.JSONAction;
import com.liferay.portal.theme.ThemeDisplay;
import com.liferay.portal.util.WebKeys;
import com.liferay.portlet.InvokerPortletImpl;
import com.liferay.portlet.PortletPreferencesFactoryUtil;

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 UpdateTitleAction extends JSONAction {

    @Override
    public String getJSON(ActionMapping mapping, ActionForm form, 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, themeDisplay.getPlid(), 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;
    }

}