1 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 ; 19 import javax.servlet.http.HttpServletResponse ; 20 21 29 public class CategorySaveAction extends Action 30 { 31 public ActionForward execute( 32 ActionMapping mapping, 33 ActionForm actionForm, 34 HttpServletRequest request, 35 HttpServletResponse response) 36 throws Exception 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(); } 51 else 52 { 53 cd = wmgr.createWeblogCategory(); 54 cd.setWebsite(rreq.getWebsite()); 55 56 String 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 |