You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by Will Glass-Husain <wg...@forio.com> on 2004/03/19 01:34:10 UTC

input event handler

Gosh, time passes (when you're having fun... or something..)

You can read the original proposal/patch at:
http://nagoya.apache.org/bugzilla/show_bug.cgi?id=20342

Essentially, this patch works like all the other event handlers.  It's
called when a user executes #parse or #include.  The event handler can
substitute one resource for another, or can block the include entirely.
I've been using it in production code since last summer to prevent templates
within a user account directory from including files from other user
directories (this is important since individual users have the ability to
upload templates).  CloD is interested in making #parse and #include operate
relative to the current directory.  As CloD noted, localization and error
handling are two other possible use cases.

Along with this patch, I'd like to suggest we add
-- ability to choose an event handler at runtime via velocity.properties
(this would apply to all the event handlers)
-- several sample event handlers in Velocity providing commonly requested
capabilities (e.g. for relative resource loading)

What do people think of including this type of event handler?  Any
additional comments or requested capabilities?  Geir, were there other
issues you remember?  If there's consensus, we can get it committed.

Cheers,

WILL

P.S.  The new event handler interface looks like this:

    /**
     * Called when an input directive is encountered.  May modify the path
of the
     * resource to be input, may block the input entirely.  The contents of
     * the context may be retrieved to aid the logic.  Changes to the
context
     * may be made (with caution) as they will apply in the input resource,
and on the
     * current resource from the input directive downwards.
     *
     * @param inputResourcePath the path as given in the input directive.
     * @param currentResourcePath the path of the template that includes the
input directive.
     * @param context the Velocity context containing the references to be
merged with the template.
     * @param parse true if the input template will be parsed.
     *
     * @return a new resource path for the directive, or null to block the
input from occurring.
     */
    public String inputEvent( String inputResourcePath, String
currentResourcePath, Context context, boolean parse );





----- Original Message ----- 
From: "Geir Magnusson Jr" <ge...@4quarters.com>
To: "Velocity Users List" <ve...@jakarta.apache.org>
Sent: Thursday, March 18, 2004 12:21 PM
Subject: Re: catching #parse errors


>
> Since you now seem to have a victim^H^H^H^Huser, lets bash it out now.
>


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