jvanzyl     00/10/26 12:37:17

  Modified:    src/java/org/apache/velocity/runtime Runtime.java
  Log:
  - fix the URL problem with the logging system. everything seems
    to be working well now.
  
  Revision  Changes    Path
  1.27      +41 -7     
jakarta-velocity/src/java/org/apache/velocity/runtime/Runtime.java
  
  Index: Runtime.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-velocity/src/java/org/apache/velocity/runtime/Runtime.java,v
  retrieving revision 1.26
  retrieving revision 1.27
  diff -u -r1.26 -r1.27
  --- Runtime.java      2000/10/23 18:27:48     1.26
  +++ Runtime.java      2000/10/26 19:37:16     1.27
  @@ -58,6 +58,7 @@
   import java.io.File;
   import java.io.FileInputStream;
   import java.io.IOException;
  +import java.net.URL;
   import java.net.MalformedURLException;
   import java.util.Hashtable;
   import java.util.Properties;
  @@ -82,6 +83,8 @@
   import org.apache.velocity.runtime.directive.Foreach;
   import org.apache.velocity.runtime.directive.Dummy;
   
  +import org.apache.velocity.runtime.log.Log;
  +
   /**
    * This is the Runtime system for Velocity. It is the
    * single access point for all functionality in Velocity.
  @@ -139,7 +142,7 @@
    *
    * @author <a href="mailto:[EMAIL PROTECTED]">Jason van Zyl</a>
    * @author <a href="mailto:[EMAIL PROTECTED]">Jeff Bowden</a>
  - * @version $Id: Runtime.java,v 1.26 2000/10/23 18:27:48 jvanzyl Exp $
  + * @version $Id: Runtime.java,v 1.27 2000/10/26 19:37:16 jvanzyl Exp $
    */
   public class Runtime
   {
  @@ -198,7 +201,7 @@
   
       /** The Runtime logger */
       private static Logger logger;
  -    
  +
       /** 
         * The Runtime parser. This has to be changed to
         * a pool of parsers!
  @@ -332,13 +335,10 @@
               // correct it if it is not a property 
               // fomratted URL.
               String logFile = getString(RUNTIME_LOG);
  -            
  -            if (! logFile.startsWith("file"))
  -                logFile = "file://" + logFile;
  -            
  +
               // Initialize the logger.
               logger = LogKit.createLogger("velocity", 
  -                getString(RUNTIME_LOG), "DEBUG");
  +                fileToURL(logFile), "DEBUG");
                   
               LogTarget[] t = logger.getLogTargets();            
   
  @@ -352,10 +352,39 @@
               {
                   logger.info(pendingMessages.toString());
               }
  +            
  +            Runtime.info("Log file being used is: " + logFile);
           }
       }
   
       /**
  +     * This was borrowed form xml-fop. Convert a file
  +     * name into a string that represents a well-formed
  +     * URL.
  +     *
  +     * d:\path\to\logfile
  +     * file://d:/path/to/logfile
  +     *
  +     * NOTE: this is a total hack-a-roo! This should
  +     * be dealt with in the org.apache.log package. Client
  +     * packages should not have to mess around making
  +     * properly formed URLs when log files are almost
  +     * always going to be specified with file paths!
  +     */
  +    private static String fileToURL(String filename)
  +        throws MalformedURLException
  +    {
  +        File file = new File(filename);
  +        String path = file.getAbsolutePath();
  +        String fSep = System.getProperty("file.separator");
  +        
  +        if (fSep != null && fSep.length() == 1)
  +            path = "file://" + path.replace(fSep.charAt(0), '/');
  +        
  +        return path;
  +    }
  +
  +    /**
        * Initialize the template loader if there
        * is a real path set for the template.path
        * property. Otherwise defer initialization
  @@ -472,5 +501,10 @@
       {
           if (DEBUG_ON)
               log(DEBUG + message.toString());
  +    }
  +
  +    public static void main(String[] args) throws Exception
  +    {
  +        System.out.println(fileToURL(args[0]));
       }
   }
  
  
  

Reply via email to