001: package de.webman.acl.eventhandler;
002:
003: import java.util.*;
004:
005: import com.teamkonzept.web.*;
006: import com.teamkonzept.lib.*;
007: import com.teamkonzept.webman.*;
008: import com.teamkonzept.webman.mainint.*;
009: import com.teamkonzept.webman.mainint.events.*;
010: import de.webman.acl.*;
011:
012: /**
013: Updates a group definiton in the database
014: * @author $Author: alex $
015: * @version $Revision: 1.3 $
016: */
017: public class ACGroupAddUserEventHandler extends DefaultEventHandler
018: implements ParameterTypes, DatabaseDefaults, FrameConstants {
019: private ACGroupAddUserEventHandler() {
020: }
021:
022: private static ACGroupAddUserEventHandler instance = new ACGroupAddUserEventHandler();
023:
024: public static ACGroupAddUserEventHandler getInstance() {
025: return instance;
026: }
027:
028: public void handleEvent(TKEvent evt) throws TKException {
029: try {
030: WebManEvent.checkEvent(evt.getRemoteUser(), evt.getName(),
031: ContextConstants.ACCESS_CONTROL);
032:
033: String groupId = evt.getParameter(PARAMETER, "GROUP_ID");
034: String userId = evt.getParameter(PARAMETER, "USER_ID");
035:
036: if (groupId != null && groupId.length() > 0) {
037: doGroup(evt);
038: } else if (userId != null && userId.length() > 0) {
039: doUser(evt);
040: }
041: } catch (Throwable e) {
042: throw WebmanExceptionHandler.getException(e);
043: }
044: }
045:
046: public boolean isHandler(TKEvent evt) {
047: return evt.getName().equalsIgnoreCase("AC_GROUP_ADD_CHILD");
048: }
049:
050: /**
051: fuegt zu einer Gruppe Benutzer oder Untergruppen hinzu
052: */
053: private void doGroup(TKEvent evt) throws Throwable {
054: String groupId = evt.getParameter(PARAMETER, "GROUP_ID");
055:
056: TKParams params = evt.getParams();
057: if (groupId != null) {
058: Profile theGroup = null;
059: theGroup = ProfileFactory.getInstance().getProfile(
060: new Integer(groupId));
061: if (theGroup != null) {
062: addLogin(theGroup, params, "ADD_USER_ID");
063: addLogin(theGroup, params, "ADD_GROUP_ID");
064:
065: }
066: }
067: TKHTMLTemplate t = evt.getPrepHTMLTemplate("f_ac_group.tmpl");
068: String editPage = evt.getParameter(PARAMETER, "EDIT_PAGE");
069: t.set("EDIT_PAGE", (editPage == null ? "1" : editPage));
070: HTMLUtils.fillFrameSet(t, LEFT_FRAME_WIDTH, "AC_GROUP_LIST",
071: "AC_GROUP_EDIT");
072: t.set("GROUP_ID", new Integer(groupId));
073: WebManEvent.fillEventsIntoTemplate(evt.getRemoteUser(), t,
074: ACCESS_CONTROL);
075: evt.finishTemplate(t);
076: }
077:
078: /**
079: convenience method for adding either users or groups to a profile
080: */
081: private void addLogin(Profile profile, TKParams params,
082: String parameter) throws Exception {
083: TKVector vec = new TKVector();
084: if (params.hasMultiple(PARAMETER, parameter)) {
085: vec = params.getVector(PARAMETER, parameter);
086: } else if (params.get(PARAMETER, parameter) != null) {
087: vec.addElement(params.get(PARAMETER, parameter));
088: }
089: Enumeration vecEnum = vec.elements();
090: while (vecEnum.hasMoreElements()) {
091: String lId = (String) vecEnum.nextElement();
092: Login login = LoginFactory.getInstance().getLogin(
093: new Integer(lId));
094: if (login != null) {
095: profile.addChild(login);
096: ProfileFactory.getInstance().modifyProfile(profile);
097: }
098: }
099: }
100:
101: /**
102: fügt einen Benutzer in mehrere Gruppen ein
103: */
104: private void doUser(TKEvent evt) throws Throwable {
105: String userId = evt.getParameter(PARAMETER, "USER_ID");
106:
107: TKParams params = evt.getParams();
108: if (userId != null && userId.length() > 0) {
109: Login theUser = null;
110: theUser = LoginFactory.getInstance().getLogin(
111: new Integer(userId));
112: if (theUser != null) {
113: addLoginToGroups(theUser, params, "ADD_GROUP_ID");
114: }
115: }
116: TKHTMLTemplate t = evt.getPrepHTMLTemplate("f_ac_user.tmpl");
117: String editPage = evt.getParameter(PARAMETER, "EDIT_PAGE");
118: t.set("EDIT_PAGE", (editPage == null ? "1" : editPage));
119: HTMLUtils.fillFrameSet(t, LEFT_FRAME_WIDTH, "AC_USER_LIST",
120: "AC_USER_EDIT");
121: t.set("USER_ID", new Integer(userId));
122: WebManEvent.fillEventsIntoTemplate(evt.getRemoteUser(), t,
123: ACCESS_CONTROL);
124: evt.finishTemplate(t);
125: }
126:
127: /**
128: fügt den Benutzer in verschiedene Gruppen ein...
129: */
130: private void addLoginToGroups(Login login, TKParams params,
131: String parameter) throws Exception {
132: TKVector vec = new TKVector();
133: if (params.hasMultiple(PARAMETER, parameter)) {
134: vec = params.getVector(PARAMETER, parameter);
135: } else if (params.get(PARAMETER, parameter) != null) {
136: vec.addElement(params.get(PARAMETER, parameter));
137: }
138: Enumeration vecEnum = vec.elements();
139: while (vecEnum.hasMoreElements()) {
140: String lId = (String) vecEnum.nextElement();
141: Profile profile = ProfileFactory.getInstance().getProfile(
142: new Integer(lId));
143: if (profile != null) {
144: profile.addChild(login);
145: ProfileFactory.getInstance().modifyProfile(profile);
146: }
147: }
148: }
149: }
|