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