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