KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > geinuke > common > GlobalCFG


1
2  /*
3  -- GeiNuke --
4 Copyright (c) 2005 by Roberto Sidoti [geinuke@users.sourceforge.net]
5  http://www.hostingjava.it/-geinuke/
6
7 This file is part of GeiNuke.
8
9     GeiNuke is free software; you can redistribute it and/or modify
10     it under the terms of the GNU General Public License as published by
11     the Free Software Foundation; either version 2 of the License, or
12     (at your option) any later version.
13
14     GeiNuke is distributed in the hope that it will be useful,
15     but WITHOUT ANY WARRANTY; without even the implied warranty of
16     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17     GNU General Public License for more details.
18
19     You should have received a copy of the GNU General Public License
20     along with GeiNuke; if not, write to the Free Software
21     Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 */

23 package com.geinuke.common;
24
25 import java.io.File JavaDoc;
26 import java.util.ArrayList JavaDoc;
27 import java.util.Hashtable JavaDoc;
28 import java.util.Vector JavaDoc;
29
30 import javax.servlet.http.HttpServletRequest JavaDoc;
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 JavaDoc modWidgets=null;
44     protected Hashtable JavaDoc blockWidgets=null;
45     protected Vector JavaDoc plugins=null;
46     protected String JavaDoc basePath=null;
47     protected String JavaDoc fs=File.separator;
48     protected String JavaDoc ppath=null;
49     
50     
51     public GlobalCFG(String JavaDoc path)throws Exception JavaDoc{
52         this.ppath=path;
53         init(path);
54     }
55     
56     public void reload()throws Exception JavaDoc{
57         init(this.ppath);
58     }
59     
60     protected Vector JavaDoc loadPlugins(String JavaDoc bP) throws Exception JavaDoc{
61         Vector JavaDoc plgs =null;
62         ArrayList JavaDoc pluginsName=NukeResource.getDirectories(bP+fs+"plugins");
63         String JavaDoc dirName=null;
64         PluginConfigParser pcp=null;
65         Object JavaDoc pl=null;
66         plgs=new Vector JavaDoc();
67         for(int i=0;i<pluginsName.size();i++){
68             dirName=(String JavaDoc)pluginsName.get(i);
69             pcp=new PluginConfigParser();
70             pl=pcp.parseFile( new File JavaDoc(bP+fs+"plugins"+fs+dirName+fs+"config.xml") );
71             plgs.add(pl);
72         }
73         return plgs;
74     }
75     
76     protected Hashtable JavaDoc loadModules(String JavaDoc bP) throws Exception JavaDoc{
77         Hashtable JavaDoc mW=null;
78         ArrayList JavaDoc modules=NukeResource.getDirectories(bP+fs+"modules");
79         //GeiServlet.intLog("GlobalCFG(...), modules="+modules);
80
String JavaDoc name=null;
81         ModuleConfigParser mParser=null;
82         ModuleWrapper mod=null;
83         mW=new Hashtable JavaDoc();
84         for(int i=0;i<modules.size();i++){
85             name=(String JavaDoc)modules.get(i);
86             //GeiServlet.intLog("GlobalCFG(...),i="+i+" simple");
87
mParser=new ModuleConfigParser();
88             //GeiServlet.intLog("GlobalCFG(...),i="+i+" name="+name);
89
mod=(ModuleWrapper)mParser.parseFile( new File JavaDoc(bP+fs+"modules"+fs+name+fs+"config.xml") );
90             //GeiServlet.intLog("GlobalCFG(...),i="+i+" mod="+mod);
91
mW.put(name,mod);
92         }
93         return mW;
94         
95     }
96     
97     protected Hashtable JavaDoc loadBlocks(String JavaDoc bP)throws Exception JavaDoc{
98         Hashtable JavaDoc bW=null;
99         bW=new Hashtable JavaDoc();
100         String JavaDoc name=null;
101         ArrayList JavaDoc blocks=NukeResource.getDirectories(bP+fs+"blocks");
102         //GeiServlet.intLog("GlobalCFG(...), blocks"+blocks);
103
BlockWrapper bloWr=null;
104         BlockConfigParser bParser=null;
105         bParser=new BlockConfigParser();
106         for(int i=0;i<blocks.size();i++){
107             name=(String JavaDoc)blocks.get(i);
108             bloWr=(BlockWrapper)bParser.parseFile( new File JavaDoc(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 JavaDoc path)throws Exception JavaDoc{
116         //GeiServlet.intLog("GlobalCFG(...), START");
117
this.modWidgets=new Hashtable JavaDoc();
118         this.blockWidgets=new Hashtable JavaDoc();
119         this.plugins=new Vector JavaDoc();
120         //SessionPlugin sp=new SessionPlugin();
121
//plugins.add(sp);
122

123         this.basePath=path+"WEB-INF"+fs+"templates";
124         //GeiServlet.intLog("GeiServlet(...), basePath="+basePath);
125

126         this.plugins=this.loadPlugins(basePath);
127         /*
128         ArrayList pluginsName=NukeResource.getDirectories(this.basePath+fs+"plugins");
129         String dirName=null;
130         PluginConfigParser pcp=null;
131         Object pl=null;
132         for(int i=0;i<pluginsName.size();i++){
133             dirName=(String)pluginsName.get(i);
134             pcp=new PluginConfigParser();
135             pl=pcp.parseFile( new File(this.basePath+fs+"plugins"+fs+dirName+fs+"config.xml") );
136             plugins.add(pl);
137         }
138         */

139         
140         this.modWidgets=this.loadModules(this.basePath);
141         
142         
143         /*
144         ArrayList modules=NukeResource.getDirectories(this.basePath+fs+"modules");
145         //GeiServlet.intLog("GlobalCFG(...), modules="+modules);
146         String name=null;
147         ModuleConfigParser mParser=null;
148         ModuleWrapper mod=null;
149         for(int i=0;i<modules.size();i++){
150             name=(String)modules.get(i);
151             //GeiServlet.intLog("GlobalCFG(...),i="+i+" simple");
152             mParser=new ModuleConfigParser();
153             //GeiServlet.intLog("GlobalCFG(...),i="+i+" name="+name);
154             mod=(ModuleWrapper)mParser.parseFile( new File(this.basePath+fs+"modules"+fs+name+fs+"config.xml") );
155             //GeiServlet.intLog("GlobalCFG(...),i="+i+" mod="+mod);
156             this.modWidgets.put(name,mod);
157         }
158         */

159         this.blockWidgets=this.loadBlocks(this.basePath);
160         
161         /*
162         ArrayList blocks=NukeResource.getDirectories(this.basePath+fs+"blocks");
163         //GeiServlet.intLog("GlobalCFG(...), blocks"+blocks);
164         BlockWrapper bloWr=null;
165         BlockConfigParser bParser=null;
166         bParser=new BlockConfigParser();
167         for(int i=0;i<blocks.size();i++){
168             name=(String)blocks.get(i);
169             bloWr=(BlockWrapper)bParser.parseFile( new File(this.basePath+fs+"blocks"+fs+name+fs+"config.xml") );
170             this.blockWidgets.put(name,bloWr);
171         }
172         */

173         //GeiServlet.intLog("GlobalCFG(...), END");
174
}
175     
176     public ModuleDBVO getDefaultModule() {
177         // TODO Auto-generated method stub
178
return null;
179     }
180
181     
182     public ModuleWidgetI getModuleWidget(String JavaDoc moduleName,String JavaDoc op) {
183         //GeiServlet.intLog("GlobalCFG.getModuleWidget(...), START");
184
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         //GeiServlet.intLog("GlobalCFG.getModuleWidget(...), modWidgets="+this.modWidgets);
190
mod=(ModuleWrapper)this.modWidgets.get(moduleName);
191         //GeiServlet.intLog("GlobalCFG.getModuleWidget(...), mod="+mod);
192
return (ModuleWidgetI)mod.getObject(op);
193     }
194     
195     public String JavaDoc getModulePage(String JavaDoc moduleName,String JavaDoc op) {
196         //GeiServlet.intLog("GlobalCFG.getModulePage(...), START");
197
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         //GeiServlet.intLog("GlobalCFG.getModulePage(...), modWidgets="+this.modWidgets);
203

204         mod=(ModuleWrapper)this.modWidgets.get(moduleName);
205         //GeiServlet.intLog("GlobalCFG.getModulePage(...), mod="+mod);
206
if(op==null)
207             op="";
208         return (String JavaDoc)mod.getPage(op);
209     }
210     
211     public String JavaDoc getModulePage(String JavaDoc moduleName,HttpServletRequest JavaDoc req) {
212         return this.getModulePage(moduleName,req.getParameter("op"));
213         
214     }
215
216     
217     public BlockWidgetI getBlockWidget(String JavaDoc blockName) {
218         
219         BlockWrapper bw=null;
220         bw=(BlockWrapper)this.blockWidgets.get(blockName);
221         return bw.getBlockWidget();
222         
223     }
224
225     
226     public Vector JavaDoc getPlugins() {
227         
228         return this.plugins;
229     }
230
231 }
232
Popular Tags