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.documentlibrary.DuplicateFileException;
024: import com.liferay.portal.kernel.util.Constants;
025: import com.liferay.portal.kernel.util.ParamUtil;
026: import com.liferay.portal.model.Layout;
027: import com.liferay.portal.security.auth.PrincipalException;
028: import com.liferay.portal.struts.PortletAction;
029: import com.liferay.portal.util.WebKeys;
030: import com.liferay.portlet.documentlibrary.DuplicateFolderNameException;
031: import com.liferay.portlet.documentlibrary.FolderNameException;
032: import com.liferay.portlet.documentlibrary.NoSuchFolderException;
033: import com.liferay.portlet.documentlibrary.service.DLFolderServiceUtil;
034: import com.liferay.util.servlet.SessionErrors;
035:
036: import javax.portlet.ActionRequest;
037: import javax.portlet.ActionResponse;
038: import javax.portlet.PortletConfig;
039: import javax.portlet.RenderRequest;
040: import javax.portlet.RenderResponse;
041:
042: import org.apache.struts.action.ActionForm;
043: import org.apache.struts.action.ActionForward;
044: import org.apache.struts.action.ActionMapping;
045:
046: /**
047: * <a href="EditFolderAction.java.html"><b><i>View Source</i></b></a>
048: *
049: * @author Brian Wing Shun Chan
050: * @author Alexander Chow
051: *
052: */
053: public class EditFolderAction extends PortletAction {
054:
055: public void processAction(ActionMapping mapping, ActionForm form,
056: PortletConfig config, ActionRequest req, ActionResponse res)
057: throws Exception {
058:
059: String cmd = ParamUtil.getString(req, Constants.CMD);
060:
061: try {
062: if (cmd.equals(Constants.ADD)
063: || cmd.equals(Constants.UPDATE)) {
064: updateFolder(req);
065: } else if (cmd.equals(Constants.DELETE)) {
066: deleteFolder(req);
067: }
068:
069: sendRedirect(req, res);
070: } catch (Exception e) {
071: if (e instanceof NoSuchFolderException
072: || e instanceof PrincipalException) {
073:
074: SessionErrors.add(req, e.getClass().getName());
075:
076: setForward(req, "portlet.document_library.error");
077: } else if (e instanceof DuplicateFileException
078: || e instanceof DuplicateFolderNameException
079: || e instanceof FolderNameException) {
080:
081: SessionErrors.add(req, e.getClass().getName());
082: } else {
083: throw e;
084: }
085: }
086: }
087:
088: public ActionForward render(ActionMapping mapping, ActionForm form,
089: PortletConfig config, RenderRequest req, RenderResponse res)
090: throws Exception {
091:
092: try {
093: ActionUtil.getFolder(req);
094: } catch (Exception e) {
095: if (e instanceof NoSuchFolderException
096: || e instanceof PrincipalException) {
097:
098: SessionErrors.add(req, e.getClass().getName());
099:
100: return mapping
101: .findForward("portlet.document_library.error");
102: } else {
103: throw e;
104: }
105: }
106:
107: return mapping.findForward(getForward(req,
108: "portlet.document_library.edit_folder"));
109: }
110:
111: protected void deleteFolder(ActionRequest req) throws Exception {
112: long folderId = ParamUtil.getLong(req, "folderId");
113:
114: DLFolderServiceUtil.deleteFolder(folderId);
115: }
116:
117: protected void updateFolder(ActionRequest req) throws Exception {
118: Layout layout = (Layout) req.getAttribute(WebKeys.LAYOUT);
119:
120: long folderId = ParamUtil.getLong(req, "folderId");
121:
122: long parentFolderId = ParamUtil.getLong(req, "parentFolderId");
123: String name = ParamUtil.getString(req, "name");
124: String description = ParamUtil.getString(req, "description");
125:
126: String[] communityPermissions = req
127: .getParameterValues("communityPermissions");
128: String[] guestPermissions = req
129: .getParameterValues("guestPermissions");
130:
131: if (folderId <= 0) {
132:
133: // Add folder
134:
135: DLFolderServiceUtil.addFolder(layout.getPlid(),
136: parentFolderId, name, description,
137: communityPermissions, guestPermissions);
138: } else {
139:
140: // Update folder
141:
142: DLFolderServiceUtil.updateFolder(folderId, parentFolderId,
143: name, description);
144: }
145: }
146:
147: }
|