KickJava   Java API By Example, From Geeks To Geeks.

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


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

4 package org.roller.presentation.bookmarks.actions;
5
6 import org.apache.struts.action.Action;
7 import org.apache.struts.action.ActionForm;
8 import org.apache.struts.action.ActionForward;
9 import org.apache.struts.action.ActionMapping;
10 import org.roller.model.BookmarkManager;
11 import org.roller.pojos.BookmarkData;
12 import org.roller.pojos.FolderData;
13 import org.roller.pojos.WebsiteData;
14 import org.roller.presentation.RollerRequest;
15 import org.roller.presentation.bookmarks.formbeans.BookmarkFormEx;
16 import org.roller.presentation.forms.BookmarkForm;
17
18 import java.util.LinkedList JavaDoc;
19
20 import javax.servlet.http.HttpServletRequest JavaDoc;
21 import javax.servlet.http.HttpServletResponse JavaDoc;
22
23 /**
24  * @struts.action path="/editor/bookmarkEdit" name="bookmarkFormEx" validate="false"
25  * @struts.action-forward name="BookmarkForm" path="/bookmarks/BookmarkForm.jsp"
26  *
27  * @author Dave Johnson
28  */

29 public class BookmarkEditAction 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         RollerRequest rreq = RollerRequest.getRollerRequest(request);
39         WebsiteData wd = rreq.getWebsite();
40         BookmarkManager bmgr = rreq.getRoller().getBookmarkManager();
41         BookmarkFormEx form = (BookmarkFormEx)actionForm;
42         
43         FolderData parentFolder = null;
44         if (null!=rreq.getBookmark() && null==request.getParameter("correct"))
45         {
46             // If request specifies bookmark and we are not correcting an
47
// already submitted form then load that bookmark into the form.
48
BookmarkData bd = rreq.getBookmark();
49             form.copyFrom(bd, request.getLocale());
50             request.setAttribute("state","edit");
51                 
52             // Pass bookmark's Folder on as attribute.
53
parentFolder = bd.getFolder();
54         }
55         else if (null != request.getParameter("correct"))
56         {
57             // We are correcting a previously submtted form.
58
request.setAttribute("state","correcting");
59                 
60             // Folder is specified by request param, pass it on as attribute.
61
parentFolder = bmgr.retrieveFolder(rreq.getFolder().getId());
62         }
63         else
64         {
65             // We are adding a new bookmark
66
request.setAttribute("state","add");
67             
68             // Folder is specified by request param, pass it on as attribute.
69
parentFolder = bmgr.retrieveFolder(rreq.getFolder().getId());
70         }
71         
72         // Build folder path for display on page
73
if (null != parentFolder)
74         {
75             request.setAttribute(
76                 RollerRequest.FOLDERID_KEY, parentFolder.getId());
77             
78             LinkedList JavaDoc folderPath = new LinkedList JavaDoc();
79             folderPath.add(0, parentFolder);
80             FolderData parent = parentFolder.getParent();
81             while (parent != null)
82             {
83                 folderPath.add(0, parent);
84                 parent = parent.getParent();
85             }
86             request.setAttribute("parentFolder", parentFolder);
87             request.setAttribute("folderPath", folderPath);
88         }
89
90         return mapping.findForward("BookmarkForm");
91     }
92     
93 }
94
Popular Tags