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.ForumFactory; 18 import org.nemesis.forum.ProfileManager; 19 import org.nemesis.forum.User; 20 import org.nemesis.forum.exception.UnauthorizedException; 21 import org.nemesis.forum.webapp.admin.bean.UserBean; 22 23 29 public class EditUserAction extends BaseAction { 30 31 static protected Log log = LogFactory.getLog(EditUserAction.class); 32 33 public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { 34 35 checkUser(request); 37 checkPermission(request, OperationConstants.EDIT_USER); 39 40 ActionErrors errors = new ActionErrors(); 41 if (isCancelled(request)) { 43 return (mapping.findForward("cancel")); 44 } 45 46 try { 47 48 ForumFactory forumFactory = ForumFactory.getInstance(getAuthToken(request)); 49 ProfileManager manager = forumFactory.getProfileManager(); 50 User user = manager.getUser(getAuthToken(request).getUserID()); 51 try { 52 53 User u = manager.getUser(Integer.parseInt(request.getParameter("userBean.id"))); 55 56 if (request.getParameter("userBean.userName") == null) { 58 UserBean ub = new UserBean(); 59 ub.setId(u.getID()); 60 ub.setEmail(u.getEmail()); 61 ub.setEmailVisible(u.isEmailVisible()); 62 ub.setName(u.getName()); 63 ub.setNameVisible(u.isNameVisible()); 64 ub.setUserName(u.getUsername()); 65 String key=null; 66 for(Enumeration e= u.propertyNames();e.hasMoreElements();){ 67 key=(String )e.nextElement(); 68 ub.setPropertie(key, u.getProperty(key)); 69 } 70 71 PropertyUtils.setProperty(form, "userBean", ub); 72 return mapping.findForward("view"); 73 } 74 75 errors = form.validate(mapping,request); 77 if (!errors.isEmpty()) { 78 saveErrors(request, errors); 79 return mapping.findForward("view"); 80 } 81 UserBean ub = (UserBean) PropertyUtils.getProperty(form, "userBean"); 83 84 u.setEmail(ub.getEmail()); 85 u.setEmailVisible(ub.isEmailVisible()); 86 u.setName(ub.getName()); 87 u.setNameVisible(ub.isNameVisible()); 88 89 if(ub.isChangePassword()){ 91 u.setPassword(ub.getPassword()); 92 } 93 String temp = null; 95 for (Iterator it = ub.getProperties().keySet().iterator(); it.hasNext();) { 96 temp = (String ) it.next(); 97 u.setProperty(temp, (String ) ub.getProperties().get(temp)); 98 } 99 100 101 }catch( NumberFormatException aee ) { 102 return mapping.findForward("cancel"); 103 } catch (UnauthorizedException aee) { 104 errors.add("general", new ActionError("addUser.unauthorized")); 105 return mapping.findForward("cancel"); 106 } 107 108 } catch (Exception e) { 109 String eid = this.getClass().getName() + "_" + System.currentTimeMillis(); 110 log.error("eid:" + eid + "\nsessionID" + request.getSession().getId(), e); 111 errors.add("general", new ActionError("error.general", "erreur id:" + eid)); 112 } 113 114 115 116 return mapping.findForward("success"); 117 } 118 119 } | Popular Tags |