KickJava   Java API By Example, From Geeks To Geeks.

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


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.RollerFactory;
33 import org.apache.roller.model.WeblogManager;
34 import org.apache.roller.pojos.WeblogCategoryData;
35 import org.apache.roller.ui.core.BasePageModel;
36 import org.apache.roller.ui.core.RollerRequest;
37 import org.apache.roller.ui.authoring.struts.formbeans.WeblogCategoryFormEx;
38 import org.apache.roller.ui.core.RequestConstants;
39
40 /**
41  * @struts.action path="/roller-ui/authoring/categoryEdit" name="weblogCategoryFormEx" validate="false"
42  * @struts.action-forward name="CategoryForm" path=".CategoryForm"
43  *
44  * @author Dave Johnson
45  */

46 public class CategoryEditAction extends Action
47 {
48     public ActionForward execute(
49         ActionMapping mapping,
50         ActionForm actionForm,
51         HttpServletRequest JavaDoc request,
52         HttpServletResponse JavaDoc response)
53         throws Exception JavaDoc
54     {
55         RollerRequest rreq = RollerRequest.getRollerRequest(request);
56         WeblogManager wmgr = RollerFactory.getRoller().getWeblogManager();
57         WeblogCategoryFormEx form = (WeblogCategoryFormEx)actionForm;
58         
59         BasePageModel pageModel = null;
60         WeblogCategoryData parentCat = null;
61         if (null!=rreq.getWeblogCategory() && null==request.getParameter("correct"))
62         {
63             // If request specifies Category and we are not correcting an
64
// already submitted form then load that Category into the form.
65
WeblogCategoryData cd = rreq.getWeblogCategory();
66             form.copyFrom(cd, request.getLocale());
67             request.setAttribute("state","edit");
68                              
69             parentCat = cd.getParent();
70             pageModel = new BasePageModel(
71                 "categoryForm.edit.title", request, response, mapping);
72             pageModel.setWebsite(cd.getWebsite());
73         }
74         else if (null != request.getParameter("correct"))
75         {
76             // We are correcting a previously submtted form.
77
// already submitted form then load that Category into the form.
78
WeblogCategoryData cd = rreq.getWeblogCategory();
79             request.setAttribute("state","correcting");
80             
81             parentCat = wmgr.getWeblogCategory(cd.getId());
82             pageModel = new BasePageModel(
83                 "categoryForm.correct.title", request, response, mapping);
84             pageModel.setWebsite(cd.getWebsite());
85         }
86         else
87         {
88             // We are adding a new Category
89
request.setAttribute("state","add");
90             
91             String JavaDoc pid = request.getParameter(RequestConstants.PARENT_ID);
92             parentCat = wmgr.getWeblogCategory(pid);
93             form.setParentId(parentCat.getId());
94             
95             pageModel = new BasePageModel(
96                 "categoryForm.add.title", request, response, mapping);
97             pageModel.setWebsite(parentCat.getWebsite());
98         }
99         
100         // Build cat path for display on page
101
if (null != parentCat)
102         {
103             LinkedList JavaDoc categoryPath = new LinkedList JavaDoc();
104             categoryPath.add(0, parentCat);
105             WeblogCategoryData parent = parentCat.getParent();
106             while (parent != null)
107             {
108                 categoryPath.add(0, parent);
109                 parent = parent.getParent();
110             }
111             request.setAttribute("parentCategory", parentCat);
112             request.setAttribute("categoryPath", categoryPath);
113         }
114         
115         request.setAttribute("model", pageModel);
116         return mapping.findForward("CategoryForm");
117     }
118     
119 }
120
Popular Tags