1 18 21 package org.apache.roller.ui.authoring.struts.actions; 22 23 import java.util.Iterator ; 24 import java.util.LinkedList ; 25 import java.util.List ; 26 27 import javax.servlet.http.HttpServletRequest ; 28 import javax.servlet.http.HttpServletResponse ; 29 30 import org.apache.struts.action.Action; 31 import org.apache.struts.action.ActionForm; 32 import org.apache.struts.action.ActionForward; 33 import org.apache.struts.action.ActionMapping; 34 import org.apache.roller.model.RollerFactory; 35 import org.apache.roller.model.WeblogManager; 36 import org.apache.roller.pojos.WeblogCategoryData; 37 import org.apache.roller.ui.core.RollerRequest; 38 import org.apache.roller.ui.core.RollerSession; 39 import org.apache.roller.util.cache.CacheManager; 40 import org.apache.roller.ui.authoring.struts.formbeans.CategoryDeleteForm; 41 import org.apache.roller.ui.core.RequestConstants; 42 43 49 public class CategoryDeleteAction 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 CategoryDeleteForm form = (CategoryDeleteForm)actionForm; 60 WeblogManager wmgr = RollerFactory.getRoller().getWeblogManager(); 61 62 String catid = request.getParameter(RequestConstants.WEBLOGCATEGORY_ID); 63 WeblogCategoryData catToDelete = 64 wmgr.getWeblogCategory(catid); 65 RollerSession rses = RollerSession.getRollerSession(request); 66 if (rses.isUserAuthorizedToAuthor(catToDelete.getWebsite())) 67 { 68 String returnId = null; 69 if (catToDelete.getParent() != null) 70 { 71 returnId = catToDelete.getParent().getId(); 72 } 73 if (form.isDelete() == null) 74 { 75 RollerRequest rreq = RollerRequest.getRollerRequest(request); 77 WeblogCategoryData theCat = wmgr.getWeblogCategory(catid); 78 Iterator allCats = 79 wmgr.getWeblogCategories(theCat.getWebsite()).iterator(); 80 List destCats = new LinkedList (); 81 while (allCats.hasNext()) 82 { 83 WeblogCategoryData cat = (WeblogCategoryData)allCats.next(); 84 if (!cat.getId().equals(catid) 87 && cat.getParent()!=null 88 && !cat.descendentOf(catToDelete)) 89 { 90 destCats.add(cat); 91 } 92 } 93 if (destCats.size() > 0) 94 { 95 form.setName(theCat.getName()); 96 form.setCategoryId(catid); 97 form.setCats(destCats); 98 form.setInUse(Boolean.valueOf(catToDelete.isInUse())); 99 forward = mapping.findForward("CategoryDeleteOK"); 100 } 101 else 102 { 103 if (null != returnId) 105 { 106 request.setAttribute( 107 RequestConstants.WEBLOGCATEGORY_ID, returnId); 108 } 109 } 110 } 111 else if (form.isDelete().booleanValue()) { 112 113 if (form.getMoveToWeblogCategoryId() != null) 116 { 117 WeblogCategoryData destCat = 118 wmgr.getWeblogCategory(form.getMoveToWeblogCategoryId()); 119 if (rses.isUserAuthorizedToAuthor(destCat.getWebsite())) 120 { 121 wmgr.moveWeblogCategoryContents(catToDelete, destCat); 122 RollerFactory.getRoller().flush(); 123 } 124 else 125 { 126 return mapping.findForward("access-denied"); 127 } 128 } 129 130 catToDelete = wmgr.getWeblogCategory(catToDelete.getId()); 131 wmgr.removeWeblogCategory(catToDelete); 132 RollerFactory.getRoller().flush(); 133 134 CacheManager.invalidate(catToDelete); 136 137 if (null != returnId) 138 { 139 request.setAttribute(RequestConstants.WEBLOGCATEGORY_ID, returnId); 140 } 141 } 142 else 143 { 144 if (null != returnId) 146 { 147 request.setAttribute( 148 RequestConstants.WEBLOGCATEGORY_ID, returnId); 149 } 150 } 151 } 152 else 153 { 154 forward = mapping.findForward("access-denied"); 155 } 156 return forward; 157 } 158 159 } 160 | Popular Tags |