KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > roller > ui > authoring > struts > actions > BookmarkSaveAction


1 /*
2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements. The ASF licenses this file to You
4 * under the Apache License, Version 2.0 (the "License"); you may not
5 * use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
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 JavaDoc;
24 import javax.servlet.http.HttpServletResponse JavaDoc;
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.model.BookmarkManager;
33 import org.apache.roller.model.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 {
52     public ActionForward execute(
53         ActionMapping mapping,
54         ActionForm actionForm,
55         HttpServletRequest JavaDoc request,
56         HttpServletResponse JavaDoc response)
57         throws Exception JavaDoc
58     {
59         ActionForward forward = mapping.findForward("Bookmarks");
60         BookmarkFormEx form = (BookmarkFormEx)actionForm;
61         RollerRequest rreq = RollerRequest.getRollerRequest(request);
62         BookmarkManager bmgr = RollerFactory.getRoller().getBookmarkManager();
63
64         BookmarkData bd = null;
65         if (null != form.getId() && !form.getId().trim().equals(""))
66         {
67             bd = bmgr.getBookmark(form.getId());
68         }
69         else
70         {
71             bd = new BookmarkData();
72             FolderData fd = bmgr.getFolder(
73                 request.getParameter(RequestConstants.FOLDER_ID));
74             bd.setFolder(fd);
75         }
76         RollerSession rses = RollerSession.getRollerSession(request);
77         if (bd.getFolder().getWebsite().hasUserPermissions(
78                 rses.getAuthenticatedUser(), PermissionsData.AUTHOR))
79         {
80             form.copyTo(bd, request.getLocale());
81             bmgr.saveBookmark(bd);
82             RollerFactory.getRoller().flush();
83             
84             CacheManager.invalidate(bd);
85             
86             request.setAttribute(
87                 RequestConstants.FOLDER_ID, bd.getFolder().getId());
88         }
89         else
90         {
91             ActionErrors errors = new ActionErrors();
92             errors.add(null, new ActionError("error.permissions.deniedSave"));
93             saveErrors(request, errors);
94             forward = mapping.findForward("access-denied");
95         }
96         return forward;
97         
98     }
99
100 }
101
Popular Tags