1 package org.nemesis.forum.webapp.admin.action; 2 3 import java.util.Enumeration ; 4 import java.util.Iterator ; 5 6 import javax.servlet.http.HttpServletRequest ; 7 import javax.servlet.http.HttpServletResponse ; 8 9 import org.apache.commons.beanutils.PropertyUtils; 10 import org.apache.commons.logging.Log; 11 import org.apache.commons.logging.LogFactory; 12 import org.apache.struts.action.ActionError; 13 import org.apache.struts.action.ActionErrors; 14 import org.apache.struts.action.ActionForm; 15 import org.apache.struts.action.ActionForward; 16 import org.apache.struts.action.ActionMapping; 17 import org.nemesis.forum.Forum; 18 import org.nemesis.forum.ForumFactory; 19 import org.nemesis.forum.webapp.admin.bean.ForumBean; 20 import org.nemesis.forum.webapp.exception.UnauthorizedException; 21 22 27 public class EditForumAction extends BaseAction { 28 29 static protected Log log = LogFactory.getLog(EditForumAction.class); 30 31 public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { 32 33 checkUser(request); 35 36 ActionErrors errors = new ActionErrors(); 37 if (isCancelled(request)) { 39 return (mapping.findForward("cancel")); 40 } 41 42 try { 43 44 ForumFactory forumFactory = ForumFactory.getInstance(getAuthToken(request)); 45 Forum forum = forumFactory.getForum(Integer.parseInt(request.getParameter("id"))); 46 47 checkPermission(request, OperationConstants.EDIT_FORUM, forum); 49 50 if (request.getParameter("forumBean.id") == null) { 52 53 ForumBean fb =new ForumBean(); 54 fb.setDescription(forum.getDescription()); 55 fb.setId(forum.getID()); 56 fb.setModerationType(forum.getModerationType()); 57 fb.setName(forum.getName()); 58 String key=null; 59 for(Enumeration e= forum.propertyNames();e.hasMoreElements();){ 60 key=(String )e.nextElement(); 61 fb.setPropertie(key, forum.getProperty(key)); 62 } 63 64 PropertyUtils.setProperty(form, "forumBean", fb); 65 return mapping.findForward("view"); 66 } 67 68 ForumBean fb = (ForumBean) PropertyUtils.getProperty(form, "forumBean"); 70 forum.setModerationType(fb.getModerationType()); 71 forum.setDescription(fb.getDescription()); 72 74 String temp = null; 76 for (Iterator it = fb.getProperties().keySet().iterator(); it.hasNext();) { 77 temp = (String ) it.next(); 78 forum.setProperty(temp, (String ) fb.getProperties().get(temp)); 79 } 80 81 } catch (NumberFormatException aee) { 82 errors.add("general", new ActionError("addForum.unauthorized")); 83 } catch (UnauthorizedException aee) { 84 errors.add("general", new ActionError("addForum.unauthorized")); 85 saveErrors(request, errors); 86 return mapping.findForward("cancel"); 87 } catch (Exception e) { 88 String eid = this.getClass().getName() + "_" + System.currentTimeMillis(); 89 log.error("eid:" + eid + "\nsessionID" + request.getSession().getId(), e); 90 errors.add("general", new ActionError("error.general", "erreur id:" + eid)); 91 } 92 93 if (!errors.isEmpty()) { 94 saveErrors(request, errors); 95 return (mapping.findForward("cancel")); 96 } 97 98 return mapping.findForward("success"); 99 } 100 101 } | Popular Tags |