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.BookmarkData;
35: import org.apache.roller.pojos.FolderData;
36: import org.apache.roller.pojos.PermissionsData;
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.BookmarkFormEx;
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/bookmarkSave" name="bookmarkFormEx"
45: * validate="true" input="/roller-ui/authoring/bookmarkEdit.do"
46: * @struts.action-forward name="Bookmarks" path="/roller-ui/authoring/bookmarks.do?method=selectFolder"
47: *
48: * @author Dave Johnson
49: */
50: public class BookmarkSaveAction 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: BookmarkFormEx form = (BookmarkFormEx) actionForm;
56: RollerRequest rreq = RollerRequest.getRollerRequest(request);
57: BookmarkManager bmgr = RollerFactory.getRoller()
58: .getBookmarkManager();
59:
60: BookmarkData bd = null;
61: if (null != form.getId() && !form.getId().trim().equals("")) {
62: bd = bmgr.getBookmark(form.getId());
63: } else {
64: bd = new BookmarkData();
65: FolderData fd = bmgr.getFolder(request
66: .getParameter(RequestConstants.FOLDER_ID));
67: bd.setFolder(fd);
68: }
69: RollerSession rses = RollerSession.getRollerSession(request);
70: if (bd.getFolder().getWebsite().hasUserPermissions(
71: rses.getAuthenticatedUser(), PermissionsData.AUTHOR)) {
72: form.copyTo(bd, request.getLocale());
73: bmgr.saveBookmark(bd);
74: RollerFactory.getRoller().flush();
75:
76: CacheManager.invalidate(bd);
77:
78: request.setAttribute(RequestConstants.FOLDER_ID, bd
79: .getFolder().getId());
80: } else {
81: ActionErrors errors = new ActionErrors();
82: errors.add(null, new ActionError(
83: "error.permissions.deniedSave"));
84: saveErrors(request, errors);
85: forward = mapping.findForward("access-denied");
86: }
87: return forward;
88:
89: }
90:
91: }
|