velocity-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Dmitri Colebatch" <...@colebatch.com>
Subject velocity-tools -> multiple instances of VelocityViewServlet, was: Simple Startup Question
Date Thu, 08 May 2003 21:28:41 GMT
Hi,

since this thread has wandered onto this topic, I have a question:

[snip]

> velocity-tools project.  so, if you plan to use Velocity for
> developing web applications, i *strongly* suggest checking out either
> velocity-tools (works great w/Struts!) or a web framework that offers
> built-in Velocity support (Turbine, WebWork, JPublish, etc.)

I'm using velocity-tools, and have tried to have two instances of
VelocityViewServlet, mainly to set the mime-time for a particular request.
Anyway, I found that the tools didn't seem to be included for requestes
going through the second instance - I've searched through the code for a
reason, but found none.  I've made sure that the init method is called, and
the init-params are set...  couldn't think of anything else.

at this stage I've got a workaround (just have one subclass and customize it
there), but I'm still confused by this behaviour.  Any suggestions?

On a second point, I found a need for a CookieTool, and coded up a quick
one - would this be welcomed as a patch?  Its very simple (see end of this
email).

cheers
dim

package org.apache.velocity.tools.view.tools;

import org.apache.velocity.tools.view.context.ViewContext;

import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.Cookie;

public class CookieTool implements ViewTool
{
  /**
   * A reference to the ServletContext
   */
  protected ServletContext application;

  /**
   * A reference to the HttpServletRequest.
   */
  protected HttpServletRequest request;

  /**
   * A reference to the HttpServletResponse.
   */
  protected HttpServletResponse response;

  public void init(Object obj)
  {
    if (!(obj instanceof ViewContext))
    {
      throw new IllegalArgumentException("Tool can only be initialized with
a ViewContext");
    }

    ViewContext context = (ViewContext) obj;
    this.request = context.getRequest();
    this.response = context.getResponse();
    this.application = context.getServletContext();
  }

  public String get(String name)
  {
    final Cookie[] cookies = request.getCookies();
    if (cookies == null)
      return null;

    for (int i = 0; i < cookies.length; i++)
    {
      Cookie cookie = cookies[i];
      if (cookie.getName().equals(name))
      {
        return cookie.getValue();
      }
    }
    return null;
  }
}


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


Mime
View raw message