001    /**
002     * Copyright (c) 2000-2010 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.quicknote.action;
016    
017    import com.liferay.portal.kernel.util.ParamUtil;
018    import com.liferay.portal.kernel.util.Validator;
019    import com.liferay.portal.security.permission.ActionKeys;
020    import com.liferay.portal.service.permission.PortletPermissionUtil;
021    import com.liferay.portal.struts.JSONAction;
022    import com.liferay.portal.theme.ThemeDisplay;
023    import com.liferay.portal.util.WebKeys;
024    import com.liferay.portlet.PortletPreferencesFactoryUtil;
025    
026    import javax.portlet.PortletPreferences;
027    
028    import javax.servlet.http.HttpServletRequest;
029    import javax.servlet.http.HttpServletResponse;
030    
031    import org.apache.struts.action.ActionForm;
032    import org.apache.struts.action.ActionMapping;
033    
034    /**
035     * @author Alexander Chow
036     */
037    public class SaveAction extends JSONAction {
038    
039            public String getJSON(
040                            ActionMapping mapping, ActionForm form, HttpServletRequest request,
041                            HttpServletResponse response)
042                    throws Exception {
043    
044                    ThemeDisplay themeDisplay = (ThemeDisplay)request.getAttribute(
045                            WebKeys.THEME_DISPLAY);
046    
047                    String portletId = ParamUtil.getString(request, "portletId");
048    
049                    PortletPermissionUtil.check(
050                            themeDisplay.getPermissionChecker(), themeDisplay.getPlid(),
051                            portletId, ActionKeys.CONFIGURATION);
052    
053                    PortletPreferences preferences =
054                            PortletPreferencesFactoryUtil.getPortletSetup(request, portletId);
055    
056                    String color = ParamUtil.getString(request, "color");
057                    String data = ParamUtil.getString(request, "data");
058    
059                    if (Validator.isNotNull(color)) {
060                            preferences.setValue("color", color);
061                    }
062    
063                    if (Validator.isNotNull(data)) {
064                            preferences.setValue("data", data);
065                    }
066    
067                    preferences.store();
068    
069                    return null;
070            }
071    
072    }