    001package org.apache.turbine.util;
    002
    003
    004/*
    005 * Licensed to the Apache Software Foundation (ASF) under one
    006 * or more contributor license agreements.  See the NOTICE file
    007 * distributed with this work for additional information
    008 * regarding copyright ownership.  The ASF licenses this file
    009 * to you under the Apache License, Version 2.0 (the
    010 * "License"); you may not use this file except in compliance
    011 * with the License.  You may obtain a copy of the License at
    012 *
    013 *   http://www.apache.org/licenses/LICENSE-2.0
    014 *
    015 * Unless required by applicable law or agreed to in writing,
    016 * software distributed under the License is distributed on an
    017 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    018 * KIND, either express or implied.  See the License for the
    019 * specific language governing permissions and limitations
    020 * under the License.
    021 */
    022
    023import java.util.HashMap;
    024import java.util.Map;
    025
    026/**
    027 * A class used for initialization of Turbine without a servlet container.
    028 * <p>
    029 * If you need to use Turbine outside of a servlet container, you can
    030 * use this class for initialization of the Turbine servlet.
    031 * <p>
    032 * <pre>
    033 * TurbineXmlConfig config = new TurbineXmlConfig(".", "conf/TurbineResources.properties");
    034 * </pre>
    035 * <p>
    036 * All paths referenced in TurbineResources.properties and the path to
    037 * the properties file itself (the second argument) will be resolved
    038 * relative to the directory given as the first argument of the constructor,
    039 * here - the directory where application was started. Don't worry about
    040 * discarding the references to objects created above. They are not needed,
    041 * once everything is initialized.
    042 * <p>
    043 * In order to initialize the Services Framework outside of the Turbine Servlet,
    044 * you need to call the <code>init()</code> method. By default, this will
    045 * initialize the Resource and Logging Services and any other services you
    046 * have defined in your TurbineResources.properties file.
    047 *
    048 * TODO Make this class enforce the lifecycle contracts
    049 *
    050 * @author <a href="mailto:epugh@upstate.com">Eric Pugh</a>
    051 * @version $Id: TurbineXmlConfig.java 1773378 2016-12-09 13:19:59Z tv $
    052 */
    053public class TurbineXmlConfig
    054        extends TurbineConfig
    055{
    056    /**
    057     * Constructs a new TurbineXmlConfig.
    058     *
    059     * This is the general form of the constructor. You can provide
    060     * a path to search for files, and a name-value map of init
    061     * parameters.
    062     *
    063     * <p> For the list of recognized init parameters, see
    064     * {@link org.apache.turbine.Turbine} class.
    065     *
    066     * @param path The web application root (i.e. the path for file lookup).
    067     * @param attributes Servlet container (or emulator) attributes.
    068     * @param initParams initialization parameters.
    069     */
    070    public TurbineXmlConfig(String path, Map<String, Object> attributes,
    071            Map<String, String> initParams)
    072    {
    073        super(path, attributes, initParams);
    074    }
    075
    076    /**
    077     * Constructs a new TurbineXmlConfig.
    078     *
    079     * This is the general form of the constructor. You can provide
    080     * a path to search for files, and a name-value map of init
    081     * parameters.
    082     *
    083     * <p> For the list of recognized init parameters, see
    084     * {@link org.apache.turbine.Turbine} class.
    085     *
    086     * @param path The web application root (i.e. the path for file lookup).
    087     * @param initParams initialization parameters.
    088     */
    089    public TurbineXmlConfig(String path, Map<String, String> initParams)
    090    {
    091        this(path, new HashMap<String, Object>(0), initParams);
    092    }
    093
    094    /**
    095     * Constructs a TurbineXmlConfig.
    096     *
    097     * This is a specialized constructor that allows to configure
    098     * Turbine easily in the common setups.
    099     *
    100     * @param path The web application root (i.e. the path for file lookup).
    101     * @param config the relative path to TurbineResources.xml file
    102     */
    103    public TurbineXmlConfig(String path, String config)
    104    {
    105        this(path, new HashMap<String, String>(1));
    106        initParams.put(CONFIGURATION_PATH_KEY, config);
    107    }
    108}