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