1 /***
2 * The contents of this file are subject to the Mozilla Public
3 * License Version 1.1 (the "License"); you may not use this file
4 * except in compliance with the License. You may obtain a copy of
5 * the License at http://www.mozilla.org/MPL/
6 *
7 * Software distributed under the License is distributed on an "AS
8 * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
9 * implied. See the License for the specific language governing
10 * rights and limitations under the License.
11 *
12 * The Original Code is pow2toolkit library.
13 *
14 * The Initial Owner of the Original Code is
15 * Power Of Two S.R.L. (www.pow2.com)
16 *
17 * Portions created by Power Of Two S.R.L. are
18 * Copyright (C) Power Of Two S.R.L.
19 * All Rights Reserved.
20 *
21 * Contributor(s):
22 */
23
24 package com.pow2.resources;
25
26
27 import javax.servlet.ServletException;
28
29 import com.pow2.resources.Prefs;
30 import com.pow2.util.Util;
31
32
33 /***
34 * Pow2Toolkit init servlet.
35 * <br>
36 * Configure and initialize the toolkit defining the following servlet
37 * into the web.xml file of your web-application.
38 *
39 * <code>
40 * <pre>
41 *
42 * <servlet>
43 * <servlet-name>Pow2ToolkitInit</servlet-name>
44 * <servlet-class>com.pow2.resources.Pow2ToolkitInit</servlet-class>
45 *
46 * <init-param>
47 * <param-name>properties</param-name>
48 * <param-value>WEB-INF/pow2toolkit.properties</param-value>
49 * </init-param>
50 *
51 * <load-on-startup>1</load-on-startup>
52 * </servlet>
53 *
54 * </pre>
55 * </code>
56 *
57 * Writing an initialization servlet is the most flexible way for initializing Pow2Toolkit.
58 * There are no constraints on the code you can place in the init() method of the servlet.
59 *
60 * @author Luca Fossato
61 * @created 2 maggio 2002
62 */
63 public class Pow2ToolkitInit extends InitServlet
64 {
65 /***
66 * Initialize this servlet and configure the Properties object
67 * using the configuration file whose path is set by the <code>properties</code>
68 * parameter of the <code>web.xml</code> file.
69 *
70 * @exception ServletException Description of the Exception
71 */
72 public void init() throws ServletException
73 {
74 super.init();
75 String file = getInitParameterFilePath("properties");
76
77
78 if (Util.isNull(file))
79 {
80 String err = "cannot configure the toolkit. Properties file is null";
81 cat.error("::init - " + err);
82 throw new ServletException(err);
83 }
84
85
86 try
87 {
88 Prefs.instance().configure(file);
89 }
90 catch(Exception e)
91 {
92 cat.error("::init - preferences configuration failed", e);
93 throw new ServletException(e.getMessage());
94 }
95
96 cat.info("::init - Pow2Toolkit successfully configured");
97 }
98 }