001 package 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 023 import java.util.HashMap; 024 import 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 * <blockquote><code><pre> 033 * TurbineXmlConfig config = new TurbineXmlConfig(".", "conf/TurbineResources.properties"); 034 * </pre></code></blockquote> 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 1073174 2011-02-21 22:18:45Z tv $ 052 */ 053 public 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 * @see #TurbineXmlConfig(String path, Map attributes, Map initParams) 078 */ 079 public TurbineXmlConfig(String path, Map<String, String> initParams) 080 { 081 this(path, new HashMap<String, Object>(0), initParams); 082 } 083 084 /** 085 * Constructs a TurbineXmlConfig. 086 * 087 * This is a specialized constructor that allows to configure 088 * Turbine easiliy in the common setups. 089 * 090 * @param path The web application root (i.e. the path for file lookup). 091 * @param configuration the relative path to TurbineResources.xml file 092 */ 093 public TurbineXmlConfig(String path, String config) 094 { 095 this(path, new HashMap<String, String>(1)); 096 initParams.put(CONFIGURATION_PATH_KEY, config); 097 } 098 }