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