KickJava   Java API By Example, From Geeks To Geeks.

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


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 Displays a form for changing the definition of a user
14  * @author $Author: sebastian $
15  * @version $Revision: 1.4 $
16  */

17 public class ACUserEditEventHandler extends DefaultEventHandler implements ParameterTypes, DatabaseDefaults, FrameConstants
18 {
19     /** empty constructor */
20     private ACUserEditEventHandler() {}
21
22     /** static initialisation */
23     private static ACUserEditEventHandler instance = new ACUserEditEventHandler();
24
25     public static ACUserEditEventHandler getInstance()
26     {
27         return instance;
28     }
29
30     public void handleEvent(TKEvent evt) throws TKException
31     {
32         try {
33             WebManEvent.checkEvent(evt.getRemoteUser(), evt.getName(), ContextConstants.ACCESS_CONTROL);
34             TKHTMLTemplate t = evt.getPrepHTMLTemplate( "ac_useredit.tmpl" );
35             String JavaDoc userId = evt.getParameter( PARAMETER, "USER_ID" );
36             String JavaDoc editPage = evt.getParameter(PARAMETER, "EDIT_PAGE");
37             t.set("EDIT_PAGE", (editPage == null ? "1" : editPage));
38             userId = (userId != null ? userId : "-1");
39             User theUser = null;
40             if (userId.length() > 0 || userId.equals("-1"))
41             {
42                 theUser = UserFactory.getInstance().getUser(new Integer JavaDoc(userId));
43                 if (theUser != null) {
44                     t.set("USER_ID", theUser.getID());
45                     t.set("USER_NAME", theUser.getName());
46                     t.set("USER_LOGIN", theUser.getLogin());
47
48                     // add list of Contexts
49
TKVector contextVector = ACConvenience.makeContextList( ContextFactory.getInstance().
50                                                 getContexts());
51                     t.setListIterator(new TKStandardPluginIterator("AC_CONTEXT_LIST", null, contextVector,
52                                                true, t.getListIterator()));
53                     
54                     // add list of Roles
55
TKVector roleVector = ACConvenience.makeRoleList( RoleFactory.getInstance().getRoles() );
56                     t.setListIterator(new TKStandardPluginIterator("AC_ROLE_LIST", null, roleVector,
57                                                true, t.getListIterator()));
58
59                     // add list of Groups
60
TKVector groupVector = ACConvenience.makeGroupList( ProfileFactory.getInstance().
61                                                 getProfiles(), theUser);
62                     t.setListIterator(new TKStandardPluginIterator("AC_GROUP_LIST", null, groupVector,
63                                                true, t.getListIterator()));
64                     
65                     // add list of global rights
66
TKVector globalRights = ACConvenience.makeGlobalRightsList( theUser.getPolicies() );
67                     if (globalRights == null || globalRights.size() == 0) t.set("NO_USER_GLOBAL_RIGHTS", "TRUE");
68                     t.setListIterator(new TKStandardPluginIterator("USER_GLOBAL_RIGHTS", null, globalRights,
69                                                 true, t.getListIterator()));
70
71                 }
72             }
73             t.set("EDIT_PAGE", (editPage == null ? "1" : editPage));
74             WebManEvent.fillEventsIntoTemplate(evt.getRemoteUser(), t, ACCESS_CONTROL);
75             evt.finishTemplate( t );
76         } catch (Throwable JavaDoc e) {
77             throw WebmanExceptionHandler.getException(e);
78         }
79     }
80
81     public boolean isHandler(TKEvent evt)
82     {
83         return evt.getName().equalsIgnoreCase( "AC_USER_EDIT" );
84     }
85
86 }
87
Popular Tags