tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From r...@apache.org
Subject cvs commit: jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/startup ContextConfig.java
Date Wed, 16 Mar 2005 11:37:44 GMT
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


Mime
View raw message