KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > za > org > coefficient > modules > myData > MyData


1 /*
2  * Coefficient - facilitates project based collaboration
3  * Copyright (C) 2003, Dylan Etkin, CSIR icomtek
4  * PO Box 395
5  * Pretoria 0001, RSA
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18  */

19
20 package za.org.coefficient.modules.myData;
21
22 import za.org.coefficient.authentication.CoefficientUser;
23 import za.org.coefficient.core.Constants;
24 import za.org.coefficient.interfaces.CoefficientContext;
25 import za.org.coefficient.modules.BaseModule;
26 import za.org.coefficient.util.ejb.VelocityScreenUtil;
27 import za.org.coefficient.util.common.ContextUtil;
28 import za.org.coefficient.util.common.InvokerFactory;
29
30 import java.util.HashMap JavaDoc;
31 import java.util.Iterator JavaDoc;
32
33 import javax.naming.Context JavaDoc;
34 import javax.naming.NameClassPair JavaDoc;
35 import javax.naming.NamingEnumeration JavaDoc;
36
37 /**
38  * @pojo2ejb.class
39  * name="MyData"
40  * jndi-prefix="za/org/coefficient/navigation/"
41  * interface-extends="za.org.coefficient.interfaces.Module"
42  * interface-local-extends="za.org.coefficient.interfaces.ModuleLocal"
43  *
44  * @web.resource-env-ref
45  * name="za/org/coefficient/navigation/MyData"
46  * type="za.org.coefficient.modules.myData.MyData"
47  * @web.resource-env-ref
48  * name="MyData"
49  * type="za.org.coefficient.modules.myData.MyData"
50  */

51 public class MyData extends BaseModule {
52     //~ Methods ================================================================
53

54     public String JavaDoc getMainMethod() {
55         return "view";
56     }
57
58     public String JavaDoc getModuleDescription() {
59         return "Module that shows all data related to the current user";
60     }
61
62     public String JavaDoc getModuleDisplayName() {
63         return "My Data";
64     }
65
66     public CoefficientContext view(CoefficientContext ctx) throws Exception JavaDoc {
67         HashMap JavaDoc map = new HashMap JavaDoc();
68
69         CoefficientUser currentUser = ctx.getCurrentUser();
70         if(currentUser == null) {
71             StringBuffer JavaDoc sb =
72                 VelocityScreenUtil.getProcessedScreen("notUser.vm", map);
73             
74             // Set the html into the context
75
ctx.setModuleContent(sb.toString(), getModuleDisplayName());
76         } else {
77
78             HashMap JavaDoc modulesContent = new HashMap JavaDoc();
79
80             // Get all modules and let them have the opportunity to tell us
81
// about the data it has for the current user
82
Context initialContext = null;
83             
84             // Get the navigation modules and their names
85
try {
86                 initialContext = ContextUtil.getContext();
87                 
88                 for (NamingEnumeration JavaDoc ne =
89                          initialContext.list(Constants.JNDI_CONTEXT); ne.hasMore();) {
90                     NameClassPair JavaDoc bind = (NameClassPair JavaDoc) ne.next();
91                     String JavaDoc dir = bind.getName();
92                     if(!dir.equals("util") && !dir.equals("themes") &&
93                        !dir.equals("utilityThemes")) {
94                         for (NamingEnumeration JavaDoc ne2 =
95                                  initialContext.list(Constants.JNDI_CONTEXT + "/"
96                                                      + dir); ne2.hasMore();) {
97                             NameClassPair JavaDoc pair = (NameClassPair JavaDoc) ne2.next();
98                             String JavaDoc mod = pair.getName();
99                         
100                             // Fire the module
101
String JavaDoc content = null;
102                             try {
103                                 content = (String JavaDoc)InvokerFactory.getInvoker()
104                                     .invokeMethodOnModule(mod, "displayUsersData",
105                                                           new Object JavaDoc[]{currentUser});
106                             } catch(Exception JavaDoc e) {
107                                 // Do nothing this is OK
108
//e.printStackTrace();
109
}
110                             if(content != null && !content.trim().equals("")) {
111                                 modulesContent.put(mod, content);
112                             }
113                         }
114                     }
115                 }
116             } catch(Exception JavaDoc e) {
117                 e.printStackTrace();
118             }
119
120             map.put("user", currentUser);
121             map.put("modulesContent", modulesContent);
122             StringBuffer JavaDoc sb =
123                 VelocityScreenUtil.getProcessedScreen("myDataView.vm", map);
124             
125             // Set the html into the context
126
ctx.setModuleContent(sb.toString(), getModuleDisplayName());
127         }
128         return ctx;
129     }
130 }
131
Popular Tags