KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > de > webman > acl > eventhandler > ACUserUpdateEventHandler


1 package de.webman.acl.eventhandler;
2
3 import java.util.*;
4
5 import com.teamkonzept.web.*;
6 import com.teamkonzept.lib.*;
7 import com.teamkonzept.webman.*;
8 import com.teamkonzept.webman.mainint.*;
9 import com.teamkonzept.webman.mainint.events.*;
10 import de.webman.acl.*;
11
12 /**
13    Updates a user definition in the database
14  * @author $Author: sebastian $
15  * @version $Revision: 1.4 $
16 */

17 public class ACUserUpdateEventHandler extends DefaultEventHandler implements ParameterTypes, DatabaseDefaults, FrameConstants
18 {
19     /** empty constructor */
20     private ACUserUpdateEventHandler() {}
21
22     private static ACUserUpdateEventHandler instance = new ACUserUpdateEventHandler();
23
24     public static ACUserUpdateEventHandler getInstance()
25     {
26     return instance;
27     }
28
29     public void handleEvent( TKEvent evt ) throws TKException
30     {
31     try {
32         WebManEvent.checkEvent(evt.getRemoteUser(), evt.getName(), ContextConstants.ACCESS_CONTROL);
33
34         String JavaDoc userId = evt.getParameter( PARAMETER, "USER_ID" );
35         String JavaDoc userName = evt.getParameter( PARAMETER, "USER_NAME" );
36         String JavaDoc userLogin = evt.getParameter( PARAMETER, "USER_LOGIN" );
37         //TKParams params = evt.getParams();
38
User theUser = null;
39
40         checkParameter(userName, "Name");
41         checkParameter(userLogin, "Login");
42
43         if (userId == null)
44         {
45             if (ACUtils.checkLoginExistance(userLogin))
46                         throw new TKUserException("An object with the given attributes already exists.",
47                                           UserCodes.DUPLICATE_OBJECT,
48                                           ErrorCodes.USER_SEVERITY,
49                                           true,
50                                           null);
51             theUser = UserFactory.getInstance().createUser(userLogin, userName);
52         }
53         else
54         {
55             if (ACUtils.checkLoginExistance(userLogin, new Integer JavaDoc(userId)))
56                         throw new TKUserException("An object with the given attributes already exists.",
57                                           UserCodes.DUPLICATE_OBJECT,
58                                           ErrorCodes.USER_SEVERITY,
59                                           true,
60                                           null);
61             theUser = UserFactory.getInstance().getUser(new Integer JavaDoc(userId));
62             
63         }
64
65         if (theUser != null) {
66
67         // change basic data
68
theUser.setName( userName );
69         theUser.setLogin( userLogin );
70
71 /*
72         // add Groups
73         TKVector addGroups = new TKVector();
74         if ( params.hasMultiple( PARAMETER, "GROUP_ID" ))
75             addGroups = params.getVector( PARAMETER, "GROUP_ID" );
76         else if ( params.get( PARAMETER, "GROUP_ID" ) != null )
77             addGroups.addElement( params.get( PARAMETER, "GROUP_ID" ));
78         Enumeration addGroupsEnum = addGroups.elements();
79         while (addGroupsEnum.hasMoreElements()) {
80             String gId = (String)addGroupsEnum.nextElement();
81             Profile theProfile = ProfileFactory.getInstance().getProfile(new Integer(gId));
82             if (theProfile != null) {
83             theProfile.addChild(theUser);
84             ProfileFactory.getInstance().modifyProfile(theProfile);
85             }
86         }
87
88         // delete Groups
89         TKVector delGroups = new TKVector();
90         if ( params.hasMultiple( PARAMETER, "DEL_GROUP_ID" ))
91             delGroups = params.getVector( PARAMETER, "DEL_GROUP_ID" );
92         else if ( params.get( PARAMETER, "DEL_GROUP_ID" ) != null )
93             delGroups.addElement( params.get( PARAMETER, "DEL_GROUP_ID" ));
94         Enumeration delGroupsEnum = delGroups.elements();
95         while (delGroupsEnum.hasMoreElements()) {
96             String gId = (String)delGroupsEnum.nextElement();
97             Profile theProfile = ProfileFactory.getInstance().getProfile(new Integer(gId));
98             if (theProfile != null)
99             {
100                 theProfile.removeChild(theUser);
101                 ProfileFactory.getInstance().modifyProfile(theProfile);
102             }
103         }
104
105 */

106         UserFactory.getInstance().modifyUser(theUser);
107         }
108         TKHTMLTemplate t = evt.getPrepHTMLTemplate( "f_ac_user.tmpl" );
109         String JavaDoc editPage = evt.getParameter(PARAMETER, "EDIT_PAGE");
110         t.set("EDIT_PAGE", (editPage == null ? "1" : editPage));
111         if (userId != null) {
112         HTMLUtils.fillFrameSet( t, HTMLUtils.LEFT_FRAME_WIDTH, "AC_USER_LIST", "AC_USER_EDIT" );
113         t.set("USER_ID", userId);
114         }
115         else
116         HTMLUtils.fillFrameSet( t, HTMLUtils.LEFT_FRAME_WIDTH, "AC_USER_LIST", "EMPTY" );
117
118         WebManEvent.fillEventsIntoTemplate(evt.getRemoteUser(), t, ACCESS_CONTROL);
119         evt.finishTemplate( t );
120     } catch (Throwable JavaDoc e) {
121         throw WebmanExceptionHandler.getException(e);
122     }
123     }
124
125     public boolean isHandler(TKEvent evt)
126     {
127     return evt.getName().equalsIgnoreCase( "AC_USER_UPDATE" );
128     }
129
130 }
131
Popular Tags