01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. The ASF licenses this file to You
04: * under the Apache License, Version 2.0 (the "License"); you may not
05: * use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License. For additional information regarding
15: * copyright in this work, please see the NOTICE file in the top level
16: * directory of this distribution.
17: */
18: /*
19: * Created on Oct 21, 2003
20: */
21: package org.apache.roller.ui.authoring.struts.actions;
22:
23: import javax.servlet.http.HttpServletRequest;
24: import javax.servlet.http.HttpServletResponse;
25:
26: import org.apache.struts.action.Action;
27: import org.apache.struts.action.ActionError;
28: import org.apache.struts.action.ActionErrors;
29: import org.apache.struts.action.ActionForm;
30: import org.apache.struts.action.ActionForward;
31: import org.apache.struts.action.ActionMapping;
32: import org.apache.roller.business.BookmarkManager;
33: import org.apache.roller.business.RollerFactory;
34: import org.apache.roller.pojos.FolderData;
35: import org.apache.roller.pojos.PermissionsData;
36: import org.apache.roller.pojos.WebsiteData;
37: import org.apache.roller.ui.core.RollerRequest;
38: import org.apache.roller.ui.core.RollerSession;
39: import org.apache.roller.ui.authoring.struts.formbeans.FolderFormEx;
40: import org.apache.roller.ui.core.RequestConstants;
41: import org.apache.roller.util.cache.CacheManager;
42:
43: /**
44: * @struts.action path="/roller-ui/authoring/folderSave" name="folderFormEx"
45: * validate="true" input="/roller-ui/authoring/folderEdit.do"
46: * @struts.action-forward name="Bookmarks" path="/roller-ui/authoring/bookmarks.do?method=selectFolder"
47: *
48: * @author Dave Johnson
49: */
50: public class FolderSaveAction extends Action {
51: public ActionForward execute(ActionMapping mapping,
52: ActionForm actionForm, HttpServletRequest request,
53: HttpServletResponse response) throws Exception {
54: ActionForward forward = mapping.findForward("Bookmarks");
55: FolderFormEx form = (FolderFormEx) actionForm;
56: RollerRequest rreq = RollerRequest.getRollerRequest(request);
57: RollerSession rses = RollerSession.getRollerSession(request);
58: BookmarkManager bmgr = RollerFactory.getRoller()
59: .getBookmarkManager();
60: WebsiteData website = null;
61:
62: FolderData fd = null;
63: if (null != form.getId() && !form.getId().trim().equals("")) {
64: fd = bmgr.getFolder(form.getId());
65: website = fd.getWebsite();
66: } else {
67: fd = new FolderData();
68: String parentId = request
69: .getParameter(RequestConstants.PARENT_ID);
70: FolderData parent = bmgr.getFolder(parentId);
71: website = parent.getWebsite();
72: fd.setParent(parent);
73: fd.setWebsite(website);
74: }
75:
76: if (fd.getWebsite().hasUserPermissions(
77: rses.getAuthenticatedUser(), PermissionsData.AUTHOR)) {
78: // Copy form values to object
79: form.copyTo(fd, request.getLocale());
80: bmgr.saveFolder(fd);
81: RollerFactory.getRoller().flush();
82:
83: CacheManager.invalidate(fd);
84: } else {
85: ActionErrors errors = new ActionErrors();
86: errors.add(null, new ActionError(
87: "error.permissions.deniedSave"));
88: saveErrors(request, errors);
89: forward = mapping.findForward("access-denied");
90: }
91: if (null != fd.getParent()) {
92: request.setAttribute(RequestConstants.FOLDER_ID, fd
93: .getParent().getId());
94: }
95: return forward;
96: }
97: }
|