Source code: org/acs/damsel/client/edit/EditGroupAction.java
1 package org.acs.damsel.client.edit;
2
3 import org.apache.struts.action.*;
4 import javax.servlet.http.*;
5 import org.acs.damsel.srvr.user.*;
6 import java.util.Enumeration;
7 import java.util.Vector;
8 import org.acs.damsel.srvr.group.*;
9
10 public class EditGroupAction
11 extends Action {
12 public ActionForward execute(ActionMapping actionMapping,
13 ActionForm actionForm,
14 HttpServletRequest httpServletRequest,
15 HttpServletResponse httpServletResponse) {
16
17 EditGroupForm editGroupForm = (EditGroupForm) actionForm;
18
19 // If the a group has been selected the page is only refreshed.
20 if (editGroupForm.isChangedGroup()) {
21 editGroupForm.setChangedGroup(false);
22 return actionMapping.findForward("reset");
23 }
24
25 // The vector containing strings of the 18 permissions is pulled from the
26 // session and another vector containing 18 occurances of the string
27 // "false".
28
29 Vector allFalse = new Vector();
30 Vector allPerms = (Vector) httpServletRequest.getSession().getAttribute(
31 "allPermissions");
32 for (int i = 0; i < allPerms.size(); i++) {
33 allFalse.add("false");
34 }
35
36 // The input forms on the edit group page are dynamically generated according
37 // to the Group that the User selects from a drop-down box. In order to
38 // recognize changes to the settings of a group all the parameters from the
39 // page are recieved and added to vectors according to their field name and
40 // the new value for that field. These field names and values are added to
41 // vectors (fieldVec and valueVev). The description is added first because
42 // it is the only peice of information on the page that is not a permission.
43 // Since the getParameterNames() method only returns the checkboxes which are
44 // set to true, only these permissions are added to fieldVec and valueVec.
45 // Once these vectors have been built, the group selected (accessed using
46 // the string variable groupName) is first updated to reflect all falses for
47 // the 18 different permsissions. This is done because of the inability to
48 // access checkboxes set to false through the getParameterNames() method.
49 // Following this setting to false, the description and permissions are
50 // updated to reflect the most recent changes made by the user. Finally the
51 // user is forwarded to a confirmation page that indicates that a group has
52 // been edited.
53
54 GroupMgr groupMgr = new GroupMgr();
55 String potentialName = new String();
56 String groupName = (String) editGroupForm.getSelectGroup();
57 String value = new String();
58 Vector fieldVec = new Vector();
59 Vector valueVec = new Vector();
60
61 fieldVec.add("Description");
62 valueVec.add(editGroupForm.getDescription());
63
64 for (Enumeration e = httpServletRequest.getParameterNames();
65 e.hasMoreElements(); ) {
66 potentialName = (String) e.nextElement();
67
68 if (potentialName.indexOf("Can") != -1) {
69 value = httpServletRequest.getParameter(potentialName);
70 if (value.equals("true")) {
71 fieldVec.addElement(potentialName);
72 valueVec.addElement("true");
73 }
74 }
75 }
76 httpServletRequest.getSession().setAttribute("editGroupPermissions",fieldVec);
77 groupMgr.updateGroup(allPerms, allFalse, groupName);
78 groupMgr.updateGroup(fieldVec, valueVec, groupName);
79 return (actionMapping.findForward("success"));
80
81 }
82 }