| 1 package org.nemesis.forum.webapp.admin.action; 2 3 import javax.servlet.http.HttpServletRequest ; 4 import javax.servlet.http.HttpServletResponse ; 5 6 import org.apache.commons.logging.Log; 7 import org.apache.commons.logging.LogFactory; 8 import org.apache.struts.action.ActionError; 9 import org.apache.struts.action.ActionErrors; 10 import org.apache.struts.action.ActionForm; 11 import org.apache.struts.action.ActionForward; 12 import org.apache.struts.action.ActionMapping; 13 import org.nemesis.forum.Forum; 14 import org.nemesis.forum.ForumFactory; 15 import org.nemesis.forum.ForumThread; 16 import org.nemesis.forum.Message; 17 import org.nemesis.forum.exception.ForumNotFoundException; 18 import org.nemesis.forum.exception.ForumThreadNotFoundException; 19 import org.nemesis.forum.exception.UnauthorizedException; 20 21 public class DelMessageAction extends BaseAction { 22 23 static protected Log log = LogFactory.getLog(DelMessageAction.class); 24 25 public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { 26 27 checkUser(request); 29 30 ActionErrors errors = new ActionErrors(); 31 boolean isRootmessage=false; 32 try { 33 34 ForumFactory forumFactory = ForumFactory.getInstance(getAuthToken(request)); 35 Forum forum = forumFactory.getForum(Integer.parseInt(request.getParameter("id"))); 36 request.setAttribute("id", request.getParameter("id")); 37 checkPermission(request, OperationConstants.DELETE_MESSAGE, forum); 39 40 ForumThread t=forum.getThread( Integer.parseInt(request.getParameter("threadID"))); 41 Message m=t.getMessage( Integer.parseInt(request.getParameter("messageID"))); 42 43 if(t.getRootMessage().getID()==(m.getID()))isRootmessage=true; 44 45 t.deleteMessage(m); 46 47 48 } catch (ForumNotFoundException e) { 49 errors.add("general", new ActionError("content.forumNotFound")); 50 } catch (ForumThreadNotFoundException e) { 51 errors.add("general", new ActionError("content.threadNotFound")); 52 } catch (UnauthorizedException ue) { 53 errors.add("general", new ActionError("content.Unauthorized")); 54 } catch (Exception e) { 55 String eid = this.getClass().getName() + "_" + System.currentTimeMillis(); 56 log.error("eid:" + eid + "\nsessionID" + request.getSession().getId(), e); 57 errors.add("general", new ActionError("error.general", "erreur id:" + eid)); 58 } 59 60 if (!errors.isEmpty()) { 61 saveErrors(request, errors); 62 return mapping.findForward("cancel"); 63 } 64 65 if(isRootmessage) return mapping.findForward("success2"); 66 else return mapping.findForward("success"); 67 68 } 69 } | Popular Tags |