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.beanutils.PropertyUtils; 7 import org.apache.commons.logging.Log; 8 import org.apache.commons.logging.LogFactory; 9 import org.apache.struts.action.ActionError; 10 import org.apache.struts.action.ActionErrors; 11 import org.apache.struts.action.ActionForm; 12 import org.apache.struts.action.ActionForward; 13 import org.apache.struts.action.ActionMapping; 14 import org.nemesis.forum.ForumFactory; 15 import org.nemesis.forum.Group; 16 import org.nemesis.forum.ProfileManager; 17 import org.nemesis.forum.User; 18 import org.nemesis.forum.exception.UnauthorizedException; 19 20 public class EditGroupAction extends BaseAction { 21 22 static protected Log log = LogFactory.getLog(EditGroupAction.class); 23 24 public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { 25 26 checkUser(request); 28 checkPermission(request, OperationConstants.EDIT_GROUP); 30 31 ActionErrors errors = new ActionErrors(); 32 33 if (isCancelled(request)) { 35 return (mapping.findForward("cancel")); 36 } 37 38 try { 39 40 ForumFactory forumFactory = ForumFactory.getInstance(getAuthToken(request)); 41 ProfileManager manager = forumFactory.getProfileManager(); 42 User user = manager.getUser(getAuthToken(request).getUserID()); 43 44 Group group = manager.getGroup(Integer.parseInt(request.getParameter("id"))); 46 47 if (request.getParameter("name") == null) { 49 PropertyUtils.setSimpleProperty(form, "id", new Integer (group.getID())); 50 PropertyUtils.setSimpleProperty(form, "name", group.getName()); 51 PropertyUtils.setSimpleProperty(form, "description", group.getDescription()); 52 return mapping.findForward("view"); 53 } 54 group.setName((String ) PropertyUtils.getSimpleProperty(form, "name")); 56 group.setDescription((String ) PropertyUtils.getSimpleProperty(form, "description")); 57 58 } catch (NumberFormatException aee) { 59 return mapping.findForward("success"); 61 } catch (UnauthorizedException aee) { 62 errors.add("general", new ActionError("editGroup.unauthorized")); 63 return mapping.findForward("view"); 64 65 } catch (Exception e) { 66 String eid = this.getClass().getName() + "_" + System.currentTimeMillis(); 67 log.error("eid:" + eid + "\nsessionID" + request.getSession().getId(), e); 68 errors.add("general", new ActionError("error.general", "erreur id:" + eid)); 69 } 70 71 if (!errors.isEmpty()) { 72 saveErrors(request, errors); 73 return mapping.findForward("view"); 74 } 75 76 return mapping.findForward("success"); 77 } 78 79 } | Popular Tags |