| 1 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 ; 31 import java.util.Iterator ; 32 33 import javax.naming.Context ; 34 import javax.naming.NameClassPair ; 35 import javax.naming.NamingEnumeration ; 36 37 51 public class MyData extends BaseModule { 52 54 public String getMainMethod() { 55 return "view"; 56 } 57 58 public String getModuleDescription() { 59 return "Module that shows all data related to the current user"; 60 } 61 62 public String getModuleDisplayName() { 63 return "My Data"; 64 } 65 66 public CoefficientContext view(CoefficientContext ctx) throws Exception { 67 HashMap map = new HashMap (); 68 69 CoefficientUser currentUser = ctx.getCurrentUser(); 70 if(currentUser == null) { 71 StringBuffer sb = 72 VelocityScreenUtil.getProcessedScreen("notUser.vm", map); 73 74 ctx.setModuleContent(sb.toString(), getModuleDisplayName()); 76 } else { 77 78 HashMap modulesContent = new HashMap (); 79 80 Context initialContext = null; 83 84 try { 86 initialContext = ContextUtil.getContext(); 87 88 for (NamingEnumeration ne = 89 initialContext.list(Constants.JNDI_CONTEXT); ne.hasMore();) { 90 NameClassPair bind = (NameClassPair ) ne.next(); 91 String dir = bind.getName(); 92 if(!dir.equals("util") && !dir.equals("themes") && 93 !dir.equals("utilityThemes")) { 94 for (NamingEnumeration ne2 = 95 initialContext.list(Constants.JNDI_CONTEXT + "/" 96 + dir); ne2.hasMore();) { 97 NameClassPair pair = (NameClassPair ) ne2.next(); 98 String mod = pair.getName(); 99 100 String content = null; 102 try { 103 content = (String )InvokerFactory.getInvoker() 104 .invokeMethodOnModule(mod, "displayUsersData", 105 new Object []{currentUser}); 106 } catch(Exception e) { 107 } 110 if(content != null && !content.trim().equals("")) { 111 modulesContent.put(mod, content); 112 } 113 } 114 } 115 } 116 } catch(Exception e) { 117 e.printStackTrace(); 118 } 119 120 map.put("user", currentUser); 121 map.put("modulesContent", modulesContent); 122 StringBuffer sb = 123 VelocityScreenUtil.getProcessedScreen("myDataView.vm", map); 124 125 ctx.setModuleContent(sb.toString(), getModuleDisplayName()); 127 } 128 return ctx; 129 } 130 } 131 | Popular Tags |