dlr 02/04/16 18:59:54 Modified: src/java/org/apache/turbine Turbine.java Log: o Added new findInitParameter(ServletContext, ServletConfig, String, String) method which should be used for all access to Turbine global or servlet-specific initialization parameters. It also introduces a new namespace (of "org.apache.turbine") which all parameters will eventually be prefixed with. It aims to be fully backwards compatible with non-prefixed parameter names. o Modified interface of createRuntimeDirectories() method to take parameters which will allow it to live up to its name and JavaDoc (and incidiently, to supply the required parameters the new findInitParameter() method). o Replaced all calls to ServletContext's and ServletConfig's getInitParameter(String) with the new findInitParameter() method. Revision Changes Path 1.37 +70 -16 jakarta-turbine-3/src/java/org/apache/turbine/Turbine.java Index: Turbine.java =================================================================== RCS file: /home/cvs/jakarta-turbine-3/src/java/org/apache/turbine/Turbine.java,v retrieving revision 1.36 retrieving revision 1.37 diff -u -u -r1.36 -r1.37 --- Turbine.java 16 Apr 2002 22:24:01 -0000 1.36 +++ Turbine.java 17 Apr 2002 01:59:54 -0000 1.37 @@ -124,7 +124,7 @@ * @author <a href="mailto:[EMAIL PROTECTED]">Jason van Zyl</a> * @author <a href="mailto:[EMAIL PROTECTED]">Daniel Rall</a> * @author <a href="mailto:[EMAIL PROTECTED]">Martin Poeschl</a> - * @version $Id: Turbine.java,v 1.36 2002/04/16 22:24:01 jvanzyl Exp $ + * @version $Id: Turbine.java,v 1.37 2002/04/17 01:59:54 dlr Exp $ */ public class Turbine extends HttpServlet @@ -182,8 +182,12 @@ try { // Setup static configuration (using default properties file). - String trProps = config.getInitParameter(TurbineConfig.PROPERTIES_KEY); - configure(config, config.getServletContext(), trProps); + ServletContext context = config.getServletContext(); + String trProps = + findInitParameter(context, config, + TurbineConfig.PROPERTIES_KEY, + "TurbineResources.properties"); + configure(config, context, trProps); } catch ( Exception e ) { @@ -545,8 +549,10 @@ * or by non-servlet applications for configuring Turbine. It loads * the default resources from a properties file. * - * @param config Servlet initialization parameter. + * @param config Initialization parameters specific to the Turbine + * servlet. * @param context Servlet container communication channel. + * Provides access to global initialization parameters. * @param propsFile The abstract path to your * <code>TurbineResources.properties</code> file (including file * name), relative to web application root. Defaults to {@link @@ -562,7 +568,8 @@ { // Set the application root. This defaults to the webapp // context if not otherwise set. - applicationRoot = config.getInitParameter(APPLICATION_ROOT); + applicationRoot = + findInitParameter(context, config, APPLICATION_ROOT, null); if (applicationRoot == null || applicationRoot.equals(WEB_CONTEXT)) { @@ -577,7 +584,7 @@ // runtime. Right now this creates the directories // for logging but we might have more of these // directories in the future. - createRuntimeDirectories(config.getInitParameter(LOGGING_ROOT)); + createRuntimeDirectories(context, config); // Get the full path to the properties file. if (propsFile == null) @@ -734,19 +741,23 @@ * Create any directories that might be needed during * runtime. Right now this includes: * - * i) directories for logging + * <ul> * - * @param path The directory to write log files to (relative to - * the web application root), or <code>null</code> for the default - * of <code>/logs</code>. + * <li>The directory to write the log files to (relative to the + * web application root), or <code>null</code> for the default of + * <code>/logs</code>. The directory is specified via the {@link + * TurbineConstants#LOGGING_ROOT} parameter.</li> + * + * </ul> + * + * @param context Global initialization parameters. + * @param config Initialization parameters specific to the Turbine + * servlet. */ - private static void createRuntimeDirectories(String path) + private static void createRuntimeDirectories(ServletContext context, + ServletConfig config) { - if (Strings.isEmpty(path)) - { - path = "/logs"; - } - + String path = findInitParameter(context, config, LOGGING_ROOT, "/logs"); File logDir = new File(getRealPath(path)); if (!logDir.exists()) { @@ -756,6 +767,49 @@ System.err.println("Cannot create directory for logs!"); } } + } + + /** + * Finds the specified servlet configuration/initialization + * parameter, looking first for a servlet-specific parameter, then + * for a global parameter, and using the provided default if not + * found. + */ + protected static final String findInitParameter(ServletContext context, + ServletConfig config, + String name, + String defaultValue) + { + String path = null; + + // Try the name as provided first. + boolean usingNamespace = name.startsWith(CONFIG_NAMESPACE); + while (true) + { + path = config.getInitParameter(name); + if (Strings.isEmpty(path)) + { + path = context.getInitParameter(name); + if (Strings.isEmpty(path)) + { + // The named parameter didn't yield a value. + if (usingNamespace) + { + path = defaultValue; + } + else + { + // Try again using Turbine's namespace. + name = CONFIG_NAMESPACE + '.' + name; + usingNamespace = true; + continue; + } + } + } + break; + } + + return path; } /**
-- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>