1 19 20 package za.org.coefficient.modules.navigation; 21 22 import za.org.coefficient.core.Constants; 23 import za.org.coefficient.interfaces.CoefficientContext; 24 import za.org.coefficient.modules.BaseModule; 25 import za.org.coefficient.util.common.InvokerFactory; 26 import za.org.coefficient.util.ejb.SecurityUtil; 27 import za.org.coefficient.util.ejb.VelocityScreenUtil; 28 29 import java.util.HashMap ; 30 import java.util.Iterator ; 31 import java.util.Vector ; 32 33 import javax.naming.Context ; 34 import javax.naming.NameClassPair ; 35 import javax.naming.NamingEnumeration ; 36 37 43 public abstract class BaseNavigate extends BaseModule { 44 46 protected CoefficientContext buildNavigation(CoefficientContext ctx, 47 String [] contextNames, String lineVM, String indexVM, boolean admin) { 48 HashMap nameMod = new HashMap (); 49 50 Context initialContext = null; 51 52 try { 54 initialContext = za.org.coefficient.util.common.ContextUtil.getContext(); 55 if (admin && (ctx.getCurrentUser() != null) 56 && ctx.getCurrentUser() 57 .getSystemRole() 58 .getDescription() 59 .equals(SecurityUtil.SITE_ADMIN_ROLE_DESC)) { 60 getNamesFromContext(contextNames, nameMod, initialContext); 61 } else if (!admin) { 62 getNamesFromContext(contextNames, nameMod, initialContext); 63 nameMod.put("__DefaultScreenHelp", ctx.getParameter("module")); 67 } 68 } catch (Exception e) { 69 e.printStackTrace(); 70 } finally { 71 try { 72 initialContext.close(); 73 } catch (Exception e) { 74 e.printStackTrace(); 75 } 76 } 77 78 HashMap map = new HashMap (); 79 Vector lines = new Vector (); 80 StringBuffer sb = null; 81 82 int modSize = nameMod.size(); 83 if(modSize == 0) { 84 modSize = 1; 85 } 86 int width = 100 / modSize; 87 88 for (Iterator it = nameMod.keySet() 89 .iterator(); it.hasNext();) { 90 String mod = (String ) it.next(); 91 String name = (String ) nameMod.get(mod); 92 map.put("name", name); 93 map.put("modulename", mod); 94 map.put("td_width", new Integer (width)); 95 if ("__DefaultScreenHelp".equals(mod)) { 96 map.put("op", "showHelp"); 97 map.put("name", "Help"); 98 map.put("modulename", name); 99 } 100 sb = VelocityScreenUtil.getProcessedScreenFullyQualified(lineVM, map); 101 lines.addElement(sb.toString()); 102 map.clear(); 103 } 104 map.put("module", this); 105 map.put("lines", lines); 106 if (lines.size() != 0) { 107 sb = VelocityScreenUtil.getProcessedScreenFullyQualified(indexVM, map); 108 ctx.setModuleContent(sb.toString(), getModuleDisplayName()); 109 } 110 return ctx; 111 } 112 113 private void getNamesFromContext(String [] contextNames, HashMap nameMod, 114 Context initialContext) throws Exception { 115 for (int i = 0; i < contextNames.length; i++) { 116 try { 117 for (NamingEnumeration ne = 118 initialContext.list(Constants.JNDI_CONTEXT + "/" 119 + contextNames[i]); ne.hasMore();) { 120 NameClassPair bind = (NameClassPair ) ne.next(); 121 String mod = bind.getName(); 122 123 String name = (String )InvokerFactory.getInvoker() 125 .invokeGetterOnModule(mod, "moduleDisplayName"); 126 nameMod.put(mod, name); 127 } 128 } catch (javax.naming.NameNotFoundException nnfe) { 129 } 131 } 132 } 133 } 134 | Popular Tags |