View Javadoc
1   package org.apache.turbine.util;
2   
3   
4   /*
5    * Licensed to the Apache Software Foundation (ASF) under one
6    * or more contributor license agreements.  See the NOTICE file
7    * distributed with this work for additional information
8    * regarding copyright ownership.  The ASF licenses this file
9    * to you under the Apache License, Version 2.0 (the
10   * "License"); you may not use this file except in compliance
11   * with the License.  You may obtain a copy of the License at
12   *
13   *   http://www.apache.org/licenses/LICENSE-2.0
14   *
15   * Unless required by applicable law or agreed to in writing,
16   * software distributed under the License is distributed on an
17   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
18   * KIND, either express or implied.  See the License for the
19   * specific language governing permissions and limitations
20   * under the License.
21   */
22  
23  import java.util.HashMap;
24  import java.util.Map;
25  
26  /**
27   * A class used for initialization of Turbine without a servlet container.
28   *
29   * <p>
30   * If you need to use Turbine outside of a servlet container, you can
31   * use this class for initialization of the Turbine servlet.
32   * </p>
33   *
34   * <pre>
35   * TurbineXmlConfig config = new TurbineXmlConfig(".", "conf/TurbineResources.properties");
36   * </pre>
37   *
38   * <p>
39   * All paths referenced in TurbineResources.properties and the path to
40   * the properties file itself (the second argument) will be resolved
41   * relative to the directory given as the first argument of the constructor,
42   * here - the directory where application was started. Don't worry about
43   * discarding the references to objects created above. They are not needed,
44   * once everything is initialized.
45   * </p>
46   *
47   * <p>
48   * In order to initialize the Services Framework outside of the Turbine Servlet,
49   * you need to call the <code>init()</code> method. By default, this will
50   * initialize the Resource and Logging Services and any other services you
51   * have defined in your TurbineResources.properties file.
52   * </p>
53   *
54   * TODO Make this class enforce the lifecycle contracts
55   *
56   * @author <a href="mailto:epugh@upstate.com">Eric Pugh</a>
57   * @version $Id$
58   */
59  public class TurbineXmlConfig
60          extends TurbineConfig
61  {
62      /**
63       * Constructs a new TurbineXmlConfig.
64       *
65       * This is the general form of the constructor. You can provide
66       * a path to search for files, and a name-value map of init
67       * parameters.
68       *
69       * <p> For the list of recognized init parameters, see
70       * {@link org.apache.turbine.Turbine} class.
71       *
72       * @param path The web application root (i.e. the path for file lookup).
73       * @param attributes Servlet container (or emulator) attributes.
74       * @param initParams initialization parameters.
75       */
76      public TurbineXmlConfig(String path, Map<String, Object> attributes,
77              Map<String, String> initParams)
78      {
79          super(path, attributes, initParams);
80      }
81  
82      /**
83       * Constructs a new TurbineXmlConfig.
84       *
85       * This is the general form of the constructor. You can provide
86       * a path to search for files, and a name-value map of init
87       * parameters.
88       *
89       * <p> For the list of recognized init parameters, see
90       * {@link org.apache.turbine.Turbine} class.
91       *
92       * @param path The web application root (i.e. the path for file lookup).
93       * @param initParams initialization parameters.
94       */
95      public TurbineXmlConfig(String path, Map<String, String> initParams)
96      {
97          this(path, new HashMap<String, Object>(0), initParams);
98      }
99  
100     /**
101      * Constructs a TurbineXmlConfig.
102      *
103      * This is a specialized constructor that allows to configure
104      * Turbine easily in the common setups.
105      *
106      * @param path The web application root (i.e. the path for file lookup).
107      * @param config the relative path to TurbineResources.xml file
108      */
109     public TurbineXmlConfig(String path, String config)
110     {
111         this(path, new HashMap<String, String>(1));
112         initParams.put(CONFIGURATION_PATH_KEY, config);
113     }
114 }