geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jdil...@apache.org
Subject cvs commit: incubator-geronimo/modules/common/src/java/org/apache/geronimo/common/log/log4j URLConfigurator.java
Date Fri, 29 Aug 2003 20:33:00 GMT
jdillon     2003/08/29 13:33:00

  Modified:    modules/common/src/java/org/apache/geronimo/common/log/log4j
                        URLConfigurator.java
  Log:
   o Added explicit checks for .properties and <?xml in file headers
  
  Revision  Changes    Path
  1.2       +35 -15    incubator-geronimo/modules/common/src/java/org/apache/geronimo/common/log/log4j/URLConfigurator.java
  
  Index: URLConfigurator.java
  ===================================================================
  RCS file: /home/cvs/incubator-geronimo/modules/common/src/java/org/apache/geronimo/common/log/log4j/URLConfigurator.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- URLConfigurator.java	29 Aug 2003 20:08:45 -0000	1.1
  +++ URLConfigurator.java	29 Aug 2003 20:33:00 -0000	1.2
  @@ -57,6 +57,8 @@
   package org.apache.geronimo.common.log.log4j;
   
   import java.io.IOException;
  +import java.io.InputStreamReader;
  +import java.io.BufferedReader;
   
   import java.net.URL;
   import java.net.URLConnection;
  @@ -87,13 +89,14 @@
           new URLConfigurator().doConfigure(url, LogManager.getLoggerRepository());
       }
       
  -    private boolean isContentXML(final URL url)
  +    private Configurator getConfigurator(final URL url)
       {
           String contentType = null;
           
           // Get the content type to see if it is XML or not
  +        URLConnection connection = null;
           try {
  -            URLConnection connection = url.openConnection();
  +            connection = url.openConnection();
               contentType = connection.getContentType();
               if (log.isTraceEnabled()) {
                   log.trace("Content type: " + contentType);
  @@ -102,24 +105,41 @@
           catch (IOException e) {
               log.warn("Could not determine content type from URL; ignoring", e);
           }
  -        
           if (contentType != null) {
  -            return contentType.toLowerCase().endsWith("/xml");
  +            if (contentType.toLowerCase().endsWith("/xml")) {
  +                return new DOMConfigurator();
  +            }
           }
           
  -        return url.getFile().toLowerCase().endsWith(".xml");
  -        
  -        //
  -        // TODO: Add check for <?xml in content
  -        //
  -    }
  -    
  -    private Configurator getConfigurator(final URL url)
  -    {
  -        if (isContentXML(url)) {
  +        // Check thr file name
  +        String filename = url.getFile().toLowerCase();
  +        if (filename.endsWith(".xml")) {
               return new DOMConfigurator();
           }
  +        else if (filename.endsWith(".properties")) {
  +            return new PropertyConfigurator();
  +        }
  +        
  +        // Check for <?xml in content
  +        if (connection != null) {
  +            try {
  +                BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
  +                try {
  +                    String head = reader.readLine();
  +                    if (head.startsWith("<?xml")) {
  +                        return new DOMConfigurator();
  +                    }
  +                }
  +                finally {
  +                    reader.close();
  +                }
  +            }
  +            catch (IOException e) {
  +                log.warn("Failed to check content header; ignoring", e);
  +            }
  +        }
           
  +        log.warn("Unable to determine content type, using property configurator");
           return new PropertyConfigurator();
       }
       
  
  
  

Mime
View raw message