1
22
23 package com.liferay.portlet.journal.action;
24
25 import com.liferay.portal.kernel.servlet.SessionErrors;
26 import com.liferay.portal.kernel.util.Constants;
27 import com.liferay.portal.kernel.util.GetterUtil;
28 import com.liferay.portal.kernel.util.ParamUtil;
29 import com.liferay.portal.kernel.util.StringPool;
30 import com.liferay.portal.kernel.util.StringUtil;
31 import com.liferay.portal.kernel.util.Validator;
32 import com.liferay.portal.model.Layout;
33 import com.liferay.portal.security.auth.PrincipalException;
34 import com.liferay.portal.struts.PortletAction;
35 import com.liferay.portal.util.PortalUtil;
36 import com.liferay.portal.util.WebKeys;
37 import com.liferay.portlet.journal.DuplicateFeedIdException;
38 import com.liferay.portlet.journal.FeedContentFieldException;
39 import com.liferay.portlet.journal.FeedDescriptionException;
40 import com.liferay.portlet.journal.FeedIdException;
41 import com.liferay.portlet.journal.FeedNameException;
42 import com.liferay.portlet.journal.FeedTargetLayoutFriendlyUrlException;
43 import com.liferay.portlet.journal.FeedTargetPortletIdException;
44 import com.liferay.portlet.journal.NoSuchFeedException;
45 import com.liferay.portlet.journal.service.JournalFeedServiceUtil;
46 import com.liferay.util.RSSUtil;
47
48 import javax.portlet.ActionRequest;
49 import javax.portlet.ActionResponse;
50 import javax.portlet.PortletConfig;
51 import javax.portlet.RenderRequest;
52 import javax.portlet.RenderResponse;
53
54 import org.apache.struts.action.ActionForm;
55 import org.apache.struts.action.ActionForward;
56 import org.apache.struts.action.ActionMapping;
57
58
64 public class EditFeedAction extends PortletAction {
65
66 public void processAction(
67 ActionMapping mapping, ActionForm form, PortletConfig portletConfig,
68 ActionRequest actionRequest, ActionResponse actionResponse)
69 throws Exception {
70
71 String cmd = ParamUtil.getString(actionRequest, Constants.CMD);
72
73 try {
74 if (cmd.equals(Constants.ADD) || cmd.equals(Constants.UPDATE)) {
75 updateFeed(actionRequest);
76 }
77 else if (cmd.equals(Constants.DELETE)) {
78 deleteFeeds(actionRequest);
79 }
80
81 sendRedirect(actionRequest, actionResponse);
82 }
83 catch (Exception e) {
84 if (e instanceof NoSuchFeedException ||
85 e instanceof PrincipalException) {
86
87 SessionErrors.add(actionRequest, e.getClass().getName());
88
89 setForward(actionRequest, "portlet.journal.error");
90 }
91 else if (e instanceof DuplicateFeedIdException ||
92 e instanceof FeedContentFieldException ||
93 e instanceof FeedDescriptionException ||
94 e instanceof FeedIdException ||
95 e instanceof FeedNameException ||
96 e instanceof FeedTargetLayoutFriendlyUrlException ||
97 e instanceof FeedTargetPortletIdException) {
98
99 SessionErrors.add(actionRequest, e.getClass().getName());
100 }
101 else {
102 throw e;
103 }
104 }
105 }
106
107 public ActionForward render(
108 ActionMapping mapping, ActionForm form, PortletConfig portletConfig,
109 RenderRequest renderRequest, RenderResponse renderResponse)
110 throws Exception {
111
112 try {
113 String cmd = ParamUtil.getString(renderRequest, Constants.CMD);
114
115 if (!cmd.equals(Constants.ADD)) {
116 ActionUtil.getFeed(renderRequest);
117 }
118 }
119 catch (NoSuchFeedException nssfe) {
120
121
124 }
125 catch (Exception e) {
126 if (e instanceof PrincipalException) {
127 SessionErrors.add(renderRequest, e.getClass().getName());
128
129 return mapping.findForward("portlet.journal.error");
130 }
131 else {
132 throw e;
133 }
134 }
135
136 return mapping.findForward(
137 getForward(renderRequest, "portlet.journal.edit_feed"));
138 }
139
140 protected void deleteFeeds(ActionRequest actionRequest) throws Exception {
141 long groupId = ParamUtil.getLong(actionRequest, "groupId");
142
143 String[] deleteFeedIds = StringUtil.split(
144 ParamUtil.getString(actionRequest, "deleteFeedIds"));
145
146 for (int i = 0; i < deleteFeedIds.length; i++) {
147 JournalFeedServiceUtil.deleteFeed(groupId, deleteFeedIds[i]);
148 }
149 }
150
151 protected void updateFeed(ActionRequest actionRequest) throws Exception {
152 String cmd = ParamUtil.getString(actionRequest, Constants.CMD);
153
154 Layout layout = (Layout)actionRequest.getAttribute(WebKeys.LAYOUT);
155
156 long groupId = ParamUtil.getLong(actionRequest, "groupId");
157
158 String feedId = ParamUtil.getString(actionRequest, "feedId");
159 boolean autoFeedId = ParamUtil.getBoolean(actionRequest, "autoFeedId");
160
161 String name = ParamUtil.getString(actionRequest, "name");
162 String description = ParamUtil.getString(actionRequest, "description");
163 String type = ParamUtil.getString(actionRequest, "type");
164 String structureId = ParamUtil.getString(actionRequest, "structureId");
165 String templateId = ParamUtil.getString(actionRequest, "templateId");
166 String rendererTemplateId = ParamUtil.getString(
167 actionRequest, "rendererTemplateId");
168 int delta = ParamUtil.getInteger(actionRequest, "delta");
169 String orderByCol = ParamUtil.getString(actionRequest, "orderByCol");
170 String orderByType = ParamUtil.getString(actionRequest, "orderByType");
171 String targetLayoutFriendlyUrl = ParamUtil.getString(
172 actionRequest, "targetLayoutFriendlyUrl");
173 String targetPortletId = ParamUtil.getString(
174 actionRequest, "targetPortletId");
175 String contentField = ParamUtil.getString(
176 actionRequest, "contentField");
177
178 String feedType = RSSUtil.DEFAULT_TYPE;
179 double feedVersion = RSSUtil.DEFAULT_VERSION;
180
181 String feedTypeAndVersion = ParamUtil.getString(
182 actionRequest, "feedTypeAndVersion");
183
184 if (Validator.isNotNull(feedTypeAndVersion)) {
185 String[] parts = feedTypeAndVersion.split(StringPool.COLON);
186
187 try {
188 feedType = parts[0];
189 feedVersion = GetterUtil.getDouble(parts[1]);
190 }
191 catch (Exception e) {
192 }
193 }
194 else {
195 feedType = ParamUtil.getString(actionRequest, "feedType", feedType);
196 feedVersion = ParamUtil.getDouble(
197 actionRequest, "feedVersion", feedVersion);
198 }
199
200 String[] communityPermissions = PortalUtil.getCommunityPermissions(
201 actionRequest);
202 String[] guestPermissions = PortalUtil.getGuestPermissions(
203 actionRequest);
204
205 if (cmd.equals(Constants.ADD)) {
206
207
209 JournalFeedServiceUtil.addFeed(
210 layout.getPlid(), feedId, autoFeedId, name, description,
211 type, structureId, templateId, rendererTemplateId, delta,
212 orderByCol, orderByType, targetLayoutFriendlyUrl,
213 targetPortletId, contentField, feedType, feedVersion,
214 communityPermissions, guestPermissions);
215 }
216 else {
217
218
220 JournalFeedServiceUtil.updateFeed(
221 groupId, feedId, name, description, type, structureId,
222 templateId, rendererTemplateId, delta, orderByCol, orderByType,
223 targetLayoutFriendlyUrl, targetPortletId, contentField,
224 feedType, feedVersion);
225 }
226 }
227
228 }