001: /**
002: * Copyright (c) 2000-2008 Liferay, Inc. All rights reserved.
003: *
004: * Permission is hereby granted, free of charge, to any person obtaining a copy
005: * of this software and associated documentation files (the "Software"), to deal
006: * in the Software without restriction, including without limitation the rights
007: * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
008: * copies of the Software, and to permit persons to whom the Software is
009: * furnished to do so, subject to the following conditions:
010: *
011: * The above copyright notice and this permission notice shall be included in
012: * all copies or substantial portions of the Software.
013: *
014: * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
015: * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
016: * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
017: * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
018: * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
019: * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
020: * SOFTWARE.
021: */package com.liferay.portlet.documentlibrary.action;
022:
023: import com.liferay.portal.kernel.util.Constants;
024: import com.liferay.portal.kernel.util.ParamUtil;
025: import com.liferay.portal.security.auth.PrincipalException;
026: import com.liferay.portal.struts.PortletAction;
027: import com.liferay.portlet.documentlibrary.FileShortcutPermissionException;
028: import com.liferay.portlet.documentlibrary.NoSuchFileEntryException;
029: import com.liferay.portlet.documentlibrary.NoSuchFileShortcutException;
030: import com.liferay.portlet.documentlibrary.service.DLFileShortcutServiceUtil;
031: import com.liferay.util.Html;
032: import com.liferay.util.servlet.SessionErrors;
033:
034: import javax.portlet.ActionRequest;
035: import javax.portlet.ActionResponse;
036: import javax.portlet.PortletConfig;
037: import javax.portlet.RenderRequest;
038: import javax.portlet.RenderResponse;
039:
040: import org.apache.struts.action.ActionForm;
041: import org.apache.struts.action.ActionForward;
042: import org.apache.struts.action.ActionMapping;
043:
044: /**
045: * <a href="EditFileShortcutAction.java.html"><b><i>View Source</i></b></a>
046: *
047: * @author Brian Wing Shun Chan
048: *
049: */
050: public class EditFileShortcutAction extends PortletAction {
051:
052: public void processAction(ActionMapping mapping, ActionForm form,
053: PortletConfig config, ActionRequest req, ActionResponse res)
054: throws Exception {
055:
056: String cmd = ParamUtil.getString(req, Constants.CMD);
057:
058: try {
059: if (cmd.equals(Constants.ADD)
060: || cmd.equals(Constants.UPDATE)) {
061: updateFileShortcut(req);
062: } else if (cmd.equals(Constants.DELETE)) {
063: deleteFileShortcut(req);
064: }
065:
066: sendRedirect(req, res);
067: } catch (Exception e) {
068: if (e instanceof NoSuchFileShortcutException
069: || e instanceof PrincipalException) {
070:
071: SessionErrors.add(req, e.getClass().getName());
072:
073: setForward(req, "portlet.document_library.error");
074: } else if (e instanceof FileShortcutPermissionException
075: || e instanceof NoSuchFileEntryException) {
076:
077: SessionErrors.add(req, e.getClass().getName());
078: } else {
079: throw e;
080: }
081: }
082: }
083:
084: public ActionForward render(ActionMapping mapping, ActionForm form,
085: PortletConfig config, RenderRequest req, RenderResponse res)
086: throws Exception {
087:
088: try {
089: ActionUtil.getFileShortcut(req);
090: } catch (Exception e) {
091: if (e instanceof NoSuchFileShortcutException
092: || e instanceof PrincipalException) {
093:
094: SessionErrors.add(req, e.getClass().getName());
095:
096: return mapping
097: .findForward("portlet.document_library.error");
098: } else {
099: throw e;
100: }
101: }
102:
103: return mapping.findForward(getForward(req,
104: "portlet.document_library.edit_file_shortcut"));
105: }
106:
107: protected void deleteFileShortcut(ActionRequest req)
108: throws Exception {
109: long fileShortcutId = ParamUtil.getLong(req, "fileShortcutId");
110:
111: DLFileShortcutServiceUtil.deleteFileShortcut(fileShortcutId);
112: }
113:
114: protected void updateFileShortcut(ActionRequest req)
115: throws Exception {
116: long fileShortcutId = ParamUtil.getLong(req, "fileShortcutId");
117:
118: long folderId = ParamUtil.getLong(req, "folderId");
119: long toFolderId = ParamUtil.getLong(req, "toFolderId");
120: String toName = Html.unescape(ParamUtil
121: .getString(req, "toName"));
122:
123: String[] communityPermissions = req
124: .getParameterValues("communityPermissions");
125: String[] guestPermissions = req
126: .getParameterValues("guestPermissions");
127:
128: if (fileShortcutId <= 0) {
129:
130: // Add file shortcut
131:
132: DLFileShortcutServiceUtil.addFileShortcut(folderId,
133: toFolderId, toName, communityPermissions,
134: guestPermissions);
135: } else {
136:
137: // Update file shortcut
138:
139: DLFileShortcutServiceUtil.updateFileShortcut(
140: fileShortcutId, folderId, toFolderId, toName);
141: }
142: }
143:
144: }
|