KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > nemesis > forum > config > InitServlet


1 package org.nemesis.forum.config;
2
3 import java.io.File JavaDoc;
4
5 import javax.servlet.ServletContext JavaDoc;
6 import javax.servlet.http.HttpServlet JavaDoc;
7 import javax.servlet.http.HttpServletRequest JavaDoc;
8 import javax.servlet.http.HttpServletResponse JavaDoc;
9
10 import org.apache.commons.logging.Log;
11 import org.apache.commons.logging.LogFactory;
12
13 public class InitServlet extends HttpServlet JavaDoc {
14     
15     private static Log log=LogFactory.getLog(InitServlet.class);
16     
17     public static String JavaDoc DATA_PATH;
18      
19     
20      /**
21       * la servlet doit etre configuré dans le web.xml pour etre chargée au demarage du container de servlet<br>
22       *
23       *
24       * */

25     public void init() {
26         log.info("--------INIT START-------------");
27
28
29         if(getServletConfig().getInitParameter("dataPath") !=null) {
30             DATA_PATH = getServletConfig().getInitParameter("dataPath");
31         }else{//relative
32
String JavaDoc realPath=getServletContext().getRealPath("");
33             if(realPath==null){
34                 System.err.println("your system doesn't support getServletContext().getRealPath() method, set absolute path in your web.xml");
35                 log.fatal("your system doesn't support getServletContext().getRealPath() method, set absolute path in your web.xml");
36                 System.exit(1);
37             }
38             DATA_PATH= realPath+File.separator+"WEB-INF"+File.separator+"nemesis-data";
39         }
40         
41         
42         
43         //---------------- P6spy -------------
44
ServletContext JavaDoc context = this.getServletConfig().getServletContext();
45
46         String JavaDoc jcp = System.getProperty("java.class.path");
47
48 // System.setProperty(
49
// "java.class.path",
50
// jcp
51
// + System.getProperty("path.separator")
52
// + context.getRealPath("WEB-INF/lib/p6spy.jar")
53
// + System.getProperty("path.separator")
54
// + context.getRealPath("WEB-INF/classes/"));
55
//
56
log.info("System classpath :\n"+System.getProperty("java.class.path"));
57         
58         //------------------------------------
59

60         String JavaDoc encoding = System.getProperty("file.encoding");
61         //System.setProperty("file.encoding","ISO-8859-1");
62

63         log.info("System file.encoding :"+encoding);
64         //------------------------------------
65

66         //parfois besoin d'un repertoire temporaire
67
String JavaDoc tempdir = System.getProperty("java.io.tmpdir");
68             
69         log.info("System TEMP DIR :"+tempdir);
70         //------------------------------------
71

72         //lancement du serveur hypersonic en mode serveur, a desactivé en production-->standalone
73
// String launchHSQLDB = getServletConfig().getInitParameter("launchHSQLDB");
74
// if("true".equals(launchHSQLDB)){
75
// try {
76
//
77
// Thread t=(new Thread( ){
78
// public void run(){
79
// try {
80
// Server hsql = new Server();
81
// hsql.main(
82
// new String[]{
83
// "-port","9001",
84
// "-silent","true",
85
// "-database",DATA_PATH+"/db/nemesis"
86
// }
87
// );
88
// } catch (Exception e) {
89
// log.fatal("hypersonic launch failed",e);
90
// }
91
// }
92
// });
93
// t.setDaemon(true);
94
// t.start();
95
// log.info("hypersonic ok");
96
//
97
// } catch (Throwable e) {
98
// log.fatal("hypersonic launch failed",e);
99
// }
100
// }
101
log.info("--------INIT END-------------");
102
103         
104     }
105     
106
107
108     public void doService(HttpServletRequest JavaDoc req, HttpServletResponse JavaDoc res) {
109         return;
110     }
111
112     /* (non-Javadoc)
113      * @see javax.servlet.Servlet#destroy()
114      */

115     public void destroy() {
116         super.destroy();
117         
118         
119     }
120
121 }
122
Popular Tags