001    /**
002     * Copyright (c) 2000-2011 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
013     */
014    
015    package com.liferay.portlet.portletconfiguration.action;
016    
017    import com.liferay.portal.kernel.language.LanguageUtil;
018    import com.liferay.portal.kernel.util.ParamUtil;
019    import com.liferay.portal.model.Layout;
020    import com.liferay.portal.security.permission.ActionKeys;
021    import com.liferay.portal.security.permission.PermissionChecker;
022    import com.liferay.portal.service.permission.PortletPermissionUtil;
023    import com.liferay.portal.struts.JSONAction;
024    import com.liferay.portal.theme.ThemeDisplay;
025    import com.liferay.portal.util.WebKeys;
026    import com.liferay.portlet.InvokerPortletImpl;
027    import com.liferay.portlet.PortletPreferencesFactoryUtil;
028    
029    import javax.portlet.PortletPreferences;
030    
031    import javax.servlet.http.HttpServletRequest;
032    import javax.servlet.http.HttpServletResponse;
033    import javax.servlet.http.HttpSession;
034    
035    import org.apache.struts.action.ActionForm;
036    import org.apache.struts.action.ActionMapping;
037    
038    /**
039     * @author Ming-Gih Lam
040     */
041    public class UpdateTitleAction extends JSONAction {
042    
043            @Override
044            public String getJSON(
045                            ActionMapping mapping, ActionForm form, HttpServletRequest request,
046                            HttpServletResponse response)
047                    throws Exception {
048    
049                    HttpSession session = request.getSession();
050    
051                    ThemeDisplay themeDisplay = (ThemeDisplay)request.getAttribute(
052                            WebKeys.THEME_DISPLAY);
053    
054                    Layout layout = themeDisplay.getLayout();
055    
056                    PermissionChecker permissionChecker =
057                            themeDisplay.getPermissionChecker();
058    
059                    String portletId = ParamUtil.getString(request, "portletId");
060    
061                    if (!PortletPermissionUtil.contains(
062                                    permissionChecker, themeDisplay.getPlid(), portletId,
063                                    ActionKeys.CONFIGURATION)) {
064    
065                            return null;
066                    }
067    
068                    String languageId = LanguageUtil.getLanguageId(request);
069                    String title = ParamUtil.getString(request, "title");
070    
071                    PortletPreferences portletSetup =
072                            PortletPreferencesFactoryUtil.getLayoutPortletSetup(
073                                    layout, portletId);
074    
075                    portletSetup.setValue("portletSetupTitle_" + languageId, title);
076                    portletSetup.setValue("portletSetupUseCustomTitle", "true");
077    
078                    portletSetup.store();
079    
080                    InvokerPortletImpl.clearResponse(
081                            session, layout.getPrimaryKey(), portletId,
082                            LanguageUtil.getLanguageId(request));
083    
084                    return null;
085            }
086    
087    }