You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@velocity.apache.org by nb...@apache.org on 2004/11/11 05:08:16 UTC

cvs commit: jakarta-velocity-tools/src/java/org/apache/velocity/tools/view/context ChainedContext.java

nbubna      2004/11/10 20:08:16

  Modified:    src/java/org/apache/velocity/tools/view/context
                        ChainedContext.java
  Log:
  wean off of deprecated ToolboxContext and begin supporting VelocityEngine use
  
  Revision  Changes    Path
  1.8       +51 -8     jakarta-velocity-tools/src/java/org/apache/velocity/tools/view/context/ChainedContext.java
  
  Index: ChainedContext.java
  ===================================================================
  RCS file: /home/cvs/jakarta-velocity-tools/src/java/org/apache/velocity/tools/view/context/ChainedContext.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- ChainedContext.java	15 Apr 2004 20:25:34 -0000	1.7
  +++ ChainedContext.java	11 Nov 2004 04:08:16 -0000	1.8
  @@ -1,5 +1,5 @@
   /*
  - * Copyright 2002-2003 The Apache Software Foundation.
  + * Copyright 2002-2004 The Apache Software Foundation.
    *
    * Licensed under the Apache License, Version 2.0 (the "License");
    * you may not use this file except in compliance with the License.
  @@ -16,7 +16,7 @@
   
   package org.apache.velocity.tools.view.context;
   
  -import java.util.HashMap;
  +import java.util.Map;
   
   import javax.servlet.http.HttpServletRequest;
   import javax.servlet.http.HttpServletResponse;
  @@ -24,6 +24,7 @@
   import javax.servlet.ServletContext;
   
   import org.apache.velocity.VelocityContext;
  +import org.apache.velocity.app.VelocityEngine;
   import org.apache.velocity.context.Context;
   
   /**
  @@ -66,7 +67,7 @@
   {
   
       /* the current toolbox, request, response, and session */
  -    private ToolboxContext toolboxContext;
  +    private Map toolbox;
       private HttpServletRequest request;
       private HttpServletResponse response;
       private HttpSession session;
  @@ -74,14 +75,39 @@
       /* the servlet context */
       private ServletContext application;
   
  +    /* the velocity engine being used */
  +    private VelocityEngine velocity;
   
  +
  +    /**
  +     * @deprecated
  +     */
       public ChainedContext(Context ctx,
                             HttpServletRequest request,
                             HttpServletResponse response,
                             ServletContext application)
       {
  +        this(ctx, null, request, response, application);
  +    }
  +
  +
  +    public ChainedContext(VelocityEngine velocity,
  +                          HttpServletRequest request,
  +                          HttpServletResponse response,
  +                          ServletContext application)
  +    {
  +        this(null, velocity, request, response, application);
  +    }
  +    
  +    public ChainedContext(Context ctx,
  +                          VelocityEngine velocity,
  +                          HttpServletRequest request,
  +                          HttpServletResponse response,
  +                          ServletContext application)
  +    {
           super(null, ctx);
   
  +        this.velocity = velocity;
           this.request = request;
           this.response = response;
           this.session = request.getSession(false);
  @@ -90,13 +116,22 @@
   
   
       /**
  +     * @deprecated Use setToolbox(Map) instead.
  +     */
  +    public void setToolbox(ToolboxContext box)
  +    {
  +        setToolbox(box.getToolbox());
  +    }
  +
  +
  +    /**
        * <p>Sets the toolbox of view tools.</p>
        *
        * @param box toolbox of view tools
        */
  -    public void setToolbox(ToolboxContext box)
  +    public void setToolbox(Map box)
       {
  -        this.toolboxContext = box;
  +        this.toolbox = box;
           /* just in case the servlet toolbox manager
            * had to create a new session to hold session tools
            * let's make sure this context's session ref is current */
  @@ -116,9 +151,9 @@
           Object o = null;
   
           /* search the toolbox */
  -        if (toolboxContext != null)
  +        if (toolbox != null)
           {
  -            o = toolboxContext.get(key);
  +            o = toolbox.get(key);
               if (o != null)
               {
                   return o;
  @@ -211,6 +246,14 @@
       public Context getVelocityContext()
       {
           return this;
  +    }
  +
  +    /**
  +     * <p>Returns a reference to the VelocityEngine.</p>
  +     */
  +    public VelocityEngine getVelocityEngine()
  +    {
  +        return velocity;
       }
   
   }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-dev-help@jakarta.apache.org