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 * 029 * <p> 030 * If you need to use Turbine outside of a servlet container, you can 031 * use this class for initialization of the Turbine servlet. 032 * </p> 033 * 034 * <pre> 035 * TurbineXmlConfig config = new TurbineXmlConfig(".", "conf/TurbineResources.properties"); 036 * </pre> 037 * 038 * <p> 039 * All paths referenced in TurbineResources.properties and the path to 040 * the properties file itself (the second argument) will be resolved 041 * relative to the directory given as the first argument of the constructor, 042 * here - the directory where application was started. Don't worry about 043 * discarding the references to objects created above. They are not needed, 044 * once everything is initialized. 045 * </p> 046 * 047 * <p> 048 * In order to initialize the Services Framework outside of the Turbine Servlet, 049 * you need to call the <code>init()</code> method. By default, this will 050 * initialize the Resource and Logging Services and any other services you 051 * have defined in your TurbineResources.properties file. 052 * </p> 053 * 054 * TODO Make this class enforce the lifecycle contracts 055 * 056 * @author <a href="mailto:epugh@upstate.com">Eric Pugh</a> 057 * @version $Id$ 058 */ 059public class TurbineXmlConfig 060 extends TurbineConfig 061{ 062 /** 063 * Constructs a new TurbineXmlConfig. 064 * 065 * This is the general form of the constructor. You can provide 066 * a path to search for files, and a name-value map of init 067 * parameters. 068 * 069 * <p> For the list of recognized init parameters, see 070 * {@link org.apache.turbine.Turbine} class. 071 * 072 * @param path The web application root (i.e. the path for file lookup). 073 * @param attributes Servlet container (or emulator) attributes. 074 * @param initParams initialization parameters. 075 */ 076 public TurbineXmlConfig(String path, Map<String, Object> attributes, 077 Map<String, String> initParams) 078 { 079 super(path, attributes, initParams); 080 } 081 082 /** 083 * Constructs a new TurbineXmlConfig. 084 * 085 * This is the general form of the constructor. You can provide 086 * a path to search for files, and a name-value map of init 087 * parameters. 088 * 089 * <p> For the list of recognized init parameters, see 090 * {@link org.apache.turbine.Turbine} class. 091 * 092 * @param path The web application root (i.e. the path for file lookup). 093 * @param initParams initialization parameters. 094 */ 095 public TurbineXmlConfig(String path, Map<String, String> initParams) 096 { 097 this(path, new HashMap<String, Object>(0), initParams); 098 } 099 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}