KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > teamkonzept > webman > WebManEvent


1 package com.teamkonzept.webman;
2
3 import com.teamkonzept.lib.*;
4 import com.teamkonzept.web.*;
5 import com.teamkonzept.webman.mainint.events.*;
6 import de.webman.acl.*;
7 import java.util.*;
8 import org.apache.log4j.Category;
9 /**
10     <b>WebManEvent</b> extends the functionality of TKEvent for special
11     features needed in the WebMan user interface.
12
13  * @author $Author: alex $
14  * @version $Revision: 1.21 $
15 */

16 public class WebManEvent
17 {
18     /** Logging Category */
19     private static Category cat = Category.getInstance(WebManEvent.class);
20     
21     /**
22         Get a Login from an event.
23     */

24     public static Login getWMLogin(String JavaDoc user)
25         throws Throwable JavaDoc
26     {
27         return LoginFactory.getInstance().getLogin(user);
28     }
29
30     /**
31         Fills all locally allowed events into a TKHashtable
32         @param TKEvent evt the event
33         @param TKHashtable hash the Template
34         @param Integer contextId the numerical ID of the context
35         @param Integer type the reference type
36         @param Integer ref the object reference
37     */

38     public static void fillEventsIntoTemplate(String JavaDoc user, TemplateBasic t, Integer JavaDoc contextId, Integer JavaDoc type, Integer JavaDoc ref)
39         throws Throwable JavaDoc
40     {
41         Context c = ContextFactory.getInstance().getContext(contextId);
42         Login l = getWMLogin(user);
43
44         TKVector vec = l.getAllowedEvents(c.getID(), type, ref);
45         if (vec != null)
46         {
47             Enumeration e = vec.elements();
48             while (e.hasMoreElements())
49             {
50                 Event ev = (Event) e.nextElement();
51                 t.set(ev.getName(), "1");
52             }
53         }
54     }
55
56     /**
57         Fills all allowed events into a template
58         @param TKTemplate t the Template
59         @param Integer contextId the numerical ID of the context
60     */

61     public static void fillEventsIntoTemplate(String JavaDoc user, TemplateBasic t, Integer JavaDoc contextId)
62         throws Throwable JavaDoc
63     {
64         Context c = ContextFactory.getInstance().getContext(contextId);
65         Login l = getWMLogin(user);
66
67         TKVector vec = l.getAllowedEvents(c.getID());
68         if (vec != null)
69         {
70             Enumeration e = vec.elements();
71             while (e.hasMoreElements())
72             {
73                 Event ev = (Event) e.nextElement();
74                 t.set(ev.getName(), "1");
75             }
76         }
77     }
78
79     /**
80         Fills all allowed events into a TKHashtable
81         @param TKEvent evt the event
82         @param TKHashtable hash the Template
83         @param Integer contextId the numerical ID of the context
84     */

85     public static void fillEventsIntoHash(String JavaDoc user, TKHashtable hash, Integer JavaDoc contextId)
86         throws Throwable JavaDoc
87     {
88         Context c = ContextFactory.getInstance().getContext(contextId);
89         Login l = getWMLogin(user);
90
91         TKVector vec = l.getAllowedEvents(c.getID());
92         if (vec != null)
93         {
94             Enumeration e = vec.elements();
95             while (e.hasMoreElements())
96             {
97                 Event ev = (Event) e.nextElement();
98                 hash.put(ev.getName(), "1");
99             }
100         }
101     }
102
103     /**
104         Fills all locally allowed events into a TKHashtable
105         @param TKEvent evt the event
106         @param TKHashtable hash the Template
107         @param Integer contextId the numerical ID of the context
108         @param Integer type the reference type
109         @param Integer ref the object reference
110     */

111     public static void fillEventsIntoHash(TKEvent evt,TKHashtable hash, Integer JavaDoc contextId, Integer JavaDoc type, Integer JavaDoc ref)
112         throws Throwable JavaDoc
113     {
114         Context c = ContextFactory.getInstance().getContext(contextId);
115         Login l = getWMLogin(evt.getRemoteUser());
116
117         TKVector vec = l.getAllowedEvents(c.getID(), type, ref);
118         if (vec != null)
119         {
120             Enumeration e = vec.elements();
121             while (e.hasMoreElements())
122             {
123                 Event ev = (Event) e.nextElement();
124                 hash.put(ev.getName(), "1");
125             }
126         }
127     }
128
129
130     /**
131         Checks if an event is allowed for a user in this context
132         @param evt the event
133         @param contextId the context
134         @return true if this event is allowed
135         @return false else
136     */

137     public static void checkEvent(String JavaDoc user, String JavaDoc eventName, Integer JavaDoc contextId, Integer JavaDoc type, Integer JavaDoc ref)
138         throws Throwable JavaDoc
139     {
140         Login l = getWMLogin(user);
141         Event event = EventFactory.getInstance().getEvent(eventName);
142         if (l == null)
143         {
144             cat.warn("------- Login ist NULL!!!!!!");
145             return;
146         }
147         if (event == null)
148         {
149             cat.warn("----------Event not found:"+eventName);
150             /*if (! insertNewEvent(evt, contextId))
151             {*/

152                 return;
153             //}
154
}
155         if (l != null
156             && event != null
157             && (! l.isAllowed(event.getID(), contextId, type, ref))
158             && (! l.isAllowed(event.getID(), contextId))
159             )
160         {
161             throw new TKUserException("Der Zugriff auf die Funktion "+eventName+" ist für "+l.getName()+" nicht gestattet!(ObjectType: "+type.toString()+", ObjektID: "+ref.toString()+")",
162                                         UserCodes.EVENT_NOT_ALLOWED, ErrorCodes.USER_SEVERITY,
163                                         true, new Object JavaDoc[] {eventName, l.getName()}, null);
164         }
165     }
166
167     /**
168         Checks if an event is allowed for a user in this context
169         @param evt the event
170         @param contextId the context
171         @return true if this event is allowed
172         @return false else
173     */

174     public static void checkEvent(String JavaDoc user, String JavaDoc evtName, Integer JavaDoc contextId)
175         throws Throwable JavaDoc
176     {
177         Login l = getWMLogin(user);
178         Event event = EventFactory.getInstance().getEvent(evtName);
179         if (l == null)
180         {
181             cat.warn("------- Login ist NULL!!!!!!");
182             return;
183         }
184         if (event == null)
185         {
186             cat.warn("----------Event not found:"+evtName);
187             /*if ( ! insertNewEvent(evt, contextId))
188             {
189                 return;
190             }*/

191             return;
192         }
193         if (l != null && event != null && (! l.isAllowed(event.getID(), contextId)))
194         {
195             throw new TKUserException("Der Zugriff auf die Funktion " + evtName + " ist für "+l.getName()+" nicht gestattet!",
196                                         UserCodes.EVENT_NOT_ALLOWED, ErrorCodes.USER_SEVERITY,
197                                         true, new Object JavaDoc[] {evtName, l.getName()}, null);
198         }
199     }
200
201     /**
202         Insert a new yet unknown Event into the Accessrights according to
203         Properties.
204         @param TKEvent evt - an Event
205         @param Integer contextId - a Context
206     */

207     public static boolean insertNewEvent(TKEvent evt, Integer JavaDoc contextId)
208     {
209         return false;
210         /*
211         boolean acceptEvent = false;
212         Integer defaultRole = new Integer(1);
213         
214         
215         try
216         {
217             PropertyManager pman = PropertyManager.getPropertyManager("NEW_EVENTS");
218             acceptEvent = pman.getValue("EVENT_ACCEPT_NEW").toUpperCase().equals("Y")
219                         || pman.getValue("EVENT_ACCEPT_NEW").toUpperCase().equals("J");
220             defaultRole = new Integer(pman.getValue("EVENT_DEFAULT_ROLE"));
221
222         }
223         catch (Throwable e)
224         {
225             ("Something happened while loading Properties for, NEW_EVENTS." + e);
226         }
227             
228         if (acceptEvent)
229         {
230             try
231             {
232                 String evtName = evt.getName();
233                 Context wm_ctxt = ContextFactory.getInstance().getContext(contextId);
234                 
235                 // create all necessary Objects ...
236                 Event wm_evt = EventFactory.getInstance().createEvent(evtName);
237                 Action wm_act = ActionFactory.getInstance().createAction(evtName);
238
239                 wm_act.addEvent(wm_evt);
240                 ActionFactory.getInstance().modifyAction(wm_act);
241
242                 Task wm_task = TaskFactory.getInstance().createTask(evtName, wm_ctxt);
243                 
244                 // add the new Task to the default role
245                 Role wm_role = RoleFactory.getInstance().getRole(defaultRole);
246                 if (wm_role != null)
247                 {
248                     wm_role.addTask(wm_task);
249                     RoleFactory.getInstance().modifyRole(wm_role);
250                     return true;
251                 }
252             }
253             catch(Throwable t)
254             {
255                 System.out.println("Something happened while creating new Event:"+evt.getName() + " " + t);
256             }
257         }
258         return false;
259         */

260     }
261
262     /**
263         Checks if an event is allowed for a user in this context
264         and on this special object!
265         @param evt the event
266         @param contextId the context
267         @param type the type of object
268         @param ref the object reference
269         @return true if this event is allowed
270         @return false else
271     */

272     public static boolean isAllowed(String JavaDoc user, String JavaDoc evtName, Integer JavaDoc contextId, Integer JavaDoc type, Integer JavaDoc ref)
273         throws Throwable JavaDoc
274     {
275         Login l = getWMLogin(user);
276         Event event = EventFactory.getInstance().getEvent(evtName);
277         return l.isAllowed(event.getID(), contextId, type, ref);
278     }
279
280     /**
281         fills allowed events for each node in this content iterator
282         @TKEvent evt - the Event
283         @Integer contextId - a Context
284         @TKDBResult tree - a content tree
285     */

286     public static void fillInContentEvents(String JavaDoc user, String JavaDoc evtName, Integer JavaDoc contextId, TKDBResult tree)
287         throws Throwable JavaDoc
288     {
289         Login l = getWMLogin(user);
290         Context c = ContextFactory.getInstance().getContext(contextId);
291         
292         Enumeration e = tree.elements();
293         while (e.hasMoreElements())
294         {
295             TKDBResultRowHash t = (TKDBResultRowHash) e.nextElement();
296             // get allowed events for this node
297
String JavaDoc nodeId = (String JavaDoc) t.get("CONTENT_NODE_ID");
298             TKVector events = l.getAllowedEvents(c.getID(), Policy.CONTENT_TREE_ID, new Integer JavaDoc(nodeId));
299             
300             // and add them to the iterator
301
if (events != null)
302             {
303                 Enumeration en = events.elements();
304                 while (en.hasMoreElements())
305                 {
306                     Event ev = (Event) en.nextElement();
307                     t.addColumn(ev.getName(), "1");
308                 }
309             }
310         }
311     }
312 }
313
Popular Tags