1   /**
2    * Copyright (c) 2000-2009 Liferay, Inc. All rights reserved.
3    *
4    * Permission is hereby granted, free of charge, to any person obtaining a copy
5    * of this software and associated documentation files (the "Software"), to deal
6    * in the Software without restriction, including without limitation the rights
7    * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8    * copies of the Software, and to permit persons to whom the Software is
9    * furnished to do so, subject to the following conditions:
10   *
11   * The above copyright notice and this permission notice shall be included in
12   * all copies or substantial portions of the Software.
13   *
14   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20   * SOFTWARE.
21   */
22  
23  package com.liferay.portlet.portletconfiguration.action;
24  
25  import com.liferay.portal.kernel.servlet.SessionErrors;
26  import com.liferay.portal.kernel.util.ParamUtil;
27  import com.liferay.portal.model.Layout;
28  import com.liferay.portal.model.Portlet;
29  import com.liferay.portal.security.auth.PrincipalException;
30  import com.liferay.portal.theme.ThemeDisplay;
31  import com.liferay.portal.util.WebKeys;
32  import com.liferay.portlet.PortletPreferencesFactoryUtil;
33  
34  import javax.portlet.ActionRequest;
35  import javax.portlet.ActionResponse;
36  import javax.portlet.PortletConfig;
37  import javax.portlet.PortletPreferences;
38  import javax.portlet.RenderRequest;
39  import javax.portlet.RenderResponse;
40  
41  import org.apache.struts.action.ActionForm;
42  import org.apache.struts.action.ActionForward;
43  import org.apache.struts.action.ActionMapping;
44  
45  /**
46   * <a href="EditSharingAction.java.html"><b><i>View Source</i></b></a>
47   *
48   * @author Jorge Ferrer
49   *
50   */
51  public class EditSharingAction extends EditConfigurationAction {
52  
53      public void processAction(
54              ActionMapping mapping, ActionForm form, PortletConfig portletConfig,
55              ActionRequest actionRequest, ActionResponse actionResponse)
56          throws Exception {
57  
58          Portlet portlet = null;
59  
60          try {
61              portlet = getPortlet(actionRequest);
62          }
63          catch (PrincipalException pe) {
64              SessionErrors.add(
65                  actionRequest, PrincipalException.class.getName());
66  
67              setForward(actionRequest, "portlet.portlet_configuration.error");
68          }
69  
70          ThemeDisplay themeDisplay = (ThemeDisplay)actionRequest.getAttribute(
71              WebKeys.THEME_DISPLAY);
72  
73          Layout layout = themeDisplay.getLayout();
74  
75          PortletPreferences preferences =
76              PortletPreferencesFactoryUtil.getLayoutPortletSetup(
77                  layout, portlet.getPortletId());
78  
79          String tabs2 = ParamUtil.getString(actionRequest, "tabs2");
80  
81          if (tabs2.equals("any-website")) {
82              updateAnyWebsite(actionRequest, preferences);
83          }
84          else if (tabs2.equals("facebook")) {
85              updateFacebook(actionRequest, preferences);
86          }
87          else if (tabs2.equals("google-gadget")) {
88              updateGoogleGadget(actionRequest, preferences);
89          }
90          else if (tabs2.equals("netvibes")) {
91              updateNetvibes(actionRequest, preferences);
92          }
93  
94          preferences.store();
95  
96          sendRedirect(actionRequest, actionResponse);
97      }
98  
99      public ActionForward render(
100             ActionMapping mapping, ActionForm form, PortletConfig portletConfig,
101             RenderRequest renderRequest, RenderResponse renderResponse)
102         throws Exception {
103 
104         Portlet portlet = null;
105 
106         try {
107             portlet = getPortlet(renderRequest);
108         }
109         catch (PrincipalException pe) {
110             SessionErrors.add(
111                 renderRequest, PrincipalException.class.getName());
112 
113             return mapping.findForward("portlet.portlet_configuration.error");
114         }
115 
116         renderResponse.setTitle(getTitle(portlet, renderRequest));
117 
118         return mapping.findForward(getForward(
119             renderRequest, "portlet.portlet_configuration.edit_sharing"));
120     }
121 
122     protected void updateAnyWebsite(
123             ActionRequest actionRequest, PortletPreferences preferences)
124         throws Exception {
125 
126         boolean widgetShowAddAppLink = ParamUtil.getBoolean(
127             actionRequest, "widgetShowAddAppLink");
128 
129         preferences.setValue(
130             "lfr-widget-show-add-app-link",
131             String.valueOf(widgetShowAddAppLink));
132     }
133 
134     protected void updateFacebook(
135             ActionRequest actionRequest, PortletPreferences preferences)
136         throws Exception {
137 
138         String facebookAPIKey = ParamUtil.getString(
139             actionRequest, "facebookAPIKey");
140         String facebookCanvasPageURL = ParamUtil.getString(
141             actionRequest, "facebookCanvasPageURL");
142         boolean facebookShowAddAppLink = ParamUtil.getBoolean(
143             actionRequest, "facebookShowAddAppLink");
144 
145         preferences.setValue("lfr-facebook-api-key", facebookAPIKey);
146         preferences.setValue(
147             "lfr-facebook-canvas-page-url", facebookCanvasPageURL);
148         preferences.setValue(
149             "lfr-facebook-show-add-app-link",
150             String.valueOf(facebookShowAddAppLink));
151     }
152 
153     protected void updateGoogleGadget(
154             ActionRequest actionRequest, PortletPreferences preferences)
155         throws Exception {
156 
157         boolean iGoogleShowAddAppLink = ParamUtil.getBoolean(
158             actionRequest, "iGoogleShowAddAppLink");
159 
160         preferences.setValue(
161             "lfr-igoogle-show-add-app-link",
162             String.valueOf(iGoogleShowAddAppLink));
163     }
164 
165     protected void updateNetvibes(
166             ActionRequest actionRequest, PortletPreferences preferences)
167         throws Exception {
168 
169         boolean netvibesShowAddAppLink = ParamUtil.getBoolean(
170             actionRequest, "netvibesShowAddAppLink");
171 
172         preferences.setValue(
173             "lfr-netvibes-show-add-app-link",
174             String.valueOf(netvibesShowAddAppLink));
175     }
176 
177 }