1
22
23 package com.liferay.portlet.bookmarks.action;
24
25 import com.liferay.portal.kernel.util.Constants;
26 import com.liferay.portal.kernel.util.ParamUtil;
27 import com.liferay.portal.kernel.util.StringUtil;
28 import com.liferay.portal.model.LayoutTypePortlet;
29 import com.liferay.portal.security.auth.PrincipalException;
30 import com.liferay.portal.struts.PortletAction;
31 import com.liferay.portal.theme.ThemeDisplay;
32 import com.liferay.portal.util.WebKeys;
33 import com.liferay.portlet.bookmarks.EntryURLException;
34 import com.liferay.portlet.bookmarks.NoSuchEntryException;
35 import com.liferay.portlet.bookmarks.NoSuchFolderException;
36 import com.liferay.portlet.bookmarks.model.BookmarksEntry;
37 import com.liferay.portlet.bookmarks.service.BookmarksEntryServiceUtil;
38 import com.liferay.portlet.taggedcontent.util.AssetPublisherUtil;
39 import com.liferay.portlet.tags.TagsEntryException;
40 import com.liferay.util.servlet.SessionErrors;
41
42 import javax.portlet.ActionRequest;
43 import javax.portlet.ActionResponse;
44 import javax.portlet.PortletConfig;
45 import javax.portlet.RenderRequest;
46 import javax.portlet.RenderResponse;
47
48 import org.apache.struts.action.ActionForm;
49 import org.apache.struts.action.ActionForward;
50 import org.apache.struts.action.ActionMapping;
51
52
58 public class EditEntryAction extends PortletAction {
59
60 public void processAction(
61 ActionMapping mapping, ActionForm form, PortletConfig config,
62 ActionRequest req, ActionResponse res)
63 throws Exception {
64
65 String cmd = ParamUtil.getString(req, Constants.CMD);
66
67 try {
68 if (cmd.equals(Constants.ADD) || cmd.equals(Constants.UPDATE)) {
69 updateEntry(req);
70 }
71 else if (cmd.equals(Constants.DELETE)) {
72 deleteEntry(req);
73 }
74
75 ThemeDisplay themeDisplay = (ThemeDisplay)req.getAttribute(
76 WebKeys.THEME_DISPLAY);
77
78 LayoutTypePortlet layoutTypePortlet =
79 themeDisplay.getLayoutTypePortlet();
80
81 if (layoutTypePortlet.hasPortletId(config.getPortletName())) {
82 sendRedirect(req, res);
83 }
84 else {
85 String redirect = ParamUtil.getString(req, "redirect");
86
87 res.sendRedirect(redirect);
88 }
89 }
90 catch (Exception e) {
91 if (e instanceof NoSuchEntryException ||
92 e instanceof PrincipalException) {
93
94 SessionErrors.add(req, e.getClass().getName());
95
96 setForward(req, "portlet.bookmarks.error");
97 }
98 else if (e instanceof EntryURLException ||
99 e instanceof NoSuchFolderException) {
100
101 SessionErrors.add(req, e.getClass().getName());
102 }
103 else if (e instanceof TagsEntryException) {
104 SessionErrors.add(req, e.getClass().getName(), e);
105 }
106 else {
107 throw e;
108 }
109 }
110 }
111
112 public ActionForward render(
113 ActionMapping mapping, ActionForm form, PortletConfig config,
114 RenderRequest req, RenderResponse res)
115 throws Exception {
116
117 try {
118 ActionUtil.getEntry(req);
119 }
120 catch (Exception e) {
121 if (e instanceof NoSuchEntryException ||
122 e instanceof PrincipalException) {
123
124 SessionErrors.add(req, e.getClass().getName());
125
126 return mapping.findForward("portlet.bookmarks.error");
127 }
128 else {
129 throw e;
130 }
131 }
132
133 return mapping.findForward(
134 getForward(req, "portlet.bookmarks.edit_entry"));
135 }
136
137 protected void deleteEntry(ActionRequest req) throws Exception {
138 long entryId = ParamUtil.getLong(req, "entryId");
139
140 BookmarksEntryServiceUtil.deleteEntry(entryId);
141 }
142
143 protected void updateEntry(ActionRequest req) throws Exception {
144 long entryId = ParamUtil.getLong(req, "entryId");
145
146 long folderId = ParamUtil.getLong(req, "folderId");
147 String name = ParamUtil.getString(req, "name");
148 String url = ParamUtil.getString(req, "url");
149 String comments = ParamUtil.getString(req, "comments");
150
151 String[] tagsEntries = StringUtil.split(
152 ParamUtil.getString(req, "tagsEntries"));
153
154 String[] communityPermissions = req.getParameterValues(
155 "communityPermissions");
156 String[] guestPermissions = req.getParameterValues(
157 "guestPermissions");
158
159 if (entryId <= 0) {
160
161
163 BookmarksEntry entry = BookmarksEntryServiceUtil.addEntry(
164 folderId, name, url, comments, tagsEntries,
165 communityPermissions, guestPermissions);
166
167 AssetPublisherUtil.addAndStoreSelection(
168 req, BookmarksEntry.class.getName(), entry.getEntryId(), -1);
169 }
170 else {
171
172
174 BookmarksEntryServiceUtil.updateEntry(
175 entryId, folderId, name, url, comments, tagsEntries);
176 }
177
178 AssetPublisherUtil.addRecentFolderId(
179 req, BookmarksEntry.class.getName(), folderId);
180 }
181
182 }