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