1 /*
2 * PROJECT : DAR Runtime and Tools
3 * COPYRIGHT : Copyright (C) 1999-2004 tim.stephenson@enableit.org
4 * LICENSE : GNU LESSER GENERAL PUBLIC LICENSE
5 * Version 2.1, February 1999
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 */
21 package org.enableit.db.darrt.web;
22
23
24 // Java imports
25 import java.io.File;
26
27 import javax.servlet.ServletException;
28 import javax.servlet.http.HttpServlet;
29
30 import org.apache.log4j.Logger;
31 import org.enableit.db.darrt.DarHandler;
32
33
34 /***
35 * Servlet used to check for and install a DAR file on server start.
36 */
37 public class DarHandlerServlet extends HttpServlet {
38 /*
39 * Properties
40 */
41
42 /***
43 * The Log4J <code>Logger</code> doing the logging.
44 */
45 private static Logger logger = Logger.getLogger(DarHandlerServlet.class);
46
47 /***
48 * CVS info ABOUT this class and its current version
49 */
50 public static final String ABOUT = "$Id: DarHandlerServlet.java,v 1.6 2004/03/20 05:25:03 tim Exp $";
51
52 /*
53 * Constructors
54 */
55
56 /***
57 * Default Constructor
58 */
59 public DarHandlerServlet() {
60 super();
61 }
62
63 /*
64 * Methods
65 */
66
67 /***
68 * Checks for a dar file named in the web.xml and installs it.
69 * <p>
70 * The servlet init-parameter name to specify the dar with is: dar-name.
71 * </p>
72 */
73 public void init()
74 throws javax.servlet.ServletException {
75 super.init();
76
77 try {
78 String darName = getServletContext().getInitParameter("dar-name");
79 File dar = new File(darName);
80
81 if (!dar.exists()) {
82 dar = new File(getServletContext().getRealPath("/"), darName);
83 }
84
85 if (dar.exists()) {
86 DarHandler dh = new DarHandler();
87
88 dh.install(dar.toURL());
89 }
90 } catch (java.net.MalformedURLException e) {
91 throw new ServletException(e.getMessage(), e);
92 } catch (org.enableit.db.DBException e) {
93 throw new ServletException(e.getMessage(), e);
94 }
95 }
96 }
This page was automatically generated by Maven