KickJava   Java API By Example, From Geeks To Geeks.

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


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.ActionForm;
28 import org.apache.struts.action.ActionForward;
29 import org.apache.struts.action.ActionMapping;
30 import org.apache.roller.model.BookmarkManager;
31 import org.apache.roller.model.RollerFactory;
32 import org.apache.roller.pojos.FolderData;
33 import org.apache.roller.ui.core.BasePageModel;
34 import org.apache.roller.ui.core.RollerRequest;
35 import org.apache.roller.ui.authoring.struts.formbeans.FolderFormEx;
36 import org.apache.roller.ui.core.RequestConstants;
37
38 /**
39  * @struts.action path="/roller-ui/authoring/folderEdit" name="folderFormEx" validate="false"
40  * @struts.action-forward name="FolderForm" path=".FolderForm"
41  *
42  * @author Dave Johnson
43  */

44 public class FolderEditAction extends Action
45 {
46     public ActionForward execute(
47         ActionMapping mapping,
48         ActionForm actionForm,
49         HttpServletRequest JavaDoc request,
50         HttpServletResponse JavaDoc response)
51         throws Exception JavaDoc
52     {
53         RollerRequest rreq = RollerRequest.getRollerRequest(request);
54         BookmarkManager bmgr = RollerFactory.getRoller().getBookmarkManager();
55         FolderFormEx form = (FolderFormEx)actionForm;
56         
57         FolderData parentFolder = null;
58         if (null!=rreq.getFolder() && null==request.getParameter("correct"))
59         {
60             // If request specifies folder and we are not correcting an
61
// already submitted form then load that folder into the form.
62
request.setAttribute("state","edit");
63
64             FolderData fd = rreq.getFolder();
65             form.copyFrom(fd, request.getLocale());
66             parentFolder = fd.getParent();
67             
68             BasePageModel pageModel = new BasePageModel(
69                 "folderForm.add.title", request, response, mapping);
70             pageModel.setWebsite(parentFolder.getWebsite());
71             request.setAttribute("model", pageModel);
72         }
73         else if (null != request.getParameter("correct"))
74         {
75             // We are correcting a previously submtted form.
76
request.setAttribute("state","correcting");
77             
78             String JavaDoc parentId = request.getParameter(RequestConstants.PARENT_ID);
79             parentFolder = bmgr.getFolder(parentId);
80             
81             BasePageModel pageModel = new BasePageModel(
82                 "folderForm.correct.title", request, response, mapping);
83             pageModel.setWebsite(parentFolder.getWebsite());
84             request.setAttribute("model", pageModel);
85         }
86         else
87         {
88             // We are adding a new bookmark
89
request.setAttribute("state","add");
90             
91             String JavaDoc parentId = request.getParameter(RequestConstants.PARENT_ID);
92             parentFolder = bmgr.getFolder(parentId);
93             
94             BasePageModel pageModel = new BasePageModel(
95                 "folderForm.add.title", request, response, mapping);
96             pageModel.setWebsite(parentFolder.getWebsite());
97             request.setAttribute("model", pageModel);
98         }
99         
100         request.setAttribute(RequestConstants.PARENT_ID, parentFolder.getId());
101         request.setAttribute("parentFolder", parentFolder);
102         
103         return mapping.findForward("FolderForm");
104     }
105
106 }
107
Popular Tags