1 2 23 package com.geinuke.common; 24 25 import java.io.File ; 26 import java.util.ArrayList ; 27 import java.util.Hashtable ; 28 import java.util.Vector ; 29 30 import javax.servlet.http.HttpServletRequest ; 31 32 import com.geinuke.block.BlockWrapper; 33 import com.geinuke.module.ModuleWrapper; 34 import com.geinuke.servlet.GeiServlet; 35 import com.geinuke.util.BlockConfigParser; 36 import com.geinuke.util.ModuleConfigParser; 37 import com.geinuke.util.NukeResource; 38 import com.geinuke.util.PluginConfigParser; 39 import com.geinuke.vo.ModuleDBVO; 40 41 public class GlobalCFG implements GlobalConfigurationI{ 42 43 protected Hashtable modWidgets=null; 44 protected Hashtable blockWidgets=null; 45 protected Vector plugins=null; 46 protected String basePath=null; 47 protected String fs=File.separator; 48 protected String ppath=null; 49 50 51 public GlobalCFG(String path)throws Exception { 52 this.ppath=path; 53 init(path); 54 } 55 56 public void reload()throws Exception { 57 init(this.ppath); 58 } 59 60 protected Vector loadPlugins(String bP) throws Exception { 61 Vector plgs =null; 62 ArrayList pluginsName=NukeResource.getDirectories(bP+fs+"plugins"); 63 String dirName=null; 64 PluginConfigParser pcp=null; 65 Object pl=null; 66 plgs=new Vector (); 67 for(int i=0;i<pluginsName.size();i++){ 68 dirName=(String )pluginsName.get(i); 69 pcp=new PluginConfigParser(); 70 pl=pcp.parseFile( new File (bP+fs+"plugins"+fs+dirName+fs+"config.xml") ); 71 plgs.add(pl); 72 } 73 return plgs; 74 } 75 76 protected Hashtable loadModules(String bP) throws Exception { 77 Hashtable mW=null; 78 ArrayList modules=NukeResource.getDirectories(bP+fs+"modules"); 79 String name=null; 81 ModuleConfigParser mParser=null; 82 ModuleWrapper mod=null; 83 mW=new Hashtable (); 84 for(int i=0;i<modules.size();i++){ 85 name=(String )modules.get(i); 86 mParser=new ModuleConfigParser(); 88 mod=(ModuleWrapper)mParser.parseFile( new File (bP+fs+"modules"+fs+name+fs+"config.xml") ); 90 mW.put(name,mod); 92 } 93 return mW; 94 95 } 96 97 protected Hashtable loadBlocks(String bP)throws Exception { 98 Hashtable bW=null; 99 bW=new Hashtable (); 100 String name=null; 101 ArrayList blocks=NukeResource.getDirectories(bP+fs+"blocks"); 102 BlockWrapper bloWr=null; 104 BlockConfigParser bParser=null; 105 bParser=new BlockConfigParser(); 106 for(int i=0;i<blocks.size();i++){ 107 name=(String )blocks.get(i); 108 bloWr=(BlockWrapper)bParser.parseFile( new File (bP+fs+"blocks"+fs+name+fs+"config.xml") ); 109 bW.put(name,bloWr); 110 } 111 112 return bW; 113 } 114 115 protected void init(String path)throws Exception { 116 this.modWidgets=new Hashtable (); 118 this.blockWidgets=new Hashtable (); 119 this.plugins=new Vector (); 120 123 this.basePath=path+"WEB-INF"+fs+"templates"; 124 126 this.plugins=this.loadPlugins(basePath); 127 139 140 this.modWidgets=this.loadModules(this.basePath); 141 142 143 159 this.blockWidgets=this.loadBlocks(this.basePath); 160 161 173 } 175 176 public ModuleDBVO getDefaultModule() { 177 return null; 179 } 180 181 182 public ModuleWidgetI getModuleWidget(String moduleName,String op) { 183 ModuleWrapper mod=null; 185 if(op==null || moduleName.equals("NotActive")) 186 op=""; 187 GeiServlet.intLog("GlobalCFG.getModuleWidget(...), moduleName="+moduleName); 188 GeiServlet.intLog("GlobalCFG.getModuleWidget...), op="+op); 189 mod=(ModuleWrapper)this.modWidgets.get(moduleName); 191 return (ModuleWidgetI)mod.getObject(op); 193 } 194 195 public String getModulePage(String moduleName,String op) { 196 ModuleWrapper mod=null; 198 if(moduleName.equals("NotActive")) 199 op=""; 200 GeiServlet.intLog("GlobalCFG.getModulePage(...), moduleName="+moduleName); 201 GeiServlet.intLog("GlobalCFG.getModulePage(...), op="+op); 202 204 mod=(ModuleWrapper)this.modWidgets.get(moduleName); 205 if(op==null) 207 op=""; 208 return (String )mod.getPage(op); 209 } 210 211 public String getModulePage(String moduleName,HttpServletRequest req) { 212 return this.getModulePage(moduleName,req.getParameter("op")); 213 214 } 215 216 217 public BlockWidgetI getBlockWidget(String blockName) { 218 219 BlockWrapper bw=null; 220 bw=(BlockWrapper)this.blockWidgets.get(blockName); 221 return bw.getBlockWidget(); 222 223 } 224 225 226 public Vector getPlugins() { 227 228 return this.plugins; 229 } 230 231 } 232 | Popular Tags |