KickJava   Java API By Example, From Geeks To Geeks.

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


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 java.util.LinkedList JavaDoc;
24
25 import javax.servlet.http.HttpServletRequest JavaDoc;
26 import javax.servlet.http.HttpServletResponse JavaDoc;
27
28 import org.apache.struts.action.Action;
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.ui.core.BasePageModel;
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
42 /**
43  * @struts.action path="/roller-ui/authoring/bookmarkEdit" name="bookmarkFormEx" validate="false"
44  * @struts.action-forward name="BookmarkForm" path=".BookmarkForm"
45  *
46  * @author Dave Johnson
47  */

48 public class BookmarkEditAction extends Action
49 {
50     public ActionForward execute(
51         ActionMapping mapping,
52         ActionForm actionForm,
53         HttpServletRequest JavaDoc request,
54         HttpServletResponse JavaDoc response)
55         throws Exception JavaDoc
56     {
57         RollerRequest rreq = RollerRequest.getRollerRequest(request);
58         RollerSession rses = RollerSession.getRollerSession(request);
59         BookmarkManager bmgr = RollerFactory.getRoller().getBookmarkManager();
60         BookmarkFormEx form = (BookmarkFormEx)actionForm;
61         
62         FolderData parentFolder = null;
63         if (null!=rreq.getBookmark() && null==request.getParameter("correct"))
64         {
65             // If request specifies bookmark and we are not correcting an
66
// already submitted form then load that bookmark into the form.
67
BookmarkData bd = rreq.getBookmark();
68             form.copyFrom(bd, request.getLocale());
69             request.setAttribute("state","edit");
70                 
71             // Pass bookmark's Folder on as attribute.
72
parentFolder = bd.getFolder();
73
74             request.setAttribute("model", new BasePageModel(
75                 "bookmarkForm.edit.title", request, response, mapping));
76         }
77         else if (null != request.getParameter("correct"))
78         {
79             // We are correcting a previously submtted form.
80
request.setAttribute("state","correcting");
81                 
82             // Folder is specified by request param, pass it on as attribute.
83
parentFolder = bmgr.getFolder(rreq.getFolder().getId());
84             
85             request.setAttribute("model", new BasePageModel(
86                 "bookmarkForm.correct.title", request, response, mapping));
87         }
88         else
89         {
90             // We are adding a new bookmark
91
request.setAttribute("state","add");
92             
93             // Folder is specified by request param, pass it on as attribute.
94
parentFolder = bmgr.getFolder(rreq.getFolder().getId());
95             
96             request.setAttribute("model", new BasePageModel(
97                 "bookmarkForm.add.title", request, response, mapping));
98         }
99         
100         // Build folder path for display on page
101
if (null != parentFolder)
102         {
103             request.setAttribute(
104                 RequestConstants.FOLDER_ID, parentFolder.getId());
105             
106             LinkedList JavaDoc folderPath = new LinkedList JavaDoc();
107             folderPath.add(0, parentFolder);
108             FolderData parent = parentFolder.getParent();
109             while (parent != null)
110             {
111                 folderPath.add(0, parent);
112                 parent = parent.getParent();
113             }
114             request.setAttribute("parentFolder", parentFolder);
115             request.setAttribute("folderPath", folderPath);
116         }
117         return mapping.findForward("BookmarkForm");
118     }
119     
120 }
121
Popular Tags