View Javadoc

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   *  &lt;servlet&gt;
43   *    &lt;servlet-name&gt;Pow2ToolkitInit&lt;/servlet-name&gt;
44   *    &lt;servlet-class&gt;com.pow2.resources.Pow2ToolkitInit&lt;/servlet-class&gt;
45   *
46   *    &lt;init-param&gt;
47   *      &lt;param-name&gt;properties&lt;/param-name&gt;
48   *      &lt;param-value&gt;WEB-INF/pow2toolkit.properties&lt;/param-value&gt;
49   *    &lt;/init-param&gt;
50   *
51   *    &lt;load-on-startup&gt;1&lt;/load-on-startup&gt;
52   *  &lt;/servlet&gt;
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      // cannot get the properties file path
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      // configure the Pow2Toolkit Prefs object;
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  }