You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by "Geir Magnusson Jr." <ge...@optonline.net> on 2002/02/15 20:58:35 UTC
Re: Treating unresolved references
On 2/15/02 2:45 PM, "Ajay Gondhiya" <aj...@dset.com> wrote:
> I use Velocity helper class from an application to evaluate
> a template that I store in database. So I use Velocity.evaluate().
You can also use the DataSourceResourceLoader. Sylwester just did some
improvements to it and the docs. Take a look.
>
> According to the limited understanding that I have developed
> about velocity in a few days, if a property reference (e.g.
> $propertyName)
> in a template does not exist in the velocity context, velocity renders
> it as
> $propertyName. To use the quiet reference, one can change the refernce
> to $!propertyName and if the property does not exist, no output will
> be rendered.
Yep
> What I need in my application is to treat such unresolved references as
> errors. Is this possible ? If yes, how ?
You might simply do is make a custom logger a look for the messages.
What we could do (after 1.3) is add a null reference event.
> On a similar note, I do not understand the conditions in which
> Velocity.evaluate() would not throw exception but return "false".
> I tried checking if Velocity.evaluate() would return "false" in case
> of any unresolved reference but that is not the case. It returns "true".
That might be a carryover, and we should fix that. Depend on the exceptions
--
Geir Magnusson Jr. geirm@optonline.net
System and Software Consulting
Be a giant. Take giant steps. Do giant things...
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>
Re: Treating unresolved references
Posted by "Geir Magnusson Jr." <ge...@optonline.net>.
On 2/15/02 5:40 PM, "Bill Burton" <bi...@progress.com> wrote:
> Hello,
>
> "Geir Magnusson Jr." wrote:
>>
>> What we could do (after 1.3) is add a null reference event.
>
> In the event_example, the class implements a referenceInsert method of the
> ReferenceInsertionEventHandler interface. Doesn't that already allow
> detecting null references?
Yes, actually it does, since we pass in the value no matter what, null or
not.
So you could catch it there, and just return a "" for prod, or null when
debugging.
>
> A more general solution might be to generate an event for anything that
> would be logged. This could still use an interface similar to LogSystem
> but maybe called LogEvent. The logVelocityMessage method could return a
> boolean like the shouldLogOnNullSet method so any message could be
> dropped.
Yes maybe, although having the logging always go out is not a bad thing.
Not maybe a great thing, but not bad.
This is a slightly different thing than the above, squelching the
$<reference> in the output.
Using a rolling log appender or such from log4j means you don't ever have to
worry about big log files...
>
> It would be really nice however this is implemented to have a new or
> modified servlet example that shows capturing these unresolved reference
> events and displaying them at the bottom of the page. This could be very
> helpful in a development environment.
Sure - that might be fun to do....
--
Geir Magnusson Jr. geirm@optonline.net
System and Software Consulting
Java : the speed of Smalltalk with the simple elegance of C++...
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>
Re: Treating unresolved references
Posted by Bill Burton <bi...@progress.com>.
Hello,
"Geir Magnusson Jr." wrote:
>
> On 2/15/02 2:45 PM, "Ajay Gondhiya" <aj...@dset.com> wrote:
> > What I need in my application is to treat such unresolved references as
> > errors. Is this possible ? If yes, how ?
>
> You might simply do is make a custom logger a look for the messages.
In writing a patch for improved logging support in the DVSL Task, I
encountered some issues like this. Unfortunately, neither the logging
example or the Developer's guide shows how to do capturing based on the
logging level. For an example of that, see the source to
o.a.v.runtime.log.AvalonLogsystem.
Unresolved references generate messages at the warning level. So if you
capture all warnings and errors it should be close to what you want.
Hovever, there is only one instance of a logger per VelocityEngine
instance. If you're running this as a standalone application, that
shouldn't be a problem. However, if you're running in a servlet
environment, messages from all requests go to the same LogSystem instance
so without some fancy footwork, you can't get access to the messages
generated just for your request.
>
> What we could do (after 1.3) is add a null reference event.
In the event_example, the class implements a referenceInsert method of the
ReferenceInsertionEventHandler interface. Doesn't that already allow
detecting null references?
A more general solution might be to generate an event for anything that
would be logged. This could still use an interface similar to LogSystem
but maybe called LogEvent. The logVelocityMessage method could return a
boolean like the shouldLogOnNullSet method so any message could be
dropped.
It would be really nice however this is implemented to have a new or
modified servlet example that shows capturing these unresolved reference
events and displaying them at the bottom of the page. This could be very
helpful in a development environment.
-Bill
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>
Re: Treating unresolved references
Posted by Ajay Gondhiya <aj...@dset.com>.
"Geir Magnusson Jr." wrote:
> On 2/15/02 2:45 PM, "Ajay Gondhiya" <aj...@dset.com> wrote:
>
> > I use Velocity helper class from an application to evaluate
> > a template that I store in database. So I use Velocity.evaluate().
>
> You can also use the DataSourceResourceLoader. Sylwester just did some
> improvements to it and the docs. Take a look.
I didn't mention in my previous mail but I do use DataSourceResourceLoader.
I will write a separate e-mail about a question I have about ResourceLoader.
>
>
> >
> > According to the limited understanding that I have developed
> > about velocity in a few days, if a property reference (e.g.
> > $propertyName)
> > in a template does not exist in the velocity context, velocity renders
> > it as
> > $propertyName. To use the quiet reference, one can change the refernce
> > to $!propertyName and if the property does not exist, no output will
> > be rendered.
>
> Yep
>
> > What I need in my application is to treat such unresolved references as
> > errors. Is this possible ? If yes, how ?
>
> You might simply do is make a custom logger a look for the messages.
>
>
>
> What we could do (after 1.3) is add a null reference event.
that would be good.
>
>
> > On a similar note, I do not understand the conditions in which
> > Velocity.evaluate() would not throw exception but return "false".
> > I tried checking if Velocity.evaluate() would return "false" in case
> > of any unresolved reference but that is not the case. It returns "true".
>
> That might be a carryover, and we should fix that. Depend on the exceptions
>
> --
> Geir Magnusson Jr. geirm@optonline.net
> System and Software Consulting
> Be a giant. Take giant steps. Do giant things...
>
> --
> To unsubscribe, e-mail: <ma...@jakarta.apache.org>
> For additional commands, e-mail: <ma...@jakarta.apache.org>
--
Ajay Gondhiya
DSET Corporation
(908)526-7500 ext-1306
ajay@dset.com
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>