1   /**
2    * Copyright (c) 2000-2009 Liferay, Inc. All rights reserved.
3    *
4    *
5    *
6    *
7    * The contents of this file are subject to the terms of the Liferay Enterprise
8    * Subscription License ("License"). You may not use this file except in
9    * compliance with the License. You can obtain a copy of the License by
10   * contacting Liferay, Inc. See the License for the specific language governing
11   * permissions and limitations under the License, including but not limited to
12   * distribution rights 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  public class EditSharingAction extends EditConfigurationAction {
51  
52      public void processAction(
53              ActionMapping mapping, ActionForm form, PortletConfig portletConfig,
54              ActionRequest actionRequest, ActionResponse actionResponse)
55          throws Exception {
56  
57          Portlet portlet = null;
58  
59          try {
60              portlet = getPortlet(actionRequest);
61          }
62          catch (PrincipalException pe) {
63              SessionErrors.add(
64                  actionRequest, PrincipalException.class.getName());
65  
66              setForward(actionRequest, "portlet.portlet_configuration.error");
67          }
68  
69          ThemeDisplay themeDisplay = (ThemeDisplay)actionRequest.getAttribute(
70              WebKeys.THEME_DISPLAY);
71  
72          Layout layout = themeDisplay.getLayout();
73  
74          PortletPreferences preferences =
75              PortletPreferencesFactoryUtil.getLayoutPortletSetup(
76                  layout, portlet.getPortletId());
77  
78          String tabs2 = ParamUtil.getString(actionRequest, "tabs2");
79  
80          if (tabs2.equals("any-website")) {
81              updateAnyWebsite(actionRequest, preferences);
82          }
83          else if (tabs2.equals("facebook")) {
84              updateFacebook(actionRequest, preferences);
85          }
86          else if (tabs2.equals("google-gadget")) {
87              updateGoogleGadget(actionRequest, preferences);
88          }
89          else if (tabs2.equals("netvibes")) {
90              updateNetvibes(actionRequest, preferences);
91          }
92  
93          preferences.store();
94  
95          sendRedirect(actionRequest, actionResponse);
96      }
97  
98      public ActionForward render(
99              ActionMapping mapping, ActionForm form, PortletConfig portletConfig,
100             RenderRequest renderRequest, RenderResponse renderResponse)
101         throws Exception {
102 
103         Portlet portlet = null;
104 
105         try {
106             portlet = getPortlet(renderRequest);
107         }
108         catch (PrincipalException pe) {
109             SessionErrors.add(
110                 renderRequest, PrincipalException.class.getName());
111 
112             return mapping.findForward("portlet.portlet_configuration.error");
113         }
114 
115         renderResponse.setTitle(getTitle(portlet, renderRequest));
116 
117         return mapping.findForward(getForward(
118             renderRequest, "portlet.portlet_configuration.edit_sharing"));
119     }
120 
121     protected void updateAnyWebsite(
122             ActionRequest actionRequest, PortletPreferences preferences)
123         throws Exception {
124 
125         boolean widgetShowAddAppLink = ParamUtil.getBoolean(
126             actionRequest, "widgetShowAddAppLink");
127 
128         preferences.setValue(
129             "lfr-widget-show-add-app-link",
130             String.valueOf(widgetShowAddAppLink));
131     }
132 
133     protected void updateFacebook(
134             ActionRequest actionRequest, PortletPreferences preferences)
135         throws Exception {
136 
137         String facebookAPIKey = ParamUtil.getString(
138             actionRequest, "facebookAPIKey");
139         String facebookCanvasPageURL = ParamUtil.getString(
140             actionRequest, "facebookCanvasPageURL");
141         boolean facebookShowAddAppLink = ParamUtil.getBoolean(
142             actionRequest, "facebookShowAddAppLink");
143 
144         preferences.setValue("lfr-facebook-api-key", facebookAPIKey);
145         preferences.setValue(
146             "lfr-facebook-canvas-page-url", facebookCanvasPageURL);
147         preferences.setValue(
148             "lfr-facebook-show-add-app-link",
149             String.valueOf(facebookShowAddAppLink));
150     }
151 
152     protected void updateGoogleGadget(
153             ActionRequest actionRequest, PortletPreferences preferences)
154         throws Exception {
155 
156         boolean iGoogleShowAddAppLink = ParamUtil.getBoolean(
157             actionRequest, "iGoogleShowAddAppLink");
158 
159         preferences.setValue(
160             "lfr-igoogle-show-add-app-link",
161             String.valueOf(iGoogleShowAddAppLink));
162     }
163 
164     protected void updateNetvibes(
165             ActionRequest actionRequest, PortletPreferences preferences)
166         throws Exception {
167 
168         boolean netvibesShowAddAppLink = ParamUtil.getBoolean(
169             actionRequest, "netvibesShowAddAppLink");
170 
171         preferences.setValue(
172             "lfr-netvibes-show-add-app-link",
173             String.valueOf(netvibesShowAddAppLink));
174     }
175 
176 }