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