KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > raptus > owxv3 > XMLVModuleManager


1 /*
2  * eAdmin/OWX
3  * Copyright (C) 1996-2003 OWX-Project Team <owx-team@gmx.net>
4  */

5  
6 /*
7  * XMLVModuleManager.java
8  *
9  * Created on April 23, 2002, 11:47 AM
10  */

11
12 package com.raptus.owxv3;
13
14 import java.io.File JavaDoc;
15 import java.util.*;
16
17 import org.jdom.*;
18 import org.jdom.input.SAXBuilder;
19
20
21 /**
22  *
23  * @author root
24  */

25 public class XMLVModuleManager extends Object JavaDoc
26 {
27     protected String JavaDoc directoryWEBINF;
28     protected static Virtualhost _vhost=null;
29     
30     public Virtualhost getVirtualhost()
31     {
32         return _vhost;
33     }
34     
35     /** Creates a new instance of XMLVModuleManager */
36     public XMLVModuleManager()
37     {
38         //LoggingManager.log("XMLVModuleManager constructor!");
39
}
40     
41     /**
42      *
43      */

44     protected static XMLVModuleManager _instance = null;
45     
46     protected static Element root = null;
47
48     /**
49      * Singleton mechanism for the manager
50      */

51     public static XMLVModuleManager getInstance()
52     {
53         if(_instance == null)
54             _instance = new XMLVModuleManager();
55
56         return _instance;
57     }
58     
59     /**
60      *
61      */

62     public boolean initialize(StrutsOWXPlugIn plugin)
63     {
64         //LoggingManager.log("initialse() in XMLVModuleManager");
65
// datasources = new Hashtable();
66
// tablenames=new Hashtable();
67
directoryWEBINF = plugin.getWEBINFDir();
68         //LoggingManager.log("web Directory is "+ directoryWEBINF);
69

70         try
71         {
72             // Request document building without validation
73
SAXBuilder builder = new SAXBuilder(false);
74             String JavaDoc file=directoryWEBINF+"/"+"owx-config.xml";
75             Document doc = builder.build(new File JavaDoc(file));
76             root = doc.getRootElement();
77             //LoggingManager.log("XML Config file loaded!");
78

79             // start initialisation process.
80
// first get virtual hosts and initialise them
81
List categories = root.getChildren("virtualhost");
82             Iterator i = categories.iterator();
83
84             while (i.hasNext())
85             {
86                 Element vhost = (Element) i.next();
87                 if(vhost != null)
88                 {
89                     if(!initialiseVirtualHost(vhost))
90                     {
91                         return false;
92                     }
93                 }
94             }
95         }
96         catch(org.jdom.JDOMException ex)
97         {
98             ex.printStackTrace();
99         }
100         // Get the root element (categorylist)
101

102         
103         return true;
104     }
105     
106     /**
107      * Initialise a virtual host
108      */

109     public boolean initialiseVirtualHost(Element e)
110     {
111         //LoggingManager.log("Initialising Virtual Host !");
112
// identification="owxv3.raptus.com"
113
// hostname="owxv3.raptus.com"
114
// webmaster="webmaster"
115
// multiuser="true"
116
// mailhost="mail.raptus.com"
117
//LoggingManager.log("Identification="+e.getAttribute("identification").getValue());
118
//LoggingManager.log("webmaster="+e.getAttribute("webmaster").getValue());
119
//LoggingManager.log("hostname="+e.getAttribute("hostname").getValue());
120
//LoggingManager.log("multiuser="+e.getAttribute("multiuser").getValue());
121

122         _vhost = new Virtualhost(e.getAttribute("identification").getValue(),
123             e.getAttribute("webmaster").getValue(),
124             e.getAttribute("hostname").getValue(),
125             e.getAttribute("multiuser").getValue().equals("true")
126         );
127         
128             List gresl = e.getChildren("global_resource");
129             Iterator i = gresl.iterator();
130
131             while (i.hasNext())
132             {
133                 Element gres = (Element) i.next();
134                 if(gres != null)
135                 {
136                     if(!initialiseGlobalResource(gres))
137                     {
138                         return false;
139                     }
140                 }
141             }
142         //LoggingManager.log("Virtual Host! initialised :)");
143
return true;
144     }
145     
146     public boolean initialiseGlobalResource(Element e)
147     {
148         //LoggingManager.log("Initialising global resources! :)");
149
return true;
150     }
151 }
152
Popular Tags