Return-Path: Delivered-To: apmail-jakarta-tomcat-dev-archive@www.apache.org Received: (qmail 92145 invoked from network); 16 Mar 2005 11:37:52 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur-2.apache.org with SMTP; 16 Mar 2005 11:37:51 -0000 Received: (qmail 36761 invoked by uid 500); 16 Mar 2005 11:37:47 -0000 Delivered-To: apmail-jakarta-tomcat-dev-archive@jakarta.apache.org Received: (qmail 36095 invoked by uid 500); 16 Mar 2005 11:37:45 -0000 Mailing-List: contact tomcat-dev-help@jakarta.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Subscribe: List-Help: List-Post: List-Id: "Tomcat Developers List" Reply-To: "Tomcat Developers List" Delivered-To: mailing list tomcat-dev@jakarta.apache.org Received: (qmail 36080 invoked by uid 500); 16 Mar 2005 11:37:45 -0000 Received: (qmail 36077 invoked by uid 99); 16 Mar 2005 11:37:45 -0000 X-ASF-Spam-Status: No, hits=-9.8 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received: from minotaur.apache.org (HELO minotaur.apache.org) (209.237.227.194) by apache.org (qpsmtpd/0.28) with SMTP; Wed, 16 Mar 2005 03:37:45 -0800 Received: (qmail 92031 invoked by uid 1135); 16 Mar 2005 11:37:44 -0000 Date: 16 Mar 2005 11:37:44 -0000 Message-ID: <20050316113744.92030.qmail@minotaur.apache.org> From: remm@apache.org To: jakarta-tomcat-catalina-cvs@apache.org Subject: cvs commit: jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/startup ContextConfig.java X-Virus-Checked: Checked X-Spam-Rating: minotaur-2.apache.org 1.6.2 0/1000/N remm 2005/03/16 03:37:44 Modified: catalina/src/share/org/apache/catalina/startup ContextConfig.java Log: - Harmonize processing of the context.xml defaults with the way web.xml is processed. Revision Changes Path 1.64 +65 -23 jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/startup/ContextConfig.java Index: ContextConfig.java =================================================================== RCS file: /home/cvs/jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/startup/ContextConfig.java,v retrieving revision 1.63 retrieving revision 1.64 diff -u -r1.63 -r1.64 --- ContextConfig.java 15 Mar 2005 13:06:30 -0000 1.63 +++ ContextConfig.java 16 Mar 2005 11:37:43 -0000 1.64 @@ -618,19 +618,29 @@ stream = null; source = null; - file = new File(getConfigBase(), Constants.HostWebXml); + String resourceName = getHostConfigPath(Constants.HostWebXml); + file = new File(getConfigBase(), resourceName); try { - if (file.exists()) { + if ( ! file.exists() ) { + // Use getResource and getResourceAsStream + stream = getClass().getClassLoader() + .getResourceAsStream(resourceName); + if( stream != null ) { + source = new InputSource + (getClass().getClassLoader() + .getResource(resourceName).toString()); + } + } else { source = new InputSource("file://" + file.getAbsolutePath()); stream = new FileInputStream(file); } } catch (Exception e) { log.error(sm.getString("contextConfig.defaultMissing") - + " " + file , e); + + " " + resourceName + " " + file , e); } - + if (stream != null) { processDefaultWebConfig(webDigester, stream, source); webRuleSet.recycle(); @@ -644,6 +654,11 @@ */ protected void processDefaultWebConfig(Digester digester, InputStream stream, InputSource source) { + + if (log.isDebugEnabled()) + log.debug("Processing context [" + context.getName() + + "] web configuration resource " + source.getSystemId()); + // Process the default web.xml file synchronized (digester) { try { @@ -696,11 +711,11 @@ if( defaultContextXml==null ) getDefaultContextXml(); if (!context.getOverride()) { - processContextConfig(new File(getBaseDir(), defaultContextXml)); - processContextConfig(new File(getConfigBase(), Constants.HostContextXml)); + processContextConfig(new File(getBaseDir()), defaultContextXml); + processContextConfig(getConfigBase(), getHostConfigPath(Constants.HostContextXml)); } if (context.getConfigFile() != null) - processContextConfig(new File(context.getConfigFile())); + processContextConfig(new File(context.getConfigFile()), null); } @@ -708,28 +723,45 @@ /** * Process a context.xml. */ - protected void processContextConfig(File file) { + protected void processContextConfig(File baseDir, String resourceName) { if (log.isDebugEnabled()) - log.debug("Processing context [" + context.getName() + "] configuration file " + file); - - // Add as watched resource so that cascade reload occurs if a default - // config file is modified/added/removed - context.addWatchedResource(file.getAbsolutePath()); + log.debug("Processing context [" + context.getName() + + "] configuration file " + baseDir + " " + resourceName); InputSource source = null; InputStream stream = null; + + File file = baseDir; + if (resourceName != null) { + file = new File(baseDir, resourceName); + } + try { - if (file.exists()) { - stream = new FileInputStream(file); + if ( !file.exists() ) { + if (resourceName != null) { + // Use getResource and getResourceAsStream + stream = getClass().getClassLoader() + .getResourceAsStream(resourceName); + if( stream != null ) { + source = new InputSource + (getClass().getClassLoader() + .getResource(resourceName).toString()); + } + } + } else { source = new InputSource("file://" + file.getAbsolutePath()); - } else if (log.isDebugEnabled()) { - log.debug("Context [" + context.getName() + "] configuration file " + file + " not found"); + stream = new FileInputStream(file); + // Add as watched resource so that cascade reload occurs if a default + // config file is modified/added/removed + context.addWatchedResource(file.getAbsolutePath()); } } catch (Exception e) { - log.error(sm.getString("contextConfig.defaultMissing") + file); + log.error(sm.getString("contextConfig.defaultMissing") + + " " + resourceName + " " + file , e); } + if (source == null) return; if (contextDigester == null){ @@ -747,6 +779,9 @@ if (parseException != null) { ok = false; } + if (log.isDebugEnabled()) + log.debug("Successfully processed context [" + context.getName() + + "] configuration file " + baseDir + " " + resourceName); } catch (SAXParseException e) { log.error(sm.getString("contextConfig.defaultParse"), e); log.error(sm.getString("contextConfig.defaultPosition", @@ -1263,7 +1298,14 @@ new File(System.getProperty("catalina.base"), "conf"); if (!configBase.exists()) { return null; + } else { + return configBase; } + } + + + protected String getHostConfigPath(String resourceName) { + StringBuffer result = new StringBuffer(); Container container = context; Container host = null; Container engine = null; @@ -1275,13 +1317,13 @@ container = container.getParent(); } if (engine != null) { - configBase = new File(configBase, engine.getName()); + result.append(engine.getName()).append('/'); } if (host != null) { - configBase = new File(configBase, host.getName()); + result.append(host.getName()).append('/'); } - configBase.mkdirs(); - return configBase; + result.append(resourceName); + return result.toString(); } --------------------------------------------------------------------- To unsubscribe, e-mail: tomcat-dev-unsubscribe@jakarta.apache.org For additional commands, e-mail: tomcat-dev-help@jakarta.apache.org