1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * This library is free software; you can redistribute it and/or modify it under
5    * the terms of the GNU Lesser General Public License as published by the Free
6    * Software Foundation; either version 2.1 of the License, or (at your option)
7    * any later version.
8    *
9    * This library is distributed in the hope that it will be useful, but WITHOUT
10   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11   * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12   * details.
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  }