KickJava   Java API By Example, From Geeks To Geeks.

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


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

5
6 package com.raptus.owxv3;
7
8 import java.util.Hashtable JavaDoc;
9
10 import javax.servlet.*;
11
12 import org.apache.struts.action.ActionServlet;
13 import org.apache.struts.config.ModuleConfig;
14
15 /**
16  *
17  *
18  * <hr>
19  * <table width="100%" border="0">
20  * <tr>
21  * <td width="24%"><b>Filename</b></td><td width="76%">StrutsOWXPlugIn.java</td>
22  * </tr>
23  * <tr>
24  * <td width="24%"><b>Author</b></td><td width="76%">Guy Zuercher (gzuercher@raptus.com)</td>
25  * </tr>
26  * <tr>
27  * <td width="24%"><b>Date</b></td><td width="76%">15th of April 2003</td>
28  * </tr>
29  * </table>
30  * <hr>
31  * <table width="100%" border="0">
32  * <tr>
33  * <td width="24%"><b>Date / Author</b></td><td width="76%"><b>Changes</b></td>
34  * </tr>
35  * <tr>
36  * <td width="24%"></td><td width="76%"></td>
37  * </tr>
38  * <tr>
39  * <td width="24%"></td><td width="76%"></td>
40  * </tr>
41  * </table>
42  * <hr>
43  */

44 public class StrutsOWXPlugIn implements org.apache.struts.action.PlugIn
45 {
46     /**
47      *
48      */

49     public boolean isInitialized() { return (webinfdir != null && servlet != null); }
50     
51     /**
52      *
53      */

54     protected String JavaDoc webinfdir = null;
55     public String JavaDoc getWEBINFDir() { return webinfdir; }
56     public void setWEBINFDir(String JavaDoc wid) { this.webinfdir = wid; }
57
58     /**
59      *
60      */

61     protected ActionServlet servlet = null;
62     public ActionServlet getServlet() { return servlet; }
63     public void setServlet(ActionServlet s) { this.servlet = s; }
64     
65     /**
66      *
67      */

68     protected ModuleConfig config = null;
69     public ModuleConfig getConfig() { return config; }
70     public void setConfig(ModuleConfig c) { this.config = c; }
71     
72     /**
73      *
74      */

75     protected VModuleManager vmm = null;
76
77     /**
78      *
79      */

80     public void init(ActionServlet servlet, ModuleConfig config)
81                      throws javax.servlet.ServletException JavaDoc
82     {
83         if(!isInitialized())
84         {
85             // remember that servlet (for convenience)
86
setServlet(servlet);
87             setConfig(config);
88             
89             ServletContext ctx = servlet.getServletContext();
90             webinfdir = ctx.getRealPath("/WEB-INF/") + "/";
91             
92             String JavaDoc logFile = ctx.getInitParameter("owxlogfile");
93             if(logFile == null)
94                throw new ServletException("Servlet context param <owxlogfile> is NULL.");
95
96             Hashtable JavaDoc initParams = new Hashtable JavaDoc();
97 // initParams.put("ConfigManager.HandlerClass", "com.raptus.owxv3.PropertiesConfigManager");
98
//
99
// initParams.put("ConfigManager.PropertiesConfigManager.FileName", getWEBINFDir() +
100
// "owx-configuration.properties");
101
initParams.put("ConfigManager.HandlerClass", "com.raptus.owxv3.XMLConfigManager");
102             
103             initParams.put("ConfigManager.XMLConfigManager.FileName", getWEBINFDir() +
104                            "owx-config.xml");
105
106             initParams.put("LoggingManager.LogHandler", "com.raptus.owxv3.PlainLoggingManager");
107             initParams.put("LoggingManager.PlainLoggingManager.LogFile", logFile);
108
109             LoggingManager logMgr = LoggingManager.getInstance(initParams);
110             if(logMgr == null)
111                 throw new ServletException("LoggingManager cannot be initialized.");
112
113             ConfigManager cfgMgr = ConfigManager.getInstance(initParams);
114             //if(cfgMgr == null)
115
// throw new ServletException("ConfigManager cannot be initialized.");
116

117             LoggingManager.log("Preparing virtualhost ...", (Object JavaDoc) this);
118
119             vmm = VModuleManager.getInstance();
120             if(!vmm.initialize(this))
121                 throw new ServletException("VModuleManager cannot be initialized.");
122
123             LoggingManager.log("Virtualhost is now ready for requests", (Object JavaDoc) this);
124             
125 // xmlvmm = XMLVModuleManager.getInstance();
126
// if(!xmlvmm.initialize(this))
127
// throw new ServletException("XMLVModuleManager cannot be initialized.");
128
}
129         else
130             throw new ServletException("StrutsOWXPlugin is already initialized! Is this an error?");
131    }
132
133    /**
134     *
135     */

136    public void destroy()
137    {
138        webinfdir = null;
139        servlet = null;
140    }
141
142 }
143
144 // eof
145
Popular Tags