1 18 21 package org.apache.roller.ui.authoring.struts.actions; 22 23 import javax.servlet.http.HttpServletRequest ; 24 import javax.servlet.http.HttpServletResponse ; 25 26 import org.apache.struts.action.Action; 27 import org.apache.struts.action.ActionError; 28 import org.apache.struts.action.ActionErrors; 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.PermissionsData; 35 import org.apache.roller.pojos.WeblogCategoryData; 36 import org.apache.roller.ui.core.RollerRequest; 37 import org.apache.roller.ui.core.RollerSession; 38 import org.apache.roller.util.cache.CacheManager; 39 import org.apache.roller.ui.authoring.struts.formbeans.WeblogCategoryFormEx; 40 import org.apache.roller.ui.core.RequestConstants; 41 import org.apache.roller.RollerException; 42 43 49 public class CategorySaveAction extends Action 50 { 51 public ActionForward execute( 52 ActionMapping mapping, 53 ActionForm actionForm, 54 HttpServletRequest request, 55 HttpServletResponse response) 56 throws Exception 57 { 58 ActionForward forward = mapping.findForward("categories"); 59 WeblogCategoryFormEx form = (WeblogCategoryFormEx)actionForm; 60 RollerRequest rreq = RollerRequest.getRollerRequest(request); 61 WeblogManager wmgr = RollerFactory.getRoller().getWeblogManager(); 62 63 WeblogCategoryData cd = null; 64 if (null != form.getId() && !form.getId().trim().equals("")) 65 { 66 cd = wmgr.getWeblogCategory(form.getId()); 67 } 68 else 69 { 70 cd = new WeblogCategoryData(); 71 String pid = form.getParentId(); 72 WeblogCategoryData parentCat = wmgr.getWeblogCategory(pid); 73 cd.setWebsite(parentCat.getWebsite()); 74 cd.setParent(parentCat); 75 } 76 77 RollerSession rses = RollerSession.getRollerSession(request); 78 if (cd.getWebsite().hasUserPermissions( 79 rses.getAuthenticatedUser(), PermissionsData.AUTHOR)) 80 { 81 form.copyTo(cd, request.getLocale()); 82 try { 83 wmgr.saveWeblogCategory(cd); 84 RollerFactory.getRoller().flush(); 85 86 CacheManager.invalidate(cd); 88 } catch (RollerException re) { 89 ActionErrors errors = new ActionErrors(); 90 errors.add(ActionErrors.GLOBAL_ERROR, 91 new ActionError("error.untranslated", re.getMessage())); 92 saveErrors(request, errors); 93 } 94 } 95 else 96 { 97 ActionErrors errors = new ActionErrors(); 98 errors.add(null, new ActionError("error.permissions.deniedSave")); 99 saveErrors(request, errors); 100 forward = mapping.findForward("access-denied"); 101 } 102 request.setAttribute( 103 RequestConstants.WEBLOGCATEGORY_ID, cd.getParent().getId()); 104 return forward; 105 } 106 } 107 | Popular Tags |