1 4 package org.roller.presentation.bookmarks.actions; 5 6 import javax.servlet.http.HttpServletRequest ; 7 import javax.servlet.http.HttpServletResponse ; 8 9 import org.apache.struts.action.Action; 10 import org.apache.struts.action.ActionError; 11 import org.apache.struts.action.ActionErrors; 12 import org.apache.struts.action.ActionForm; 13 import org.apache.struts.action.ActionForward; 14 import org.apache.struts.action.ActionMapping; 15 import org.roller.RollerException; 16 import org.roller.RollerPermissionsException; 17 import org.roller.model.BookmarkManager; 18 import org.roller.pojos.FolderData; 19 import org.roller.pojos.WebsiteData; 20 import org.roller.presentation.RollerRequest; 21 import org.roller.presentation.bookmarks.formbeans.FolderFormEx; 22 23 30 public class FolderSaveAction 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 = mapping.findForward("Bookmarks"); 40 FolderFormEx form = (FolderFormEx)actionForm; 41 RollerRequest rreq = RollerRequest.getRollerRequest(request); 42 WebsiteData wd = rreq.getWebsite(); 43 BookmarkManager bmgr = rreq.getRoller().getBookmarkManager(); 44 45 FolderData fd = null; 46 if (null != form.getId() && !form.getId().trim().equals("")) 47 { 48 fd = bmgr.retrieveFolder(form.getId()); 49 fd.save(); } 51 else 52 { 53 fd = bmgr.createFolder(); 54 55 String parentId = request.getParameter(RollerRequest.PARENTID_KEY); 56 FolderData parent = null; 57 if (null != parentId && !parentId.trim().equalsIgnoreCase("null")) 58 { 59 parent = bmgr.retrieveFolder(parentId); 60 } 61 else 62 { 63 parent = bmgr.getRootFolder(wd); 64 } 65 fd.setParent(parent); 66 fd.setWebsite(wd); 67 } 68 69 form.copyTo(fd, request.getLocale()); 71 72 try 73 { 74 fd.save(); 76 rreq.getRoller().commit(); 77 } 78 catch (RollerPermissionsException e) 79 { 80 ActionErrors errors = new ActionErrors(); 81 errors.add(null, new ActionError("error.permissions.deniedSave")); 82 saveErrors(request, errors); 83 forward = mapping.findForward("access-denied"); 84 } 85 catch (RollerException re) 86 { 87 rreq.getRoller().rollback(); 88 ActionErrors errors = new ActionErrors(); 89 String msg = (null != re.getRootCause()) 90 ? re.getRootCause().toString() 91 : re.toString(); 92 errors.add(ActionErrors.GLOBAL_ERROR, 93 new ActionError("folderForm.save.exception", msg)); 94 saveErrors(request,errors); 95 } 96 97 if (null != fd.getParent()) 98 { 99 request.setAttribute( 100 RollerRequest.FOLDERID_KEY, fd.getParent().getId()); 101 } 102 return forward; 103 } 104 } 105 | Popular Tags |