1 package org.nextime.ion.admin.action.group; 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.GroupForm; 15 import org.nextime.ion.framework.business.Group; 16 import org.nextime.ion.framework.business.User; 17 import org.nextime.ion.framework.business.impl.GroupImpl; 18 import org.nextime.ion.framework.mapping.Mapping; 19 20 public class EditGroupAction 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", "group"); 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("userList", User.listAll()); 41 Mapping.commit(); 42 43 if (request.getParameter("editSubmit") == null) { 44 Mapping.begin(); 45 46 Group u = Group.getInstance(id); 48 GroupForm f = (GroupForm) form; 49 f.setId(u.getId()); 50 f.setUsers(u.getUsersIds()); 51 request.setAttribute("metaData", ((GroupImpl) u).getMetaData()); 52 53 Mapping.commit(); 54 return new ActionForward( mapping.getInput() ); 55 } 56 57 Mapping.begin(); 59 GroupForm f = (GroupForm) form; 60 Group u = Group.getInstance(id); 61 String [] g = f.getUsers(); 62 u.resetUsers(); 63 if (g != null) { 64 for (int i = 0; i < g.length; i++) { 65 u.addUser(User.getInstance(g[i])); 66 } 67 } 68 69 79 Enumeration ps = request.getParameterNames(); 81 while (ps.hasMoreElements()) { 82 String name = ps.nextElement() + ""; 83 if (name.startsWith("META_")) { 84 name = name.substring(5); 85 u.setMetaData(name, request.getParameter("META_" + name)); 86 } 87 } 88 String mtd = request.getParameter("metaToDelete"); 90 if ((mtd + "").trim().equals("")) 91 mtd = null; 92 if (mtd != null) { 93 u.removeMetaData(mtd); 94 request.setAttribute("metaData", ((GroupImpl) u).getMetaData()); 95 } 96 String mtd2 = request.getParameter("newMETA"); 98 if ((mtd2 + "").trim().equals("")) 99 mtd2 = null; 100 if (mtd2 != null) { 101 u.setMetaData(mtd2, ""); 102 request.setAttribute("metaData", ((GroupImpl) u).getMetaData()); 103 } 104 Mapping.commit(); 105 106 if (mtd != null || mtd2 != null) { 108 return new ActionForward( mapping.getInput() ); 109 } 110 111 113 } catch (Exception e) { 114 Mapping.rollback(); 115 request.setAttribute("error", e.getMessage()); 116 return new ActionForward( mapping.getInput() ); 117 } 118 119 return mapping.findForward("success"); 120 } 121 122 } | Popular Tags |