You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@velocity.apache.org by Daniel Burke <da...@propylon.com> on 2005/11/18 16:27:36 UTC

Undefined Reference:- raise exception?

Hi,
Is it possible to configure velocity to raise an exception if a variable
is reference which is undefined at the parsing stage? I know you use quiet
syntax to not output the variable name but I want to stop parsing the
message.
cheers
Dan


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


Re: Undefined Reference:- raise exception?

Posted by Daniel Burke <da...@propylon.com>.
Sorry, merging. I had a look at that however I don't think that will
address my issue. I want to throw an Exception if the value is null.
However the interface method
ReferenceInsertionEventHandler.referenceInsert is not defined as throwing
an exception. I think at this stage I'm stuck. Anyone got any suggestions?
thanks
Dan
> parsing?  do you mean the merging stage?  there's no context at the
> parsing stage.  and if the latter, then yes, that should be doable.
> look in the developer's guide for the ReferenceInsertionEventHandler.
>
> On 11/18/05, Daniel Burke <da...@propylon.com> wrote:
>> Hi,
>> Is it possible to configure velocity to raise an exception if a variable
>> is reference which is undefined at the parsing stage? I know you use
>> quiet
>> syntax to not output the variable name but I want to stop parsing the
>> message.
>> cheers
>> Dan
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: velocity-dev-unsubscribe@jakarta.apache.org
>> For additional commands, e-mail: velocity-dev-help@jakarta.apache.org
>>
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: velocity-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: velocity-dev-help@jakarta.apache.org
>
>



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


Re: Undefined Reference:- raise exception?

Posted by Nathan Bubna <nb...@gmail.com>.
parsing?  do you mean the merging stage?  there's no context at the
parsing stage.  and if the latter, then yes, that should be doable. 
look in the developer's guide for the ReferenceInsertionEventHandler.

On 11/18/05, Daniel Burke <da...@propylon.com> wrote:
> Hi,
> Is it possible to configure velocity to raise an exception if a variable
> is reference which is undefined at the parsing stage? I know you use quiet
> syntax to not output the variable name but I want to stop parsing the
> message.
> cheers
> Dan
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: velocity-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: velocity-dev-help@jakarta.apache.org
>
>

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


Re: Undefined Reference:- raise exception?

Posted by Will Glass-Husain <wg...@forio.com>.
But in the uberspect you don't have access to the full reference string. 
Seems less useful.

Maybe there's a different way.  We could make a new event handler to be 
called upon invalid references.  (as opposed to null references).

Of course, this isn't a one versus other.  The uberspect approach still 
works.  (although it isn't being called with null objects -- we should fix 
that).
It's easier now that you can have an exception extend 
VelocityRuntimeException instead of error.

WILL

----- Original Message ----- 
From: "Llewellyn Falco" <is...@setgame.com>
To: "Velocity Developers List" <ve...@jakarta.apache.org>
Sent: Friday, November 18, 2005 5:01 PM
Subject: Re: Undefined Reference:- raise exception?


