1   /**
2    * Copyright (c) 2000-2008 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 prefs =
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, prefs);
83          }
84          else if (tabs2.equals("facebook")) {
85              updateFacebook(actionRequest, prefs);
86          }
87  
88          prefs.store();
89  
90          sendRedirect(actionRequest, actionResponse);
91      }
92  
93      public ActionForward render(
94              ActionMapping mapping, ActionForm form, PortletConfig portletConfig,
95              RenderRequest renderRequest, RenderResponse renderResponse)
96          throws Exception {
97  
98          Portlet portlet = null;
99  
100         try {
101             portlet = getPortlet(renderRequest);
102         }
103         catch (PrincipalException pe) {
104             SessionErrors.add(
105                 renderRequest, PrincipalException.class.getName());
106 
107             return mapping.findForward("portlet.portlet_configuration.error");
108         }
109 
110         renderResponse.setTitle(getTitle(portlet, renderRequest));
111 
112         return mapping.findForward(getForward(
113             renderRequest, "portlet.portlet_configuration.edit_sharing"));
114     }
115 
116     protected void updateAnyWebsite(
117             ActionRequest actionRequest, PortletPreferences prefs)
118         throws Exception {
119 
120         boolean widgetShowAddAppLink = ParamUtil.getBoolean(
121             actionRequest, "widgetShowAddAppLink");
122 
123         prefs.setValue(
124             "lfr-widget-show-add-app-link",
125             String.valueOf(widgetShowAddAppLink));
126     }
127 
128     protected void updateFacebook(
129             ActionRequest actionRequest, PortletPreferences prefs)
130         throws Exception {
131 
132         String facebookAPIKey = ParamUtil.getString(
133             actionRequest, "facebookAPIKey");
134         String facebookCanvasPageURL = ParamUtil.getString(
135             actionRequest, "facebookCanvasPageURL");
136         boolean facebookShowAddAppLink = ParamUtil.getBoolean(
137             actionRequest, "facebookShowAddAppLink");
138 
139         prefs.setValue("lfr-facebook-api-key", facebookAPIKey);
140         prefs.setValue("lfr-facebook-canvas-page-url", facebookCanvasPageURL);
141         prefs.setValue(
142             "lfr-facebook-show-add-app-link",
143             String.valueOf(facebookShowAddAppLink));
144     }
145 
146 }