1 18 21 package org.apache.roller.ui.authoring.struts.actions; 22 23 import java.util.LinkedList ; 24 25 import javax.servlet.http.HttpServletRequest ; 26 import javax.servlet.http.HttpServletResponse ; 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 46 public class CategoryEditAction extends Action 47 { 48 public ActionForward execute( 49 ActionMapping mapping, 50 ActionForm actionForm, 51 HttpServletRequest request, 52 HttpServletResponse response) 53 throws Exception 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 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 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 request.setAttribute("state","add"); 90 91 String 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 if (null != parentCat) 102 { 103 LinkedList categoryPath = new LinkedList (); 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 |