1 package org.nextime.ion.admin.action.user; 2 3 import java.io.IOException ; 4 import java.util.Enumeration ; 5 6 import javax.servlet.ServletException ; 7 import javax.servlet.http.HttpServletRequest ; 8 import javax.servlet.http.HttpServletResponse ; 9 import org.apache.struts.action.Action; 10 import org.apache.struts.action.ActionForm; 11 import org.apache.struts.action.ActionForward; 12 import org.apache.struts.action.ActionMapping; 13 14 import org.nextime.ion.admin.form.UserForm; 15 import org.nextime.ion.framework.business.Group; 16 import org.nextime.ion.framework.business.User; 17 import org.nextime.ion.framework.business.impl.UserImpl; 18 import org.nextime.ion.framework.mapping.Mapping; 19 20 public class EditUserAction extends Action { 21 22 public ActionForward perform( 23 ActionMapping mapping, 24 ActionForm form, 25 HttpServletRequest request, 26 HttpServletResponse response) 27 throws IOException , ServletException { 28 29 request.setAttribute("view", "user"); 31 32 if( request.getParameter("id") != null ) 33 request.setAttribute("id", request.getParameter("id")); 34 String id = request.getAttribute("id")+""; 35 36 try { 37 38 Mapping.begin(); 40 request.setAttribute("groupList", Group.listAll()); 41 Mapping.commit(); 42 43 if (request.getParameter("editSubmit") == null) { 44 Mapping.begin(); 45 46 User u = User.getInstance(id); 48 UserForm f = (UserForm) form; 49 f.setLogin(u.getLogin()); 50 f.setPassword(u.getPassword()); 51 f.setGroups(u.getGroupsIds()); 52 request.setAttribute("metaData", ((UserImpl) u).getMetaData()); 53 54 Mapping.commit(); 55 return new ActionForward( mapping.getInput() ); 56 } 57 58 Mapping.begin(); 60 UserForm f = (UserForm) form; 61 User u = User.getInstance(id); 62 u.setPassword(f.getPassword()); 63 String [] g = f.getGroups(); 64 u.resetGroups(); 65 if (g != null) { 66 for (int i = 0; i < g.length; i++) { 67 u.addGroup(Group.getInstance(g[i])); 68 } 69 } 70 71 81 Enumeration ps = request.getParameterNames(); 83 while (ps.hasMoreElements()) { 84 String name = ps.nextElement() + ""; 85 if (name.startsWith("META_")) { 86 name = name.substring(5); 87 u.setMetaData(name, request.getParameter("META_" + name)); 88 } 89 } 90 String mtd = request.getParameter("metaToDelete"); 92 if ((mtd + "").trim().equals("")) 93 mtd = null; 94 if (mtd != null) { 95 u.removeMetaData(mtd); 96 request.setAttribute("metaData", ((UserImpl) u).getMetaData()); 97 } 98 String mtd2 = request.getParameter("newMETA"); 100 if ((mtd2 + "").trim().equals("")) 101 mtd2 = null; 102 if (mtd2 != null) { 103 u.setMetaData(mtd2, ""); 104 request.setAttribute("metaData", ((UserImpl) u).getMetaData()); 105 } 106 Mapping.commit(); 107 108 if (mtd != null || mtd2 != null) { 110 return new ActionForward( mapping.getInput() ); 111 } 112 113 115 } catch (Exception e) { 116 Mapping.rollback(); 117 request.setAttribute("error", e.getMessage()); 118 return new ActionForward( mapping.getInput() ); 119 } 120 121 return mapping.findForward("success"); 122 } 123 124 } | Popular Tags |