KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > roller > presentation > bookmarks > actions > BookmarkSaveAction


1 /*
2  * Created on Oct 21, 2003
3  */

4 package org.roller.presentation.bookmarks.actions;
5
6 import javax.servlet.http.HttpServletRequest JavaDoc;
7 import javax.servlet.http.HttpServletResponse JavaDoc;
8
9 import org.apache.struts.action.Action;
10 import org.apache.struts.action.ActionError;
11 import org.apache.struts.action.ActionErrors;
12 import org.apache.struts.action.ActionForm;
13 import org.apache.struts.action.ActionForward;
14 import org.apache.struts.action.ActionMapping;
15 import org.roller.RollerPermissionsException;
16 import org.roller.model.BookmarkManager;
17 import org.roller.pojos.BookmarkData;
18 import org.roller.pojos.FolderData;
19 import org.roller.presentation.RollerRequest;
20 import org.roller.presentation.bookmarks.formbeans.BookmarkFormEx;
21
22 /**
23  * @struts.action path="/editor/bookmarkSave" name="bookmarkFormEx"
24  * validate="true" input="/editor/bookmarkEdit.do"
25  * @struts.action-forward name="Bookmarks" path="/editor/bookmarks.do?method=selectFolder"
26  *
27  * @author Dave Johnson
28  */

29 public class BookmarkSaveAction extends Action
30 {
31     public ActionForward execute(
32         ActionMapping mapping,
33         ActionForm actionForm,
34         HttpServletRequest JavaDoc request,
35         HttpServletResponse JavaDoc response)
36         throws Exception JavaDoc
37     {
38         ActionForward forward = mapping.findForward("Bookmarks");
39         try
40         {
41             BookmarkFormEx form = (BookmarkFormEx)actionForm;
42             RollerRequest rreq = RollerRequest.getRollerRequest(request);
43             BookmarkManager bmgr = rreq.getRoller().getBookmarkManager();
44             
45             BookmarkData bd = null;
46             if (null != form.getId() && !form.getId().trim().equals(""))
47             {
48                 bd = bmgr.retrieveBookmark(form.getId());
49                 bd.save(); // should throw if save not permitted
50
}
51             else
52             {
53                 bd = bmgr.createBookmark();
54                 
55                 // Existing bookmarks already have folders, but this is a new one.
56
FolderData fd = bmgr.retrieveFolder(
57                     request.getParameter(RollerRequest.FOLDERID_KEY));
58                 bd.setFolder(fd);
59             }
60             form.copyTo(bd, request.getLocale());
61             bd.save();
62             rreq.getRoller().commit();
63             
64             request.setAttribute(
65                 RollerRequest.FOLDERID_KEY,bd.getFolder().getId());
66         }
67         catch (RollerPermissionsException e)
68         {
69             ActionErrors errors = new ActionErrors();
70             errors.add(null, new ActionError("error.permissions.deniedSave"));
71             saveErrors(request, errors);
72             forward = mapping.findForward("access-denied");
73         }
74         return forward;
75         
76     }
77
78 }
79
Popular Tags