This morning I came accross an error with Caucho and Velocity in which I could not 
find any template files in my .war file.

I was storing my template files in:
  resin-2.0.1\webapps\myapp

I was storing my servlets class files in:
  resin-2.0.1\webapps\myapp\web-inf\classes

I was storing my library files (including velocity) in:
  resin-2.0.1\webapps\myapp\web-inf\lib

After about an decent amount of time moving the template files around Resin, and 
tinkering with
my code it occured to me to modify the velocity base code. Accordingly I went into the
VelocityServlet class and changed the init method, and added a setProperty, which 
changed the
base path.  This seemed to correct the issue.  Are there any implications to this for 
other
servlet engines?  I realize that this bug technically is more of an issue with Caucho, 
however
since I don't think they will be changing their code any time soon (and I'm not about 
to tinker
with the inner workings of their servlet engine for a 3 line fix), it might be nice if 
you guys
included this change, or something like it in future versions.


The fix is below:


    public void init( ServletConfig config )
        throws ServletException
    {
        super.init( config );
                
        try
        {
            /*
             *  call the overridable method to allow the 
             *  derived classes a shot at altering the configuration
             *  before initializing Runtime
             */

            Properties props = loadConfiguration( config );

            //Code correction for Caucho added here
            //<Fix>
  
            String path = getServletContext().getRealPath("\\");

            if(path != null)
            {
             props.setProperty(Velocity.FILE_RESOURCE_LOADER_PATH, path);             
            };

            //</Fix>

            
            Velocity.init(props);            
             
            defaultContentType = RuntimeSingleton.getString( CONTENT_TYPE, 
DEFAULT_CONTENT_TYPE);
            
            encoding = RuntimeSingleton.getString( RuntimeSingleton.OUTPUT_ENCODING, 
DEFAULT_OUTPUT_ENCODING);
        }
        catch( Exception e )
        {
            throw new ServletException("Error configuring the loader: " + e);
        }
    }

Reply via email to