001
014
015 package com.liferay.portlet.portletconfiguration.action;
016
017 import com.liferay.portal.kernel.portlet.LiferayPortletConfig;
018 import com.liferay.portal.kernel.servlet.SessionErrors;
019 import com.liferay.portal.kernel.servlet.SessionMessages;
020 import com.liferay.portal.kernel.util.ParamUtil;
021 import com.liferay.portal.kernel.util.Validator;
022 import com.liferay.portal.model.Layout;
023 import com.liferay.portal.model.Portlet;
024 import com.liferay.portal.security.auth.PrincipalException;
025 import com.liferay.portal.theme.ThemeDisplay;
026 import com.liferay.portal.util.PortalUtil;
027 import com.liferay.portal.util.WebKeys;
028 import com.liferay.portlet.PortletPreferencesFactoryUtil;
029
030 import javax.portlet.ActionRequest;
031 import javax.portlet.ActionResponse;
032 import javax.portlet.PortletConfig;
033 import javax.portlet.PortletPreferences;
034 import javax.portlet.RenderRequest;
035 import javax.portlet.RenderResponse;
036
037 import org.apache.struts.action.ActionForm;
038 import org.apache.struts.action.ActionForward;
039 import org.apache.struts.action.ActionMapping;
040
041
044 public class EditSharingAction extends EditConfigurationAction {
045
046 @Override
047 public void processAction(
048 ActionMapping mapping, ActionForm form, PortletConfig portletConfig,
049 ActionRequest actionRequest, ActionResponse actionResponse)
050 throws Exception {
051
052 Portlet portlet = null;
053
054 try {
055 portlet = getPortlet(actionRequest);
056 }
057 catch (PrincipalException pe) {
058 SessionErrors.add(
059 actionRequest, PrincipalException.class.getName());
060
061 setForward(actionRequest, "portlet.portlet_configuration.error");
062 }
063
064 ThemeDisplay themeDisplay = (ThemeDisplay)actionRequest.getAttribute(
065 WebKeys.THEME_DISPLAY);
066
067 Layout layout = themeDisplay.getLayout();
068
069 PortletPreferences preferences =
070 PortletPreferencesFactoryUtil.getLayoutPortletSetup(
071 layout, portlet.getPortletId());
072
073 String tabs2 = ParamUtil.getString(actionRequest, "tabs2");
074
075 if (tabs2.equals("any-website")) {
076 updateAnyWebsite(actionRequest, preferences);
077 }
078 else if (tabs2.equals("facebook")) {
079 updateFacebook(actionRequest, preferences);
080 }
081 else if (tabs2.equals("friends")) {
082 updateFriends(actionRequest, preferences);
083 }
084 else if (tabs2.equals("opensocial-gadget")) {
085 updateGoogleGadget(actionRequest, preferences);
086 }
087 else if (tabs2.equals("netvibes")) {
088 updateNetvibes(actionRequest, preferences);
089 }
090
091 preferences.store();
092
093 if (SessionErrors.isEmpty(actionRequest)) {
094 LiferayPortletConfig liferayPortletConfig =
095 (LiferayPortletConfig)portletConfig;
096
097 String portletResource = ParamUtil.getString(
098 actionRequest, "portletResource");
099
100 SessionMessages.add(
101 actionRequest,
102 liferayPortletConfig.getPortletId() +
103 SessionMessages.KEY_SUFFIX_REFRESH_PORTLET,
104 portletResource);
105
106 SessionMessages.add(
107 actionRequest,
108 liferayPortletConfig.getPortletId() +
109 SessionMessages.KEY_SUFFIX_UPDATED_CONFIGURATION);
110
111 String redirect = PortalUtil.escapeRedirect(
112 ParamUtil.getString(actionRequest, "redirect"));
113
114 if (Validator.isNotNull(redirect)) {
115 actionResponse.sendRedirect(redirect);
116 }
117 }
118 }
119
120 @Override
121 public ActionForward render(
122 ActionMapping mapping, ActionForm form, PortletConfig portletConfig,
123 RenderRequest renderRequest, RenderResponse renderResponse)
124 throws Exception {
125
126 Portlet portlet = null;
127
128 try {
129 portlet = getPortlet(renderRequest);
130 }
131 catch (PrincipalException pe) {
132 SessionErrors.add(
133 renderRequest, PrincipalException.class.getName());
134
135 return mapping.findForward("portlet.portlet_configuration.error");
136 }
137
138 renderResponse.setTitle(getTitle(portlet, renderRequest));
139
140 return mapping.findForward(
141 getForward(
142 renderRequest, "portlet.portlet_configuration.edit_sharing"));
143 }
144
145 protected void updateAnyWebsite(
146 ActionRequest actionRequest, PortletPreferences preferences)
147 throws Exception {
148
149 boolean widgetShowAddAppLink = ParamUtil.getBoolean(
150 actionRequest, "widgetShowAddAppLink");
151
152 preferences.setValue(
153 "lfrWidgetShowAddAppLink", String.valueOf(widgetShowAddAppLink));
154 }
155
156 protected void updateFacebook(
157 ActionRequest actionRequest, PortletPreferences preferences)
158 throws Exception {
159
160 String facebookAPIKey = ParamUtil.getString(
161 actionRequest, "facebookAPIKey");
162 String facebookCanvasPageURL = ParamUtil.getString(
163 actionRequest, "facebookCanvasPageURL");
164 boolean facebookShowAddAppLink = ParamUtil.getBoolean(
165 actionRequest, "facebookShowAddAppLink");
166
167 preferences.setValue("lfrFacebookApiKey", facebookAPIKey);
168 preferences.setValue("lfrFacebookCanvasPageUrl", facebookCanvasPageURL);
169 preferences.setValue(
170 "lfrFacebookShowAddAppLink",
171 String.valueOf(facebookShowAddAppLink));
172 }
173
174 protected void updateFriends(
175 ActionRequest actionRequest, PortletPreferences preferences)
176 throws Exception {
177
178 boolean appShowShareWithFriendsLink = ParamUtil.getBoolean(
179 actionRequest, "appShowShareWithFriendsLink");
180
181 preferences.setValue(
182 "lfrAppShowShareWithFriendsLink",
183 String.valueOf(appShowShareWithFriendsLink));
184 }
185
186 protected void updateGoogleGadget(
187 ActionRequest actionRequest, PortletPreferences preferences)
188 throws Exception {
189
190 boolean iGoogleShowAddAppLink = ParamUtil.getBoolean(
191 actionRequest, "iGoogleShowAddAppLink");
192
193 preferences.setValue(
194 "lfrIgoogleShowAddAppLink", String.valueOf(iGoogleShowAddAppLink));
195 }
196
197 protected void updateNetvibes(
198 ActionRequest actionRequest, PortletPreferences preferences)
199 throws Exception {
200
201 boolean netvibesShowAddAppLink = ParamUtil.getBoolean(
202 actionRequest, "netvibesShowAddAppLink");
203
204 preferences.setValue(
205 "lfrNetvibesShowAddAppLink",
206 String.valueOf(netvibesShowAddAppLink));
207 }
208
209 }