1   /**
2    * Copyright (c) 2000-2010 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   *
12   * 
13   */
14  
15  package com.liferay.portlet.portletconfiguration.action;
16  
17  import com.liferay.portal.kernel.servlet.SessionErrors;
18  import com.liferay.portal.kernel.util.ParamUtil;
19  import com.liferay.portal.model.Layout;
20  import com.liferay.portal.model.Portlet;
21  import com.liferay.portal.security.auth.PrincipalException;
22  import com.liferay.portal.theme.ThemeDisplay;
23  import com.liferay.portal.util.WebKeys;
24  import com.liferay.portlet.PortletPreferencesFactoryUtil;
25  
26  import javax.portlet.ActionRequest;
27  import javax.portlet.ActionResponse;
28  import javax.portlet.PortletConfig;
29  import javax.portlet.PortletPreferences;
30  import javax.portlet.RenderRequest;
31  import javax.portlet.RenderResponse;
32  
33  import org.apache.struts.action.ActionForm;
34  import org.apache.struts.action.ActionForward;
35  import org.apache.struts.action.ActionMapping;
36  
37  /**
38   * <a href="EditSharingAction.java.html"><b><i>View Source</i></b></a>
39   *
40   * @author Jorge Ferrer
41   */
42  public class EditSharingAction extends EditConfigurationAction {
43  
44      public void processAction(
45              ActionMapping mapping, ActionForm form, PortletConfig portletConfig,
46              ActionRequest actionRequest, ActionResponse actionResponse)
47          throws Exception {
48  
49          Portlet portlet = null;
50  
51          try {
52              portlet = getPortlet(actionRequest);
53          }
54          catch (PrincipalException pe) {
55              SessionErrors.add(
56                  actionRequest, PrincipalException.class.getName());
57  
58              setForward(actionRequest, "portlet.portlet_configuration.error");
59          }
60  
61          ThemeDisplay themeDisplay = (ThemeDisplay)actionRequest.getAttribute(
62              WebKeys.THEME_DISPLAY);
63  
64          Layout layout = themeDisplay.getLayout();
65  
66          PortletPreferences preferences =
67              PortletPreferencesFactoryUtil.getLayoutPortletSetup(
68                  layout, portlet.getPortletId());
69  
70          String tabs2 = ParamUtil.getString(actionRequest, "tabs2");
71  
72          if (tabs2.equals("any-website")) {
73              updateAnyWebsite(actionRequest, preferences);
74          }
75          else if (tabs2.equals("facebook")) {
76              updateFacebook(actionRequest, preferences);
77          }
78          else if (tabs2.equals("google-gadget")) {
79              updateGoogleGadget(actionRequest, preferences);
80          }
81          else if (tabs2.equals("netvibes")) {
82              updateNetvibes(actionRequest, preferences);
83          }
84  
85          preferences.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 preferences)
115         throws Exception {
116 
117         boolean widgetShowAddAppLink = ParamUtil.getBoolean(
118             actionRequest, "widgetShowAddAppLink");
119 
120         preferences.setValue(
121             "lfr-widget-show-add-app-link",
122             String.valueOf(widgetShowAddAppLink));
123     }
124 
125     protected void updateFacebook(
126             ActionRequest actionRequest, PortletPreferences preferences)
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         preferences.setValue("lfr-facebook-api-key", facebookAPIKey);
137         preferences.setValue(
138             "lfr-facebook-canvas-page-url", facebookCanvasPageURL);
139         preferences.setValue(
140             "lfr-facebook-show-add-app-link",
141             String.valueOf(facebookShowAddAppLink));
142     }
143 
144     protected void updateGoogleGadget(
145             ActionRequest actionRequest, PortletPreferences preferences)
146         throws Exception {
147 
148         boolean iGoogleShowAddAppLink = ParamUtil.getBoolean(
149             actionRequest, "iGoogleShowAddAppLink");
150 
151         preferences.setValue(
152             "lfr-igoogle-show-add-app-link",
153             String.valueOf(iGoogleShowAddAppLink));
154     }
155 
156     protected void updateNetvibes(
157             ActionRequest actionRequest, PortletPreferences preferences)
158         throws Exception {
159 
160         boolean netvibesShowAddAppLink = ParamUtil.getBoolean(
161             actionRequest, "netvibesShowAddAppLink");
162 
163         preferences.setValue(
164             "lfr-netvibes-show-add-app-link",
165             String.valueOf(netvibesShowAddAppLink));
166     }
167 
168 }