KickJava   Java API By Example, From Geeks To Geeks.

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


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.ActionError;
8 import org.apache.struts.action.ActionErrors;
9 import org.apache.struts.action.ActionForm;
10 import org.apache.struts.action.ActionForward;
11 import org.apache.struts.action.ActionMapping;
12 import org.roller.RollerPermissionsException;
13 import org.roller.model.WeblogManager;
14 import org.roller.pojos.WeblogCategoryData;
15 import org.roller.presentation.RollerRequest;
16 import org.roller.presentation.weblog.formbeans.WeblogCategoryFormEx;
17
18 import javax.servlet.http.HttpServletRequest JavaDoc;
19 import javax.servlet.http.HttpServletResponse JavaDoc;
20
21 /**
22  * @struts.action path="/editor/categorySave" name="weblogCategoryFormEx"
23  * validate="true" input="/editor/categoryEdit.do"
24  *
25  * @struts.action-forward name="Categories" path="/editor/categories.do?method=selectCategory"
26  *
27  * @author Dave Johnson
28  */

29 public class CategorySaveAction 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         ActionForward forward = mapping.findForward("Categories");
39         try
40         {
41             WeblogCategoryFormEx form = (WeblogCategoryFormEx)actionForm;
42             RollerRequest rreq = RollerRequest.getRollerRequest(request);
43             WeblogManager wmgr = rreq.getRoller().getWeblogManager();
44             
45             WeblogCategoryData cd = null;
46             if (null != form.getId() && !form.getId().trim().equals(""))
47             {
48                 cd = wmgr.retrieveWeblogCategory(form.getId());
49                 cd.save(); // should throw if save not permitted
50
}
51             else
52             {
53                 cd = wmgr.createWeblogCategory();
54                 cd.setWebsite(rreq.getWebsite());
55                 
56                 String JavaDoc parentId = form.getParentId();
57                 cd.setParent(wmgr.retrieveWeblogCategory(parentId));
58             }
59             form.copyTo(cd, request.getLocale());
60             cd.save();
61             rreq.getRoller().commit();
62             
63             request.setAttribute(
64                 RollerRequest.WEBLOGCATEGORYID_KEY, cd.getParent().getId());
65         }
66         catch (RollerPermissionsException e)
67         {
68             ActionErrors errors = new ActionErrors();
69             errors.add(null, new ActionError("error.permissions.deniedSave"));
70             saveErrors(request, errors);
71             forward = mapping.findForward("access-denied");
72         }
73         return forward;
74     }
75 }
76
Popular Tags