You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@turbine.apache.org by jt...@apache.org on 2002/05/18 20:09:04 UTC

cvs commit: jakarta-turbine-fulcrum/src/services/org/apache/fulcrum/velocity TurbineVelocityService.java

jtaylor     02/05/18 11:09:04

  Modified:    src/services/org/apache/fulcrum/velocity
                        TurbineVelocityService.java
  Log:
  TrubineVelocityService now uses a VelocityEngine instead of the Velocity
  singleton. This helps avoid configuration conflicts with other velocity
  stuff running in the same webapp (DVSL or instances of VelocityServlet
  for example).
  
  Revision  Changes    Path
  1.18      +22 -20    jakarta-turbine-fulcrum/src/services/org/apache/fulcrum/velocity/TurbineVelocityService.java
  
  Index: TurbineVelocityService.java
  ===================================================================
  RCS file: /home/cvs/jakarta-turbine-fulcrum/src/services/org/apache/fulcrum/velocity/TurbineVelocityService.java,v
  retrieving revision 1.17
  retrieving revision 1.18
  diff -u -r1.17 -r1.18
  --- TurbineVelocityService.java	15 May 2002 15:57:01 -0000	1.17
  +++ TurbineVelocityService.java	18 May 2002 18:09:04 -0000	1.18
  @@ -62,9 +62,8 @@
   import java.io.Writer;
   import java.io.OutputStreamWriter;
   import java.io.ByteArrayOutputStream;
  -import org.apache.velocity.Template;
   import org.apache.velocity.VelocityContext;
  -import org.apache.velocity.app.Velocity;
  +import org.apache.velocity.app.VelocityEngine;
   import org.apache.velocity.app.event.EventCartridge;
   import org.apache.velocity.app.event.ReferenceInsertionEventHandler;
   import org.apache.velocity.app.event.NullSetEventHandler;
  @@ -74,7 +73,6 @@
   import org.apache.velocity.exception.MethodInvocationException;
   import org.apache.fulcrum.ServiceException;
   import org.apache.fulcrum.InitializationException;
  -import org.apache.fulcrum.template.TurbineTemplate;
   import org.apache.fulcrum.template.TemplateContext;
   import org.apache.fulcrum.template.BaseTemplateEngineService;
   import org.apache.commons.configuration.ConfigurationConverter;
  @@ -101,7 +99,8 @@
    * @author <a href="mailto:dlr@finemaltcoding.com">Daniel Rall</a>
    * @author <a href="mailto:jon@latchkey.com">Jon S. Stevens</a>
    * @author <a href="mailto:mpoeschl@marmot.at">Martin Poeschl</a>
  - * @version $Id: TurbineVelocityService.java,v 1.17 2002/05/15 15:57:01 jtaylor Exp $
  + * @author <a href="mailto:james@jamestaylor.org">James Taylor</a>
  + * @version $Id: TurbineVelocityService.java,v 1.18 2002/05/18 18:09:04 jtaylor Exp $
    */
   public class TurbineVelocityService
       extends BaseTemplateEngineService
  @@ -140,6 +139,11 @@
       private boolean eventCartridgeEnabled = true;
   
       /**
  +     * The VelocityEngine used by the service to merge templates
  +     */
  +    private VelocityEngine velocityEngine = new VelocityEngine();
  +
  +    /**
        * Performs early initialization of this Turbine service.
        */
       public void init()
  @@ -249,8 +253,7 @@
       }
   
       /**
  -     * @see org.apache.fulcrum.template.TemplateEngineService#handleRequest(
  -     * Context, String, Writer)
  +     * @see BaseTemplateEngineService#handleRequest(TemplateContext, String, Writer)
        */
       public void handleRequest(TemplateContext context,
                                          String template, Writer writer)
  @@ -260,8 +263,7 @@
       }
   
       /**
  -     * @see org.apache.fulcrum.velocity.VelocityService#handleRequest(Context,
  -     * String, Writer)
  +     * @see VelocityService#handleRequest(Context, String, Writer)
        */
       public void handleRequest(Context context, String filename,
                                 Writer writer)
  @@ -271,8 +273,7 @@
       }
   
       /**
  -     * @see org.apache.fulcrum.velocity.VelocityService#handleRequest(Context,
  -     * String, Writer, String)
  +     * @see VelocityService#handleRequest(Context, String, Writer, String)
        */
       public void handleRequest(Context context, String filename,
                                 Writer writer, String encoding)
  @@ -307,12 +308,12 @@
               if (encoding != null)
               {
                   // Request scoped encoding first supported by Velocity 1.1.
  -                Velocity.mergeTemplate(filename, encoding,
  -                                       eventContext, writer);
  +                velocityEngine.mergeTemplate(filename, encoding,
  +                                             eventContext, writer);
               }
               else
               {
  -                Velocity.mergeTemplate(filename, eventContext, writer);
  +                velocityEngine.mergeTemplate(filename, eventContext, writer);
               }
           }
           catch (Exception e)
  @@ -347,7 +348,7 @@
        * @param context A context to use when evaluating the specified
        * template.
        * @param filename The file name of the template.
  -     * @param out The stream to which we will write the processed
  +     * @param output The stream to which we will write the processed
        * template as a String.
        * @return The character set applied to the resulting text.
        *
  @@ -494,11 +495,11 @@
           // Now we have to perform a couple of path translations
           // for our log file and template paths.
           String path = getRealPath(
  -            getConfiguration().getString(Velocity.RUNTIME_LOG, null));
  +            getConfiguration().getString(VelocityEngine.RUNTIME_LOG, null));
   
           if (path != null && path.length() > 0)
           {
  -            getConfiguration().setProperty(Velocity.RUNTIME_LOG, path);
  +            getConfiguration().setProperty(VelocityEngine.RUNTIME_LOG, path);
           }
           else
           {
  @@ -534,7 +535,7 @@
               paths = getConfiguration().getVector(key,null);
               if (paths != null)
               {
  -                Velocity.clearProperty(key);
  +                velocityEngine.clearProperty(key);
                   getConfiguration().clearProperty(key);
   
                   for (Iterator j = paths.iterator(); j.hasNext();)
  @@ -576,9 +577,10 @@
   
           try
           {
  -            Velocity.setExtendedProperties(ConfigurationConverter
  +            velocityEngine.setExtendedProperties(ConfigurationConverter
                       .getExtendedProperties(getConfiguration()));
  -            Velocity.init();
  +
  +            velocityEngine.init();
           }
           catch(Exception e)
           {
  @@ -600,6 +602,6 @@
        */
       public boolean templateExists(String template)
       {
  -        return Velocity.templateExists(template);
  +        return velocityEngine.templateExists(template);
       }
   }
  
  
  

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>