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   * <p>
    29   * If you need to use Turbine outside of a servlet container, you can
    30   * use this class for initialization of the Turbine servlet.
    31   * <p>
    32   * <blockquote><code><pre>
    33   * TurbineXmlConfig config = new TurbineXmlConfig(".", "conf/TurbineResources.properties");
    34   * </pre></code></blockquote>
    35   * <p>
    36   * All paths referenced in TurbineResources.properties and the path to
    37   * the properties file itself (the second argument) will be resolved
    38   * relative to the directory given as the first argument of the constructor,
    39   * here - the directory where application was started. Don't worry about
    40   * discarding the references to objects created above. They are not needed,
    41   * once everything is initialized.
    42   * <p>
    43   * In order to initialize the Services Framework outside of the Turbine Servlet,
    44   * you need to call the <code>init()</code> method. By default, this will
    45   * initialize the Resource and Logging Services and any other services you
    46   * have defined in your TurbineResources.properties file.
    47   *
    48   * @todo Make this class enforce the lifecycle contracts
    49   *
    50   * @author <a href="mailto:epugh@upstate.com">Eric Pugh</a>
    51   * @version $Id: TurbineXmlConfig.java 1073174 2011-02-21 22:18:45Z tv $
    52   */
    53  public class TurbineXmlConfig
    54          extends TurbineConfig
    55  {
    56      /**
    57       * Constructs a new TurbineXmlConfig.
    58       *
    59       * This is the general form of the constructor. You can provide
    60       * a path to search for files, and a name-value map of init
    61       * parameters.
    62       *
    63       * <p> For the list of recognized init parameters, see
    64       * {@link org.apache.turbine.Turbine} class.
    65       *
    66       * @param path The web application root (i.e. the path for file lookup).
    67       * @param attributes Servlet container (or emulator) attributes.
    68       * @param initParams initialization parameters.
    69       */
    70      public TurbineXmlConfig(String path, Map<String, Object> attributes,
    71              Map<String, String> initParams)
    72      {
    73          super(path, attributes, initParams);
    74      }
    75
    76      /**
    77       * @see #TurbineXmlConfig(String path, Map attributes, Map initParams)
    78       */
    79      public TurbineXmlConfig(String path, Map<String, String> initParams)
    80      {
    81          this(path, new HashMap<String, Object>(0), initParams);
    82      }
    83
    84      /**
    85       * Constructs a TurbineXmlConfig.
    86       *
    87       * This is a specialized constructor that allows to configure
    88       * Turbine easiliy in the common setups.
    89       *
    90       * @param path The web application root (i.e. the path for file lookup).
    91       * @param configuration the relative path to TurbineResources.xml file
    92       */
    93      public TurbineXmlConfig(String path, String config)
    94      {
    95          this(path, new HashMap<String, String>(1));
    96          initParams.put(CONFIGURATION_PATH_KEY, config);
    97      }
    98  }