KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > roller > presentation > weblog > actions > CategoryEditAction


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

4 package org.roller.presentation.weblog.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.WeblogManager;
11 import org.roller.pojos.WeblogCategoryData;
12 import org.roller.pojos.WebsiteData;
13 import org.roller.presentation.RollerRequest;
14 import org.roller.presentation.weblog.formbeans.WeblogCategoryFormEx;
15
16 import java.util.LinkedList JavaDoc;
17
18 import javax.servlet.http.HttpServletRequest JavaDoc;
19 import javax.servlet.http.HttpServletResponse JavaDoc;
20
21 /**
22  * @struts.action path="/editor/categoryEdit" name="weblogCategoryFormEx" validate="false"
23  * @struts.action-forward name="CategoryForm" path="/weblog/CategoryForm.jsp"
24  *
25  * @author Dave Johnson
26  */

27 public class CategoryEditAction extends Action
28 {
29     public ActionForward execute(
30         ActionMapping mapping,
31         ActionForm actionForm,
32         HttpServletRequest JavaDoc request,
33         HttpServletResponse JavaDoc response)
34         throws Exception JavaDoc
35     {
36         RollerRequest rreq = RollerRequest.getRollerRequest(request);
37         WebsiteData wd = rreq.getWebsite();
38         WeblogManager wmgr = rreq.getRoller().getWeblogManager();
39         WeblogCategoryFormEx form = (WeblogCategoryFormEx)actionForm;
40         
41         WeblogCategoryData parentCat = null;
42         if (null!=rreq.getWeblogCategory() && null==request.getParameter("correct"))
43         {
44             // If request specifies Category and we are not correcting an
45
// already submitted form then load that Category into the form.
46
WeblogCategoryData cd = rreq.getWeblogCategory();
47             form.copyFrom(cd, request.getLocale());
48             request.setAttribute("state","edit");
49                 
50             // Pass Category's parent id on as attribute.
51
parentCat = cd.getParent();
52             request.setAttribute(
53                 RollerRequest.WEBLOGCATEGORYID_KEY, parentCat.getId());
54         }
55         else if (null != request.getParameter("correct"))
56         {
57             // We are correcting a previously submtted form.
58
request.setAttribute("state","correcting");
59                 
60             // Cat is specified by request param, pass it on as attribute.
61
parentCat = wmgr.retrieveWeblogCategory(rreq.getWeblogCategory().getId());
62             request.setAttribute(
63                 RollerRequest.WEBLOGCATEGORYID_KEY, parentCat.getId());
64         }
65         else
66         {
67             // We are adding a new Category
68
request.setAttribute("state","add");
69             
70             // Cat is specified by request param, pass it on as attribute.
71
String JavaDoc parentId = request.getParameter(RollerRequest.PARENTID_KEY);
72             form.setParentId(parentId);
73         }
74         
75         // Build cat path for display on page
76
if (null != parentCat)
77         {
78             LinkedList JavaDoc categoryPath = new LinkedList JavaDoc();
79             categoryPath.add(0, parentCat);
80             WeblogCategoryData parent = parentCat.getParent();
81             while (parent != null)
82             {
83                 categoryPath.add(0, parent);
84                 parent = parent.getParent();
85             }
86             request.setAttribute("parentCategory", parentCat);
87             request.setAttribute("categoryPath", categoryPath);
88         }
89
90         return mapping.findForward("CategoryForm");
91     }
92     
93 }
94
Popular Tags