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