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