1   /**
2    * Copyright (c) 2000-2009 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   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
12   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
13   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
14   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
15   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
16   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
17   * SOFTWARE.
18   */
19  
20  package com.liferay.portlet.portletconfiguration.action;
21  
22  import com.liferay.portal.kernel.servlet.SessionErrors;
23  import com.liferay.portal.kernel.util.ParamUtil;
24  import com.liferay.portal.model.Layout;
25  import com.liferay.portal.model.Portlet;
26  import com.liferay.portal.security.auth.PrincipalException;
27  import com.liferay.portal.theme.ThemeDisplay;
28  import com.liferay.portal.util.WebKeys;
29  import com.liferay.portlet.PortletPreferencesFactoryUtil;
30  
31  import javax.portlet.ActionRequest;
32  import javax.portlet.ActionResponse;
33  import javax.portlet.PortletConfig;
34  import javax.portlet.PortletPreferences;
35  import javax.portlet.RenderRequest;
36  import javax.portlet.RenderResponse;
37  
38  import org.apache.struts.action.ActionForm;
39  import org.apache.struts.action.ActionForward;
40  import org.apache.struts.action.ActionMapping;
41  
42  /**
43   * <a href="EditSharingAction.java.html"><b><i>View Source</i></b></a>
44   *
45   * @author Jorge Ferrer
46   *
47   */
48  public class EditSharingAction extends EditConfigurationAction {
49  
50      public void processAction(
51              ActionMapping mapping, ActionForm form, PortletConfig portletConfig,
52              ActionRequest actionRequest, ActionResponse actionResponse)
53          throws Exception {
54  
55          Portlet portlet = null;
56  
57          try {
58              portlet = getPortlet(actionRequest);
59          }
60          catch (PrincipalException pe) {
61              SessionErrors.add(
62                  actionRequest, PrincipalException.class.getName());
63  
64              setForward(actionRequest, "portlet.portlet_configuration.error");
65          }
66  
67          ThemeDisplay themeDisplay = (ThemeDisplay)actionRequest.getAttribute(
68              WebKeys.THEME_DISPLAY);
69  
70          Layout layout = themeDisplay.getLayout();
71  
72          PortletPreferences preferences =
73              PortletPreferencesFactoryUtil.getLayoutPortletSetup(
74                  layout, portlet.getPortletId());
75  
76          String tabs2 = ParamUtil.getString(actionRequest, "tabs2");
77  
78          if (tabs2.equals("any-website")) {
79              updateAnyWebsite(actionRequest, preferences);
80          }
81          else if (tabs2.equals("facebook")) {
82              updateFacebook(actionRequest, preferences);
83          }
84          else if (tabs2.equals("friends")) {
85              updateFriends(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 updateFriends(
154             ActionRequest actionRequest, PortletPreferences preferences)
155         throws Exception {
156 
157         boolean appShowShareWithFriendsLink = ParamUtil.getBoolean(
158             actionRequest, "appShowShareWithFriendsLink");
159 
160         preferences.setValue(
161             "lfr-app-show-share-with-friends-link",
162             String.valueOf(appShowShareWithFriendsLink));
163     }
164 
165     protected void updateGoogleGadget(
166             ActionRequest actionRequest, PortletPreferences preferences)
167         throws Exception {
168 
169         boolean iGoogleShowAddAppLink = ParamUtil.getBoolean(
170             actionRequest, "iGoogleShowAddAppLink");
171 
172         preferences.setValue(
173             "lfr-igoogle-show-add-app-link",
174             String.valueOf(iGoogleShowAddAppLink));
175     }
176 
177     protected void updateNetvibes(
178             ActionRequest actionRequest, PortletPreferences preferences)
179         throws Exception {
180 
181         boolean netvibesShowAddAppLink = ParamUtil.getBoolean(
182             actionRequest, "netvibesShowAddAppLink");
183 
184         preferences.setValue(
185             "lfr-netvibes-show-add-app-link",
186             String.valueOf(netvibesShowAddAppLink));
187     }
188 
189 }