1 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 ; 17 18 import javax.servlet.http.HttpServletRequest ; 19 import javax.servlet.http.HttpServletResponse ; 20 21 27 public class CategoryEditAction extends Action 28 { 29 public ActionForward execute( 30 ActionMapping mapping, 31 ActionForm actionForm, 32 HttpServletRequest request, 33 HttpServletResponse response) 34 throws Exception 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 WeblogCategoryData cd = rreq.getWeblogCategory(); 47 form.copyFrom(cd, request.getLocale()); 48 request.setAttribute("state","edit"); 49 50 parentCat = cd.getParent(); 52 request.setAttribute( 53 RollerRequest.WEBLOGCATEGORYID_KEY, parentCat.getId()); 54 } 55 else if (null != request.getParameter("correct")) 56 { 57 request.setAttribute("state","correcting"); 59 60 parentCat = wmgr.retrieveWeblogCategory(rreq.getWeblogCategory().getId()); 62 request.setAttribute( 63 RollerRequest.WEBLOGCATEGORYID_KEY, parentCat.getId()); 64 } 65 else 66 { 67 request.setAttribute("state","add"); 69 70 String parentId = request.getParameter(RollerRequest.PARENTID_KEY); 72 form.setParentId(parentId); 73 } 74 75 if (null != parentCat) 77 { 78 LinkedList categoryPath = new LinkedList (); 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 |