1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * The contents of this file are subject to the terms of the Liferay Enterprise
5    * Subscription License ("License"). You may not use this file except in
6    * compliance with the License. You can obtain a copy of the License by
7    * contacting Liferay, Inc. See the License for the specific language governing
8    * permissions and limitations under the License, including but not limited to
9    * distribution rights of the Software.
10   *
11   *
12   *
13   */
14  
15  package com.liferay.portlet.quicknote.action;
16  
17  import com.liferay.portal.kernel.util.ParamUtil;
18  import com.liferay.portal.kernel.util.Validator;
19  import com.liferay.portal.security.permission.ActionKeys;
20  import com.liferay.portal.service.permission.PortletPermissionUtil;
21  import com.liferay.portal.struts.JSONAction;
22  import com.liferay.portal.theme.ThemeDisplay;
23  import com.liferay.portal.util.WebKeys;
24  import com.liferay.portlet.PortletPreferencesFactoryUtil;
25  
26  import javax.portlet.PortletPreferences;
27  
28  import javax.servlet.http.HttpServletRequest;
29  import javax.servlet.http.HttpServletResponse;
30  
31  import org.apache.struts.action.ActionForm;
32  import org.apache.struts.action.ActionMapping;
33  
34  /**
35   * <a href="SaveAction.java.html"><b><i>View Source</i></b></a>
36   *
37   * @author Alexander Chow
38   */
39  public class SaveAction extends JSONAction {
40  
41      public String getJSON(
42              ActionMapping mapping, ActionForm form, HttpServletRequest request,
43              HttpServletResponse response)
44          throws Exception {
45  
46          ThemeDisplay themeDisplay = (ThemeDisplay)request.getAttribute(
47              WebKeys.THEME_DISPLAY);
48  
49          String portletId = ParamUtil.getString(request, "portletId");
50  
51          PortletPermissionUtil.check(
52              themeDisplay.getPermissionChecker(), themeDisplay.getPlid(),
53              portletId, ActionKeys.CONFIGURATION);
54  
55          PortletPreferences preferences =
56              PortletPreferencesFactoryUtil.getPortletSetup(request, portletId);
57  
58          String color = ParamUtil.getString(request, "color");
59          String data = ParamUtil.getString(request, "data");
60  
61          if (Validator.isNotNull(color)) {
62              preferences.setValue("color", color);
63          }
64  
65          if (Validator.isNotNull(data)) {
66              preferences.setValue("data", data);
67          }
68  
69          preferences.store();
70  
71          return null;
72      }
73  
74  }