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("friends")) {
88              updateFriends(actionRequest, preferences);
89          }
90          else if (tabs2.equals("google-gadget")) {
91              updateGoogleGadget(actionRequest, preferences);
92          }
93          else if (tabs2.equals("netvibes")) {
94              updateNetvibes(actionRequest, preferences);
95          }
96  
97          preferences.store();
98  
99          sendRedirect(actionRequest, actionResponse);
100     }
101 
102     public ActionForward render(
103             ActionMapping mapping, ActionForm form, PortletConfig portletConfig,
104             RenderRequest renderRequest, RenderResponse renderResponse)
105         throws Exception {
106 
107         Portlet portlet = null;
108 
109         try {
110             portlet = getPortlet(renderRequest);
111         }
112         catch (PrincipalException pe) {
113             SessionErrors.add(
114                 renderRequest, PrincipalException.class.getName());
115 
116             return mapping.findForward("portlet.portlet_configuration.error");
117         }
118 
119         renderResponse.setTitle(getTitle(portlet, renderRequest));
120 
121         return mapping.findForward(getForward(
122             renderRequest, "portlet.portlet_configuration.edit_sharing"));
123     }
124 
125     protected void updateAnyWebsite(
126             ActionRequest actionRequest, PortletPreferences preferences)
127         throws Exception {
128 
129         boolean widgetShowAddAppLink = ParamUtil.getBoolean(
130             actionRequest, "widgetShowAddAppLink");
131 
132         preferences.setValue(
133             "lfr-widget-show-add-app-link",
134             String.valueOf(widgetShowAddAppLink));
135     }
136 
137     protected void updateFacebook(
138             ActionRequest actionRequest, PortletPreferences preferences)
139         throws Exception {
140 
141         String facebookAPIKey = ParamUtil.getString(
142             actionRequest, "facebookAPIKey");
143         String facebookCanvasPageURL = ParamUtil.getString(
144             actionRequest, "facebookCanvasPageURL");
145         boolean facebookShowAddAppLink = ParamUtil.getBoolean(
146             actionRequest, "facebookShowAddAppLink");
147 
148         preferences.setValue("lfr-facebook-api-key", facebookAPIKey);
149         preferences.setValue(
150             "lfr-facebook-canvas-page-url", facebookCanvasPageURL);
151         preferences.setValue(
152             "lfr-facebook-show-add-app-link",
153             String.valueOf(facebookShowAddAppLink));
154     }
155 
156     protected void updateFriends(
157             ActionRequest actionRequest, PortletPreferences preferences)
158         throws Exception {
159 
160         boolean appShowShareWithFriendsLink = ParamUtil.getBoolean(
161             actionRequest, "appShowShareWithFriendsLink");
162 
163         preferences.setValue(
164             "lfr-app-show-share-with-friends-link",
165             String.valueOf(appShowShareWithFriendsLink));
166     }
167 
168     protected void updateGoogleGadget(
169             ActionRequest actionRequest, PortletPreferences preferences)
170         throws Exception {
171 
172         boolean iGoogleShowAddAppLink = ParamUtil.getBoolean(
173             actionRequest, "iGoogleShowAddAppLink");
174 
175         preferences.setValue(
176             "lfr-igoogle-show-add-app-link",
177             String.valueOf(iGoogleShowAddAppLink));
178     }
179 
180     protected void updateNetvibes(
181             ActionRequest actionRequest, PortletPreferences preferences)
182         throws Exception {
183 
184         boolean netvibesShowAddAppLink = ParamUtil.getBoolean(
185             actionRequest, "netvibesShowAddAppLink");
186 
187         preferences.setValue(
188             "lfr-netvibes-show-add-app-link",
189             String.valueOf(netvibesShowAddAppLink));
190     }
191 
192 }