1
22
23 package com.liferay.portlet.documentlibrary.action;
24
25 import com.liferay.portal.kernel.util.Constants;
26 import com.liferay.portal.kernel.util.ParamUtil;
27 import com.liferay.portal.security.auth.PrincipalException;
28 import com.liferay.portal.struts.PortletAction;
29 import com.liferay.portlet.documentlibrary.FileShortcutPermissionException;
30 import com.liferay.portlet.documentlibrary.NoSuchFileEntryException;
31 import com.liferay.portlet.documentlibrary.NoSuchFileShortcutException;
32 import com.liferay.portlet.documentlibrary.service.DLFileShortcutServiceUtil;
33 import com.liferay.util.servlet.SessionErrors;
34
35 import javax.portlet.ActionRequest;
36 import javax.portlet.ActionResponse;
37 import javax.portlet.PortletConfig;
38 import javax.portlet.RenderRequest;
39 import javax.portlet.RenderResponse;
40
41 import org.apache.struts.action.ActionForm;
42 import org.apache.struts.action.ActionForward;
43 import org.apache.struts.action.ActionMapping;
44
45
51 public class EditFileShortcutAction extends PortletAction {
52
53 public void processAction(
54 ActionMapping mapping, ActionForm form, PortletConfig config,
55 ActionRequest req, ActionResponse res)
56 throws Exception {
57
58 String cmd = ParamUtil.getString(req, Constants.CMD);
59
60 try {
61 if (cmd.equals(Constants.ADD) || cmd.equals(Constants.UPDATE)) {
62 updateFileShortcut(req);
63 }
64 else if (cmd.equals(Constants.DELETE)) {
65 deleteFileShortcut(req);
66 }
67
68 sendRedirect(req, res);
69 }
70 catch (Exception e) {
71 if (e instanceof NoSuchFileShortcutException ||
72 e instanceof PrincipalException) {
73
74 SessionErrors.add(req, e.getClass().getName());
75
76 setForward(req, "portlet.document_library.error");
77 }
78 else if (e instanceof FileShortcutPermissionException ||
79 e instanceof NoSuchFileEntryException) {
80
81 SessionErrors.add(req, e.getClass().getName());
82 }
83 else {
84 throw e;
85 }
86 }
87 }
88
89 public ActionForward render(
90 ActionMapping mapping, ActionForm form, PortletConfig config,
91 RenderRequest req, RenderResponse res)
92 throws Exception {
93
94 try {
95 ActionUtil.getFileShortcut(req);
96 }
97 catch (Exception e) {
98 if (e instanceof NoSuchFileShortcutException ||
99 e instanceof PrincipalException) {
100
101 SessionErrors.add(req, e.getClass().getName());
102
103 return mapping.findForward("portlet.document_library.error");
104 }
105 else {
106 throw e;
107 }
108 }
109
110 return mapping.findForward(
111 getForward(req, "portlet.document_library.edit_file_shortcut"));
112 }
113
114 protected void deleteFileShortcut(ActionRequest req) throws Exception {
115 long fileShortcutId = ParamUtil.getLong(req, "fileShortcutId");
116
117 DLFileShortcutServiceUtil.deleteFileShortcut(fileShortcutId);
118 }
119
120 protected void updateFileShortcut(ActionRequest req) throws Exception {
121 long fileShortcutId = ParamUtil.getLong(req, "fileShortcutId");
122
123 long folderId = ParamUtil.getLong(req, "folderId");
124 long toFolderId = ParamUtil.getLong(req, "toFolderId");
125 String toName = ParamUtil.getString(req, "toName");
126
127 String[] communityPermissions = req.getParameterValues(
128 "communityPermissions");
129 String[] guestPermissions = req.getParameterValues(
130 "guestPermissions");
131
132 if (fileShortcutId <= 0) {
133
134
136 DLFileShortcutServiceUtil.addFileShortcut(
137 folderId, toFolderId, toName, communityPermissions,
138 guestPermissions);
139 }
140 else {
141
142
144 DLFileShortcutServiceUtil.updateFileShortcut(
145 fileShortcutId, folderId, toFolderId, toName);
146 }
147 }
148
149 }