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.CategoryDeleteForm; 15 16 import java.util.Iterator ; 17 import java.util.LinkedList ; 18 import java.util.List ; 19 20 import javax.servlet.http.HttpServletRequest ; 21 import javax.servlet.http.HttpServletResponse ; 22 23 30 public class CategoryDeleteAction extends Action 31 { 32 public ActionForward execute( 33 ActionMapping mapping, 34 ActionForm actionForm, 35 HttpServletRequest request, 36 HttpServletResponse response) 37 throws Exception 38 { 39 ActionForward forward = null; 40 CategoryDeleteForm form = (CategoryDeleteForm)actionForm; 41 RollerRequest rreq = RollerRequest.getRollerRequest(request); 42 WeblogManager wmgr = rreq.getRoller().getWeblogManager(); 43 44 if (rreq.isUserAuthorizedToEdit()) 45 { 46 String catid = request.getParameter("catid"); 47 WeblogCategoryData catToDelete = 48 wmgr.retrieveWeblogCategory(catid); 49 String returnId = null; 50 if (catToDelete.getParent() != null) 51 { 52 returnId = catToDelete.getParent().getId(); 53 } 54 if (form.isDelete() == null) 55 { 56 WebsiteData website = rreq.getWebsite(); 58 WeblogCategoryData theCat = wmgr.retrieveWeblogCategory(catid); 59 Iterator allCats = 60 wmgr.getWeblogCategories(website).iterator(); 61 List destCats = new LinkedList (); 62 while (allCats.hasNext()) 63 { 64 WeblogCategoryData cat = (WeblogCategoryData)allCats.next(); 65 if (!cat.getId().equals(catid) 68 && cat.getParent()!=null 69 && !cat.descendentOf(catToDelete)) 70 { 71 destCats.add(cat); 72 } 73 } 74 if (destCats.size() > 0) 75 { 76 form.setName(theCat.getName()); 77 form.setCatid(catid); 78 form.setCats(destCats); 79 form.setInUse(Boolean.valueOf(catToDelete.isInUse())); 80 forward = mapping.findForward("CategoryDeleteOK"); 81 } 82 else 83 { 84 if (null != returnId) 86 { 87 request.setAttribute( 88 RollerRequest.WEBLOGCATEGORYID_KEY, returnId); 89 } 90 forward = mapping.findForward("Categories"); 91 } 92 } 93 else if (form.isDelete().booleanValue()) 94 { 95 WeblogCategoryData destCat = null; 97 if (form.getMoveToWeblogCategoryId() != null) 98 { 99 destCat = wmgr.retrieveWeblogCategory(form.getMoveToWeblogCategoryId()); 100 } 101 102 catToDelete.remove(destCat); 104 105 rreq.getRoller().commit(); 106 107 if (null != returnId) 108 { 109 request.setAttribute( 110 RollerRequest.WEBLOGCATEGORYID_KEY, returnId); 111 } 112 forward = mapping.findForward("Categories"); 113 } 114 else 115 { 116 if (null != returnId) 118 { 119 request.setAttribute( 120 RollerRequest.WEBLOGCATEGORYID_KEY, returnId); 121 } 122 forward = mapping.findForward("Categories"); 123 } 124 } 125 else 126 { 127 forward = mapping.findForward("access-denied"); 128 } 129 return forward; 130 } 131 132 } 133 | Popular Tags |