>I am still very concerned as to what falls as a bad reference, especially 
>as nulls are concerned.
>
> $a.b().c().d().e($f.g())
> should not be a bad reference if e or g returned null,
> it should be if a,b,c,d, or f did.
>
> you can NOT make it so #if($common.isNull($order.getBuyer())) N/A #else 
> $order.getBuyer().getName() #end
> will not work.
>
> likewise if an exception is thrown, it is much more useful to get
> null.d()
>
> than
> $a.b().c().d().e($f.g())
> had a null.
>
> again, this belongs in the uberspect.
>
>    llewellyn.
>
>
> ----- Original Message ----- 
> From: "Will Glass-Husain" <wg...@forio.com>
> To: "Velocity Developers List" <ve...@jakarta.apache.org>
> Sent: Friday, November 18, 2005 3:36 PM
> Subject: Re: Undefined Reference:- raise exception?
>
>
>> Hi,
>>
>> I've coded an event handler (InvalidReferenceHandler) that implements 
>> this. It's in a patch file at
>> http://issues.apache.org/jira/browse/VELOCITY-423
>>
>> It can be configured to either parse the whole page and collect a list of 
>> invalid resources, or to throw a runtime exception upon encountering the 
>> first one.
>>
>> Warning: this is subject to change.  But feel free to take a look at it. 
>> In a day or two I'll add it to the main source tree.  If anyone has 
>> comments before then, I'd be glad to hear them.
>>
>> Best,
>> WILL
>>
>> ----- Original Message ----- 
>> From: "Will Glass-Husain" <wg...@forio.com>
>> To: "Velocity Developers List" <ve...@jakarta.apache.org>
>> Sent: Friday, November 18, 2005 1:37 PM
>> Subject: Re: Undefined Reference:- raise exception?
>>
>>
>>> Hi,
>>>
>>> I'm rethinking my earlier message.  Definitely implement  a custom
>>> ReferenceInsertionHandler.  If the refererence is invalid then the value
>>> will be null.
>>>
>>> If you want to stop parsing, throw a custom defined Error instead of an
>>> exception.  Velocity catches all Exceptions from both the Uberspector 
>>> and
>>> the event handlers but will let subclasses of Error go through.
>>>
>>> I think you should find this to be pretty simple.
>>>
>>> One disadvantage to this approach is that you can't access the line and 
>>> column of the reference.  Maybe there's something we can do to make that 
>>> work.
>>>
>>> WILL
>>>
>>> ----- Original Message ----- 
>>> From: "Will Glass-Husain" <wg...@forio.com>
>>> To: "Velocity Developers List" <ve...@jakarta.apache.org>
>>> Sent: Friday, November 18, 2005 12:52 PM
>>> Subject: Re: Undefined Reference:- raise exception?
>>>
>>>
>>>>I can think of two different methods...
>>>>
>>>> (1) Implement a ReferenceInsertionHandler.  This has a method that 
>>>> receives the complete reference string (e.g. "foo.bar.someMethod()" ) 
>>>> and allows you to modify the result.  The problem is that this will not 
>>>> be called for invalid references.
>>>>
>>>> (2) better would be to implement a custom Ubserspector.  Override the 
>>>> default UberspectImpl and the methods getMethod and getMethodGet.  If 
>>>> no method is present, flag the error.
>>>>
>>>> For an example, see "UberspectTestImpl" in the current velocity source 
>>>> head (it's in the test classes).
>>>>
>>>> There's one thing that doesn't work with this approach and that's when 
>>>> there's a null in the middle of a chain of reference.  In other words, 
>>>> if "foo.bar.someMethod()" if the bar property is null, getMethod is 
>>>> never called.  As Llewellyn referred to we're going to submit a patch 
>>>> that will always call the Uberspector even if the object result is 
>>>> null.
>>>>
>>>> Best, WILL
>>>>
>>>> ----- Original Message ----- 
>>>> From: "Daniel Burke" <da...@propylon.com>
>>>> To: <ve...@jakarta.apache.org>
>>>> Sent: Friday, November 18, 2005 7:27 AM
>>>> Subject: Undefined Reference:- raise exception?
>>>>
>>>>
>>>>> Hi,
>>>>> Is it possible to configure velocity to raise an exception if a 
>>>>> variable
>>>>> is reference which is undefined at the parsing stage? I know you use 
>>>>> quiet
>>>>> syntax to not output the variable name but I want to stop parsing the
>>>>> message.
>>>>> cheers
>>>>> Dan
>>>>>
>>>>>
>>>>> ---------------------------------------------------------------------
>>>>> To unsubscribe, e-mail: velocity-dev-unsubscribe@jakarta.apache.org
>>>>> For additional commands, e-mail: velocity-dev-help@jakarta.apache.org
>>>>>
>>>>
>>>>
>>>> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail: velocity-dev-unsubscribe@jakarta.apache.org
>>>> For additional commands, e-mail: velocity-dev-help@jakarta.apache.org
>>>>
>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: velocity-dev-unsubscribe@jakarta.apache.org
>>> For additional commands, e-mail: velocity-dev-help@jakarta.apache.org
>>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: velocity-dev-unsubscribe@jakarta.apache.org
>> For additional commands, e-mail: velocity-dev-help@jakarta.apache.org
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: velocity-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: velocity-dev-help@jakarta.apache.org
> 


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


Re: Undefined Reference:- raise exception?

Posted by Llewellyn Falco <is...@setgame.com>.
I am still very concerned as to what falls as a bad reference, especially as 
nulls are concerned.

$a.b().c().d().e($f.g())
should not be a bad reference if e or g returned null,
it should be if a,b,c,d, or f did.

you can NOT make it so #if($common.isNull($order.getBuyer())) N/A #else 
$order.getBuyer().getName() #end
will not work.

likewise if an exception is thrown, it is much more useful to get
null.d()

than
$a.b().c().d().e($f.g())
had a null.

again, this belongs in the uberspect.

    llewellyn.


----- Original Message ----- 
From: "Will Glass-Husain" <wg...@forio.com>
To: "Velocity Developers List" <ve...@jakarta.apache.org>
Sent: Friday, November 18, 2005 3:36 PM
Subject: Re: Undefined Reference:- raise exception?


> Hi,
>
> I've coded an event handler (InvalidReferenceHandler) that implements 
> this. It's in a patch file at
> http://issues.apache.org/jira/browse/VELOCITY-423
>
> It can be configured to either parse the whole page and collect a list of 
> invalid resources, or to throw a runtime exception upon encountering the 
> first one.
>
> Warning: this is subject to change.  But feel free to take a look at it. 
> In a day or two I'll add it to the main source tree.  If anyone has 
> comments before then, I'd be glad to hear them.
>
> Best,
> WILL
>
> ----- Original Message ----- 
> From: "Will Glass-Husain" <wg...@forio.com>
> To: "Velocity Developers List" <ve...@jakarta.apache.org>
> Sent: Friday, November 18, 2005 1:37 PM
> Subject: Re: Undefined Reference:- raise exception?
>
>
>> Hi,
>>
>> I'm rethinking my earlier message.  Definitely implement  a custom
>> ReferenceInsertionHandler.  If the refererence is invalid then the value
>> will be null.
>>
>> If you want to stop parsing, throw a custom defined Error instead of an
>> exception.  Velocity catches all Exceptions from both the Uberspector and
>> the event handlers but will let subclasses of Error go through.
>>
>> I think you should find this to be pretty simple.
>>
>> One disadvantage to this approach is that you can't access the line and 
>> column of the reference.  Maybe there's something we can do to make that 
>> work.
>>
>> WILL
>>
>> ----- Original Message ----- 
>> From: "Will Glass-Husain" <wg...@forio.com>
>> To: "Velocity Developers List" <ve...@jakarta.apache.org>
>> Sent: Friday, November 18, 2005 12:52 PM
>> Subject: Re: Undefined Reference:- raise exception?
>>
>>
>>>I can think of two different methods...
>>>
>>> (1) Implement a ReferenceInsertionHandler.  This has a method that 
>>> receives the complete reference string (e.g. "foo.bar.someMethod()" ) 
>>> and allows you to modify the result.  The problem is that this will not 
>>> be called for invalid references.
>>>
>>> (2) better would be to implement a custom Ubserspector.  Override the 
>>> default UberspectImpl and the methods getMethod and getMethodGet.  If no 
>>> method is present, flag the error.
>>>
>>> For an example, see "UberspectTestImpl" in the current velocity source 
>>> head (it's in the test classes).
>>>
>>> There's one thing that doesn't work with this approach and that's when 
>>> there's a null in the middle of a chain of reference.  In other words, 
>>> if "foo.bar.someMethod()" if the bar property is null, getMethod is 
>>> never called.  As Llewellyn referred to we're going to submit a patch 
>>> that will always call the Uberspector even if the object result is null.
>>>
>>> Best, WILL
>>>
>>> ----- Original Message ----- 
>>> From: "Daniel Burke" <da...@propylon.com>
>>> To: <ve...@jakarta.apache.org>
>>> Sent: Friday, November 18, 2005 7:27 AM
>>> Subject: Undefined Reference:- raise exception?
>>>
>>>
>>>> Hi,
>>>> Is it possible to configure velocity to raise an exception if a 
>>>> variable
>>>> is reference which is undefined at the parsing stage? I know you use 
>>>> quiet
>>>> syntax to not output the variable name but I want to stop parsing the
>>>> message.
>>>> cheers
>>>> Dan
>>>>
>>>>
>>>> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail: velocity-dev-unsubscribe@jakarta.apache.org
>>>> For additional commands, e-mail: velocity-dev-help@jakarta.apache.org
>>>>
>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: velocity-dev-unsubscribe@jakarta.apache.org
>>> For additional commands, e-mail: velocity-dev-help@jakarta.apache.org
>>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: velocity-dev-unsubscribe@jakarta.apache.org
>> For additional commands, e-mail: velocity-dev-help@jakarta.apache.org
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: velocity-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: velocity-dev-help@jakarta.apache.org 


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


Re: Undefined Reference:- raise exception?

Posted by Will Glass-Husain <wg...@forio.com>.
Hi,

I've coded an event handler (InvalidReferenceHandler) that implements this. 
It's in a patch file at
http://issues.apache.org/jira/browse/VELOCITY-423

It can be configured to either parse the whole page and collect a list of 
invalid resources, or to throw a runtime exception upon encountering the 
first one.

Warning: this is subject to change.  But feel free to take a look at it.  In 
a day or two I'll add it to the main source tree.  If anyone has comments 
before then, I'd be glad to hear them.

Best,
WILL

----- Original Message ----- 
From: "Will Glass-Husain" <wg...@forio.com>
To: "Velocity Developers List" <ve...@jakarta.apache.org>
Sent: Friday, November 18, 2005 1:37 PM
Subject: Re: Undefined Reference:- raise exception?


> Hi,
>
> I'm rethinking my earlier message.  Definitely implement  a custom
> ReferenceInsertionHandler.  If the refererence is invalid then the value
> will be null.
>
> If you want to stop parsing, throw a custom defined Error instead of an
> exception.  Velocity catches all Exceptions from both the Uberspector and
> the event handlers but will let subclasses of Error go through.
>
> I think you should find this to be pretty simple.
>
> One disadvantage to this approach is that you can't access the line and 
> column of the reference.  Maybe there's something we can do to make that 
> work.
>
> WILL
>
> ----- Original Message ----- 
> From: "Will Glass-Husain" <wg...@forio.com>
> To: "Velocity Developers List" <ve...@jakarta.apache.org>
> Sent: Friday, November 18, 2005 12:52 PM
> Subject: Re: Undefined Reference:- raise exception?
>
>
>>I can think of two different methods...
>>
>> (1) Implement a ReferenceInsertionHandler.  This has a method that 
>> receives the complete reference string (e.g. "foo.bar.someMethod()" ) and 
>> allows you to modify the result.  The problem is that this will not be 
>> called for invalid references.
>>
>> (2) better would be to implement a custom Ubserspector.  Override the 
>> default UberspectImpl and the methods getMethod and getMethodGet.  If no 
>> method is present, flag the error.
>>
>> For an example, see "UberspectTestImpl" in the current velocity source 
>> head (it's in the test classes).
>>
>> There's one thing that doesn't work with this approach and that's when 
>> there's a null in the middle of a chain of reference.  In other words, if 
>> "foo.bar.someMethod()" if the bar property is null, getMethod is never 
>> called.  As Llewellyn referred to we're going to submit a patch that will 
>> always call the Uberspector even if the object result is null.
>>
>> Best, WILL
>>
>> ----- Original Message ----- 
>> From: "Daniel Burke" <da...@propylon.com>
>> To: <ve...@jakarta.apache.org>
>> Sent: Friday, November 18, 2005 7:27 AM
>> Subject: Undefined Reference:- raise exception?
>>
>>
>>> Hi,
>>> Is it possible to configure velocity to raise an exception if a variable
>>> is reference which is undefined at the parsing stage? I know you use 
>>> quiet
>>> syntax to not output the variable name but I want to stop parsing the
>>> message.
>>> cheers
>>> Dan
>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: velocity-dev-unsubscribe@jakarta.apache.org
>>> For additional commands, e-mail: velocity-dev-help@jakarta.apache.org
>>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: velocity-dev-unsubscribe@jakarta.apache.org
>> For additional commands, e-mail: velocity-dev-help@jakarta.apache.org
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: velocity-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: velocity-dev-help@jakarta.apache.org
> 


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


Re: Undefined Reference:- raise exception?

Posted by Will Glass-Husain <wg...@forio.com>.
Hi,

I'm rethinking my earlier message.  Definitely implement  a custom
ReferenceInsertionHandler.  If the refererence is invalid then the value
will be null.

If you want to stop parsing, throw a custom defined Error instead of an
exception.  Velocity catches all Exceptions from both the Uberspector and
the event handlers but will let subclasses of Error go through.

I think you should find this to be pretty simple.

One disadvantage to this approach is that you can't access the line and 
column of the reference.  Maybe there's something we can do to make that 
work.

WILL

----- Original Message ----- 
From: "Will Glass-Husain" <wg...@forio.com>
To: "Velocity Developers List" <ve...@jakarta.apache.org>
Sent: Friday, November 18, 2005 12:52 PM
Subject: Re: Undefined Reference:- raise exception?


>I can think of two different methods...
>
> (1) Implement a ReferenceInsertionHandler.  This has a method that 
> receives the complete reference string (e.g. "foo.bar.someMethod()" ) and 
> allows you to modify the result.  The problem is that this will not be 
> called for invalid references.
>
> (2) better would be to implement a custom Ubserspector.  Override the 
> default UberspectImpl and the methods getMethod and getMethodGet.  If no 
> method is present, flag the error.
>
> For an example, see "UberspectTestImpl" in the current velocity source 
> head (it's in the test classes).
>
> There's one thing that doesn't work with this approach and that's when 
> there's a null in the middle of a chain of reference.  In other words, if 
> "foo.bar.someMethod()" if the bar property is null, getMethod is never 
> called.  As Llewellyn referred to we're going to submit a patch that will 
> always call the Uberspector even if the object result is null.
>
> Best, WILL
>
> ----- Original Message ----- 
> From: "Daniel Burke" <da...@propylon.com>
> To: <ve...@jakarta.apache.org>
> Sent: Friday, November 18, 2005 7:27 AM
> Subject: Undefined Reference:- raise exception?
>
>
>> Hi,
>> Is it possible to configure velocity to raise an exception if a variable
>> is reference which is undefined at the parsing stage? I know you use 
>> quiet
>> syntax to not output the variable name but I want to stop parsing the
>> message.
>> cheers
>> Dan
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: velocity-dev-unsubscribe@jakarta.apache.org
>> For additional commands, e-mail: velocity-dev-help@jakarta.apache.org
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: velocity-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: velocity-dev-help@jakarta.apache.org
>


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


Re: Undefined Reference:- raise exception?

Posted by Will Glass-Husain <wg...@forio.com>.
I can think of two different methods...

(1) Implement a ReferenceInsertionHandler.  This has a method that receives 
the complete reference string (e.g. "foo.bar.someMethod()" ) and allows you 
to modify the result.  The problem is that this will not be called for 
invalid references.

(2) better would be to implement a custom Ubserspector.  Override the 
default UberspectImpl and the methods getMethod and getMethodGet.  If no 
method is present, flag the error.

For an example, see "UberspectTestImpl" in the current velocity source head 
(it's in the test classes).

There's one thing that doesn't work with this approach and that's when 
there's a null in the middle of a chain of reference.  In other words, if 
"foo.bar.someMethod()" if the bar property is null, getMethod is never 
called.  As Llewellyn referred to we're going to submit a patch that will 
always call the Uberspector even if the object result is null.

Best, WILL

----- Original Message ----- 
From: "Daniel Burke" <da...@propylon.com>
To: <ve...@jakarta.apache.org>
Sent: Friday, November 18, 2005 7:27 AM
Subject: Undefined Reference:- raise exception?


> Hi,
> Is it possible to configure velocity to raise an exception if a variable
> is reference which is undefined at the parsing stage? I know you use quiet
> syntax to not output the variable name but I want to stop parsing the
> message.
> cheers
> Dan
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: velocity-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: velocity-dev-help@jakarta.apache.org
> 


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


Re: Undefined Reference:- raise exception?

Posted by Llewellyn Falco <is...@setgame.com>.
Hey Daniel,

    Will & I took a look at this earlier today, should have a patch in soon, 
I'll send a usable build later today.

    llewellyn.
----- Original Message ----- 
From: "Daniel Burke" <da...@propylon.com>
To: <ve...@jakarta.apache.org>
Sent: Friday, November 18, 2005 7:27 AM
Subject: Undefined Reference:- raise exception?


> Hi,
> Is it possible to configure velocity to raise an exception if a variable
> is reference which is undefined at the parsing stage? I know you use quiet
> syntax to not output the variable name but I want to stop parsing the
> message.
> cheers
> Dan
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: velocity-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: velocity-dev-help@jakarta.apache.org 


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