You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by Ja...@cox.com on 2004/11/17 15:26:25 UTC

Include directive behavior

Aye, here's the rub:
If I have the following in my application's config file:
directive.include.output.errormsg.start = ***ERROR:
directive.include.output.errormsg.end = *****

I load those properties into Velocity when initializing, my
understanding is that any errors with the arguments for the Include
directive should be written to the output stream.
However, this is not occurring in cases where the argument references a
file that does not exist.  Instead a ResourceNotFoundException is
thrown, whether you define the start and end properties or not.
This could be by design, but I wanted to make sure.

I'm using velocity 1.3.1 but 1.4 does the same.

In Include.java, the render() function makes a call to renderOutput().
If renderOutput() returns false, then render() calls
outputErrorToStream().
However, renderOutput() will throw a ResourceNotFoundException if the
Included file does not exist (the exception is caught in renderOutput,
but thrown again).
This exception is not handled by render(), and so the exception gets
passed up the call stack without outputErrorToStream() ever being
called.

So my first question is:  is this a bug, or is there a reason to not
allow writing an error to the output stream in this case?

Question 2:  I can modify the Include directive, but is there a way to
configure Velocity at runtime to use the custom directive, so that I can
continue using an unmodified velocity jar?
I'm using setProperty() to override velocity.properties with values that
are in my application's config, but I can't see a way to do that to
override what's in directive.properties.

Thanks,
Jason


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


Re: Include directive behavior

Posted by Shinobu Kawai <sh...@gmail.com>.
Hi Jason,

> However, renderOutput() will throw a ResourceNotFoundException if the
> Included file does not exist (the exception is caught in renderOutput,
> but thrown again).
> This exception is not handled by render(), and so the exception gets
> passed up the call stack without outputErrorToStream() ever being
> called.
> 
> So my first question is:  is this a bug, or is there a reason to not
> allow writing an error to the output stream in this case?
I don't know about this.  Maybe it should be discussed in the developer list.
## Or you can just file an issue and see what happens.  B)

> Question 2:  I can modify the Include directive, but is there a way to
> configure Velocity at runtime to use the custom directive, so that I can
> continue using an unmodified velocity jar?
> I'm using setProperty() to override velocity.properties with values that
> are in my application's config, but I can't see a way to do that to
> override what's in directive.properties.
Try userdirective.
  http://jakarta.apache.org/velocity/developer-guide.html#FAQ3

Best regards,
-- Shinobu Kawai

-- 
Shinobu Kawai <sh...@gmail.com>

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