You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@velocity.apache.org by Vincent van Beveren <vi...@nazarene.nl> on 2005/01/06 16:12:40 UTC

Context availability during method invocation / ReferenceInsertionEventHandler

Hi everyone,

I've searched through the JavaDocs' and source code to find a solution 
for the following problem, but I don't think there are any facilities 
for it, but maybe someone has an idea. I would like to simplify the 
following piece Velocity code:

$locale = ... user defined locale ...      // this is done while setting 
up the context

Description: $product.description.toString($locale)
Title: $product.title.toString($locale)

In which the class product has a method 'getDescription' which returens 
a home-made object of the class LocaleData. LocaleData is basically a 
map with as key a locale and as value an object, usually a string. 
Somewhat like a ResourceBundle (but not quite)

The simplified version would be like this.

$locale = ... user defined locale ...// this is done while setting up 
the context

Description: $product.description
Title: $product.title

As you can see, the whole localized stuff is gone. As far as I can see 
this can be done in two ways: Either I extend the Uberspector to 
recognize the return-type of getDescription and create the correct 
handler for it, or I intercept objects of the type LocaleData with a 
ReferenceInsertionEventHandler, and replace them for their data in the 
correct locale. Both ways though, run into dead ends. Both in the 
Uberspector as the ReferenceInsertionEventHandler the context is not 
available.

I found a spark of hope when I saw

   /**
     * Execute method against context.
     */
    public Object OLDexecute(Object o, InternalContextAdapter context)
        throws IllegalAccessException, MethodInvocationException
    { ..

in the GetExecutor. Unfortunatly, it seems to be deprecated, and no 
longer in use.

Anyone has any idea how to accompish automatic parsing of localized data?

Thanks in advance,
Vincent





-- 
XIAM Solutions B.V.
Barchman Wuytierslaan 72A
3818 LK AMERSFOORT
tel. : +31(0)33 462 40 07
e-mail: vincent@nazarene.nl, info@xiam.nl

WAARSCHUWING:
Dit bericht is UITSLUITEND bestemd voor de (rechts)perso(o)n(en) aan welke het bericht is gericht. Het kan vertrouwelijke of alleen voor deze rechts)perso(o)n(en) bestemde informatie bevatten, die niet mag worden geopenbaard. Als dit bericht niet voor u bestemd is, mag u de ontvangen informatie niet lezen, gebruiken, verspreiden of kopiëren. Als u dit bericht per abuis heeft ontvangen, gelieve het bericht dan te vernietigen en contact op te nemen met de afzender.

WARNING:
This message is intended ONLY for the person(s) or entity to which it is addressed and may contain confidential and/or privileged information, the disclosure of which is prohibited. If you are not the intended recipient you may not read, use, disseminate or copy the information transmitted. If you have received this message by mistake, please contact the sender and delete the material from any computer.



-- 
No virus found in this outgoing message.
Checked by AVG Anti-Virus.
Version: 7.0.300 / Virus Database: 265.6.8 - Release Date: 3-1-2005


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


Re: Context availability during method invocation / ReferenceInsertionEventHandler

Posted by Will Glass-Husain <wg...@forio.com>.
This should still work.  Go review how you use a ReferenceInsertionHandler. 
You bind it to a context.  Therefore, if you create a new context for every 
merge you have a unique ReferenceInsertionHandler per merge.

When I have time later today, I'll write some sample code.  You might take 
another look at the docs for event handlers in the meantime.

WILL

----- Original Message ----- 
From: "Vincent van Beveren" <vi...@nazarene.nl>
To: "Velocity Developers List" <ve...@jakarta.apache.org>
Sent: Friday, January 07, 2005 12:51 AM
Subject: Re: Context availability during method invocation / 
ReferenceInsertionEventHandler


> Thanks Will,
>
> That sounds like something that could work. However (why is there always a 
> however), there are two issues:
> 1. Its a web-app, so the ReferenceInsertionHandler would need to be bound 
> to a merge because of multithreadding.
> 2. I really wouldn't know where to add the listener. There is no 
> 'MergeEventHandler' or something.
>
> Okay, I have one, somewhat far-fetched solution, but I think its rather 
> ugly:
>
> First, you create a static class with some map. The map contains a thread 
> as key, and a locale as value. Then (assuming we use a model 2 design 
> pattern) during the setup I add the locale to the of that thread to that 
> map. Now during merging, the ReferenceInsertionHandler would look up the 
> Locale currently associated with that thread, and get the right language. 
> It might work, but it just doesn't feel right.
>
> Thanks,
> Vincent
>
>
> Will Glass-Husain wrote:
>
>> Hi Vincent,
>>
>> I'd make a ReferenceInsertionEventHandler.  You can make the context
>> available by passing into the constructor and storing it as an instance
>> variable in the handler.  Just initialize a new
>> ReferenceInsertionEventHandler for each page merge.
>>
>> As a side note, maybe we should create some examples of this in the 
>> developer docs.  It took me a while to realize the usefulness of this 
>> pattern.
>>
>> WILL
>>
>> ----- Original Message ----- From: "Vincent van Beveren" 
>> <vi...@nazarene.nl>
>> To: <ve...@jakarta.apache.org>
>> Sent: Thursday, January 06, 2005 7:12 AM
>> Subject: Context availability during method invocation /
>> ReferenceInsertionEventHandler
>>
>>
>>> Hi everyone,
>>>
>>> I've searched through the JavaDocs' and source code to find a solution 
>>> for
>>> the following problem, but I don't think there are any facilities for 
>>> it,
>>> but maybe someone has an idea. I would like to simplify the following
>>> piece Velocity code:
>>>
>>> $locale = ... user defined locale ...      // this is done while setting
>>> up the context
>>>
>>> Description: $product.description.toString($locale)
>>> Title: $product.title.toString($locale)
>>>
>>> In which the class product has a method 'getDescription' which returens 
>>> a
>>> home-made object of the class LocaleData. LocaleData is basically a map
>>> with as key a locale and as value an object, usually a string. Somewhat
>>> like a ResourceBundle (but not quite)
>>>
>>> The simplified version would be like this.
>>>
>>> $locale = ... user defined locale ...// this is done while setting up 
>>> the
>>> context
>>>
>>> Description: $product.description
>>> Title: $product.title
>>>
>>> As you can see, the whole localized stuff is gone. As far as I can see
>>> this can be done in two ways: Either I extend the Uberspector to 
>>> recognize
>>> the return-type of getDescription and create the correct handler for it,
>>> or I intercept objects of the type LocaleData with a
>>> ReferenceInsertionEventHandler, and replace them for their data in the
>>> correct locale. Both ways though, run into dead ends. Both in the
>>> Uberspector as the ReferenceInsertionEventHandler the context is not
>>> available.
>>>
>>> I found a spark of hope when I saw
>>>
>>>   /**
>>>     * Execute method against context.
>>>     */
>>>    public Object OLDexecute(Object o, InternalContextAdapter context)
>>>        throws IllegalAccessException, MethodInvocationException
>>>    { ..
>>>
>>> in the GetExecutor. Unfortunatly, it seems to be deprecated, and no 
>>> longer
>>> in use.
>>>
>>> Anyone has any idea how to accompish automatic parsing of localized 
>>> data?
>>>
>>> Thanks in advance,
>>> Vincent
>>>
>>>
>>>
>>>
>>>
>
>
>
> -- 
> No virus found in this outgoing message.
> Checked by AVG Anti-Virus.
> Version: 7.0.300 / Virus Database: 265.6.8 - Release Date: 3-1-2005
>
>
> ---------------------------------------------------------------------
> 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: Context availability during method invocation / ReferenceInsertionEventHandler

Posted by Vincent van Beveren <vi...@nazarene.nl>.
Hi Simon,

Yes, I know, I started that thread :) but now our company has made some 
decissions in this area which effect the approach w're using.

Using a ThreadLocal is I guess a better idea than doing it yourself. It 
doesn't change the principle that you need to bind a value to the 
thread, which I think is something you need to avoid if possible.

Vincent

Simon Christian wrote:

> Hi Vincent,
>
> There was some discussion on pretty much this topic on the user list 
> recently:
>
> http://mail-archives.apache.org/eyebrowse/BrowseList?listName=velocity-user@jakarta.apache.org&by=thread&from=944016 
>
>
> , or search the archives for 'Localized data'.
>
> I suggested using a ThreadLocal object per request which would have 
> the same effect as your 'ugly' solution but (to my mind) slightly 
> neater and without the cleanup issue.
>
> - simon
>
> Vincent van Beveren wrote:
>
>> Thanks Will,
>>
>> That sounds like something that could work. However (why is there 
>> always a however), there are two issues:
>> 1. Its a web-app, so the ReferenceInsertionHandler would need to be 
>> bound to a merge because of multithreadding.
>> 2. I really wouldn't know where to add the listener. There is no 
>> 'MergeEventHandler' or something.
>>
>> Okay, I have one, somewhat far-fetched solution, but I think its 
>> rather ugly:
>>
>> First, you create a static class with some map. The map contains a 
>> thread as key, and a locale as value. Then (assuming we use a model 2 
>> design pattern) during the setup I add the locale to the of that 
>> thread to that map. Now during merging, the ReferenceInsertionHandler 
>> would look up the Locale currently associated with that thread, and 
>> get the right language. It might work, but it just doesn't feel right.
>>
>> Thanks,
>> Vincent
>>
>>
>> Will Glass-Husain wrote:
>>
>>> Hi Vincent,
>>>
>>> I'd make a ReferenceInsertionEventHandler.  You can make the context
>>> available by passing into the constructor and storing it as an instance
>>> variable in the handler.  Just initialize a new
>>> ReferenceInsertionEventHandler for each page merge.
>>>
>>> As a side note, maybe we should create some examples of this in the 
>>> developer docs.  It took me a while to realize the usefulness of 
>>> this pattern.
>>>
>>> WILL
>>>
>>> ----- Original Message ----- From: "Vincent van Beveren" 
>>> <vi...@nazarene.nl>
>>> To: <ve...@jakarta.apache.org>
>>> Sent: Thursday, January 06, 2005 7:12 AM
>>> Subject: Context availability during method invocation /
>>> ReferenceInsertionEventHandler
>>>
>>>
>>>> Hi everyone,
>>>>
>>>> I've searched through the JavaDocs' and source code to find a 
>>>> solution for
>>>> the following problem, but I don't think there are any facilities 
>>>> for it,
>>>> but maybe someone has an idea. I would like to simplify the following
>>>> piece Velocity code:
>>>>
>>>> $locale = ... user defined locale ...      // this is done while 
>>>> setting
>>>> up the context
>>>>
>>>> Description: $product.description.toString($locale)
>>>> Title: $product.title.toString($locale)
>>>>
>>>> In which the class product has a method 'getDescription' which 
>>>> returens a
>>>> home-made object of the class LocaleData. LocaleData is basically a 
>>>> map
>>>> with as key a locale and as value an object, usually a string. 
>>>> Somewhat
>>>> like a ResourceBundle (but not quite)
>>>>
>>>> The simplified version would be like this.
>>>>
>>>> $locale = ... user defined locale ...// this is done while setting 
>>>> up the
>>>> context
>>>>
>>>> Description: $product.description
>>>> Title: $product.title
>>>>
>>>> As you can see, the whole localized stuff is gone. As far as I can see
>>>> this can be done in two ways: Either I extend the Uberspector to 
>>>> recognize
>>>> the return-type of getDescription and create the correct handler 
>>>> for it,
>>>> or I intercept objects of the type LocaleData with a
>>>> ReferenceInsertionEventHandler, and replace them for their data in the
>>>> correct locale. Both ways though, run into dead ends. Both in the
>>>> Uberspector as the ReferenceInsertionEventHandler the context is not
>>>> available.
>>>>
>>>> I found a spark of hope when I saw
>>>>
>>>>   /**
>>>>     * Execute method against context.
>>>>     */
>>>>    public Object OLDexecute(Object o, InternalContextAdapter context)
>>>>        throws IllegalAccessException, MethodInvocationException
>>>>    { ..
>>>>
>>>> in the GetExecutor. Unfortunatly, it seems to be deprecated, and no 
>>>> longer
>>>> in use.
>>>>
>>>> Anyone has any idea how to accompish automatic parsing of localized 
>>>> data?
>>>>
>>>> Thanks in advance,
>>>> Vincent
>>>>
>>>>
>>>>
>>>>
>>>>
>>
>>
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: velocity-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: velocity-dev-help@jakarta.apache.org
>
>


-- 
XIAM Solutions B.V.
Barchman Wuytierslaan 72A
3818 LK AMERSFOORT
tel. : +31(0)33 462 40 07
e-mail: vincent@nazarene.nl, info@xiam.nl

WAARSCHUWING:
Dit bericht is UITSLUITEND bestemd voor de (rechts)perso(o)n(en) aan welke het bericht is gericht. Het kan vertrouwelijke of alleen voor deze rechts)perso(o)n(en) bestemde informatie bevatten, die niet mag worden geopenbaard. Als dit bericht niet voor u bestemd is, mag u de ontvangen informatie niet lezen, gebruiken, verspreiden of kopiëren. Als u dit bericht per abuis heeft ontvangen, gelieve het bericht dan te vernietigen en contact op te nemen met de afzender.

WARNING:
This message is intended ONLY for the person(s) or entity to which it is addressed and may contain confidential and/or privileged information, the disclosure of which is prohibited. If you are not the intended recipient you may not read, use, disseminate or copy the information transmitted. If you have received this message by mistake, please contact the sender and delete the material from any computer.



-- 
No virus found in this outgoing message.
Checked by AVG Anti-Virus.
Version: 7.0.300 / Virus Database: 265.6.8 - Release Date: 3-1-2005


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


Re: Context availability during method invocation / ReferenceInsertionEventHandler

Posted by Simon Christian <si...@stoutstick.com>.
Sorry Vincent just realised you started the thread I referenced there - 
  guessing it wasn't useful to you last time around!

-s

Simon Christian wrote:
> Hi Vincent,
> 
> There was some discussion on pretty much this topic on the user list 
> recently:
> 
> http://mail-archives.apache.org/eyebrowse/BrowseList?listName=velocity-user@jakarta.apache.org&by=thread&from=944016 
> 
> 
> , or search the archives for 'Localized data'.
> 
> I suggested using a ThreadLocal object per request which would have the 
> same effect as your 'ugly' solution but (to my mind) slightly neater and 
> without the cleanup issue.
> 
> - simon
> 
> Vincent van Beveren wrote:

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


Re: Context availability during method invocation / ReferenceInsertionEventHandler

Posted by Simon Christian <si...@stoutstick.com>.
Hi Vincent,

There was some discussion on pretty much this topic on the user list 
recently:

http://mail-archives.apache.org/eyebrowse/BrowseList?listName=velocity-user@jakarta.apache.org&by=thread&from=944016

, or search the archives for 'Localized data'.

I suggested using a ThreadLocal object per request which would have the 
same effect as your 'ugly' solution but (to my mind) slightly neater and 
without the cleanup issue.

- simon

Vincent van Beveren wrote:

> Thanks Will,
> 
> That sounds like something that could work. However (why is there always 
> a however), there are two issues:
> 1. Its a web-app, so the ReferenceInsertionHandler would need to be 
> bound to a merge because of multithreadding.
> 2. I really wouldn't know where to add the listener. There is no 
> 'MergeEventHandler' or something.
> 
> Okay, I have one, somewhat far-fetched solution, but I think its rather 
> ugly:
> 
> First, you create a static class with some map. The map contains a 
> thread as key, and a locale as value. Then (assuming we use a model 2 
> design pattern) during the setup I add the locale to the of that thread 
> to that map. Now during merging, the ReferenceInsertionHandler would 
> look up the Locale currently associated with that thread, and get the 
> right language. It might work, but it just doesn't feel right.
> 
> Thanks,
> Vincent
> 
> 
> Will Glass-Husain wrote:
> 
>> Hi Vincent,
>>
>> I'd make a ReferenceInsertionEventHandler.  You can make the context
>> available by passing into the constructor and storing it as an instance
>> variable in the handler.  Just initialize a new
>> ReferenceInsertionEventHandler for each page merge.
>>
>> As a side note, maybe we should create some examples of this in the 
>> developer docs.  It took me a while to realize the usefulness of this 
>> pattern.
>>
>> WILL
>>
>> ----- Original Message ----- From: "Vincent van Beveren" 
>> <vi...@nazarene.nl>
>> To: <ve...@jakarta.apache.org>
>> Sent: Thursday, January 06, 2005 7:12 AM
>> Subject: Context availability during method invocation /
>> ReferenceInsertionEventHandler
>>
>>
>>> Hi everyone,
>>>
>>> I've searched through the JavaDocs' and source code to find a 
>>> solution for
>>> the following problem, but I don't think there are any facilities for 
>>> it,
>>> but maybe someone has an idea. I would like to simplify the following
>>> piece Velocity code:
>>>
>>> $locale = ... user defined locale ...      // this is done while setting
>>> up the context
>>>
>>> Description: $product.description.toString($locale)
>>> Title: $product.title.toString($locale)
>>>
>>> In which the class product has a method 'getDescription' which 
>>> returens a
>>> home-made object of the class LocaleData. LocaleData is basically a map
>>> with as key a locale and as value an object, usually a string. Somewhat
>>> like a ResourceBundle (but not quite)
>>>
>>> The simplified version would be like this.
>>>
>>> $locale = ... user defined locale ...// this is done while setting up 
>>> the
>>> context
>>>
>>> Description: $product.description
>>> Title: $product.title
>>>
>>> As you can see, the whole localized stuff is gone. As far as I can see
>>> this can be done in two ways: Either I extend the Uberspector to 
>>> recognize
>>> the return-type of getDescription and create the correct handler for it,
>>> or I intercept objects of the type LocaleData with a
>>> ReferenceInsertionEventHandler, and replace them for their data in the
>>> correct locale. Both ways though, run into dead ends. Both in the
>>> Uberspector as the ReferenceInsertionEventHandler the context is not
>>> available.
>>>
>>> I found a spark of hope when I saw
>>>
>>>   /**
>>>     * Execute method against context.
>>>     */
>>>    public Object OLDexecute(Object o, InternalContextAdapter context)
>>>        throws IllegalAccessException, MethodInvocationException
>>>    { ..
>>>
>>> in the GetExecutor. Unfortunatly, it seems to be deprecated, and no 
>>> longer
>>> in use.
>>>
>>> Anyone has any idea how to accompish automatic parsing of localized 
>>> data?
>>>
>>> Thanks in advance,
>>> Vincent
>>>
>>>
>>>
>>>
>>>
> 
> 
> 


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


Re: Context availability during method invocation / ReferenceInsertionEventHandler

Posted by Vincent van Beveren <vi...@nazarene.nl>.
Thanks Will,

That sounds like something that could work. However (why is there always 
a however), there are two issues:
1. Its a web-app, so the ReferenceInsertionHandler would need to be 
bound to a merge because of multithreadding.
2. I really wouldn't know where to add the listener. There is no 
'MergeEventHandler' or something.

Okay, I have one, somewhat far-fetched solution, but I think its rather 
ugly:

First, you create a static class with some map. The map contains a 
thread as key, and a locale as value. Then (assuming we use a model 2 
design pattern) during the setup I add the locale to the of that thread 
to that map. Now during merging, the ReferenceInsertionHandler would 
look up the Locale currently associated with that thread, and get the 
right language. It might work, but it just doesn't feel right.

Thanks,
Vincent


Will Glass-Husain wrote:

> Hi Vincent,
>
> I'd make a ReferenceInsertionEventHandler.  You can make the context
> available by passing into the constructor and storing it as an instance
> variable in the handler.  Just initialize a new
> ReferenceInsertionEventHandler for each page merge.
>
> As a side note, maybe we should create some examples of this in the 
> developer docs.  It took me a while to realize the usefulness of this 
> pattern.
>
> WILL
>
> ----- Original Message ----- From: "Vincent van Beveren" 
> <vi...@nazarene.nl>
> To: <ve...@jakarta.apache.org>
> Sent: Thursday, January 06, 2005 7:12 AM
> Subject: Context availability during method invocation /
> ReferenceInsertionEventHandler
>
>
>> Hi everyone,
>>
>> I've searched through the JavaDocs' and source code to find a 
>> solution for
>> the following problem, but I don't think there are any facilities for 
>> it,
>> but maybe someone has an idea. I would like to simplify the following
>> piece Velocity code:
>>
>> $locale = ... user defined locale ...      // this is done while setting
>> up the context
>>
>> Description: $product.description.toString($locale)
>> Title: $product.title.toString($locale)
>>
>> In which the class product has a method 'getDescription' which 
>> returens a
>> home-made object of the class LocaleData. LocaleData is basically a map
>> with as key a locale and as value an object, usually a string. Somewhat
>> like a ResourceBundle (but not quite)
>>
>> The simplified version would be like this.
>>
>> $locale = ... user defined locale ...// this is done while setting up 
>> the
>> context
>>
>> Description: $product.description
>> Title: $product.title
>>
>> As you can see, the whole localized stuff is gone. As far as I can see
>> this can be done in two ways: Either I extend the Uberspector to 
>> recognize
>> the return-type of getDescription and create the correct handler for it,
>> or I intercept objects of the type LocaleData with a
>> ReferenceInsertionEventHandler, and replace them for their data in the
>> correct locale. Both ways though, run into dead ends. Both in the
>> Uberspector as the ReferenceInsertionEventHandler the context is not
>> available.
>>
>> I found a spark of hope when I saw
>>
>>   /**
>>     * Execute method against context.
>>     */
>>    public Object OLDexecute(Object o, InternalContextAdapter context)
>>        throws IllegalAccessException, MethodInvocationException
>>    { ..
>>
>> in the GetExecutor. Unfortunatly, it seems to be deprecated, and no 
>> longer
>> in use.
>>
>> Anyone has any idea how to accompish automatic parsing of localized 
>> data?
>>
>> Thanks in advance,
>> Vincent
>>
>>
>>
>>
>>



-- 
No virus found in this outgoing message.
Checked by AVG Anti-Virus.
Version: 7.0.300 / Virus Database: 265.6.8 - Release Date: 3-1-2005


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


Re: Context availability during method invocation / ReferenceInsertionEventHandler

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

I'd make a ReferenceInsertionEventHandler.  You can make the context
available by passing into the constructor and storing it as an instance
variable in the handler.  Just initialize a new
ReferenceInsertionEventHandler for each page merge.

As a side note, maybe we should create some examples of this in the 
developer docs.  It took me a while to realize the usefulness of this 
pattern.

WILL

----- Original Message ----- 
From: "Vincent van Beveren" <vi...@nazarene.nl>
To: <ve...@jakarta.apache.org>
Sent: Thursday, January 06, 2005 7:12 AM
Subject: Context availability during method invocation /
ReferenceInsertionEventHandler


> Hi everyone,
>
> I've searched through the JavaDocs' and source code to find a solution for
> the following problem, but I don't think there are any facilities for it,
> but maybe someone has an idea. I would like to simplify the following
> piece Velocity code:
>
> $locale = ... user defined locale ...      // this is done while setting
> up the context
>
> Description: $product.description.toString($locale)
> Title: $product.title.toString($locale)
>
> In which the class product has a method 'getDescription' which returens a
> home-made object of the class LocaleData. LocaleData is basically a map
> with as key a locale and as value an object, usually a string. Somewhat
> like a ResourceBundle (but not quite)
>
> The simplified version would be like this.
>
> $locale = ... user defined locale ...// this is done while setting up the
> context
>
> Description: $product.description
> Title: $product.title
>
> As you can see, the whole localized stuff is gone. As far as I can see
> this can be done in two ways: Either I extend the Uberspector to recognize
> the return-type of getDescription and create the correct handler for it,
> or I intercept objects of the type LocaleData with a
> ReferenceInsertionEventHandler, and replace them for their data in the
> correct locale. Both ways though, run into dead ends. Both in the
> Uberspector as the ReferenceInsertionEventHandler the context is not
> available.
>
> I found a spark of hope when I saw
>
>   /**
>     * Execute method against context.
>     */
>    public Object OLDexecute(Object o, InternalContextAdapter context)
>        throws IllegalAccessException, MethodInvocationException
>    { ..
>
> in the GetExecutor. Unfortunatly, it seems to be deprecated, and no longer
> in use.
>
> Anyone has any idea how to accompish automatic parsing of localized data?
>
> Thanks in advance,
> Vincent
>
>
>
>
>
> -- 
> XIAM Solutions B.V.
> Barchman Wuytierslaan 72A
> 3818 LK AMERSFOORT
> tel. : +31(0)33 462 40 07
> e-mail: vincent@nazarene.nl, info@xiam.nl
>
> WAARSCHUWING:
> Dit bericht is UITSLUITEND bestemd voor de (rechts)perso(o)n(en) aan welke
> het bericht is gericht. Het kan vertrouwelijke of alleen voor deze
> rechts)perso(o)n(en) bestemde informatie bevatten, die niet mag worden
> geopenbaard. Als dit bericht niet voor u bestemd is, mag u de ontvangen
> informatie niet lezen, gebruiken, verspreiden of kopiëren. Als u dit
> bericht per abuis heeft ontvangen, gelieve het bericht dan te vernietigen
> en contact op te nemen met de afzender.
>
> WARNING:
> This message is intended ONLY for the person(s) or entity to which it is
> addressed and may contain confidential and/or privileged information, the
> disclosure of which is prohibited. If you are not the intended recipient
> you may not read, use, disseminate or copy the information transmitted. If
> you have received this message by mistake, please contact the sender and
> delete the material from any computer.
>
>
>
> -- 
> No virus found in this outgoing message.
> Checked by AVG Anti-Virus.
> Version: 7.0.300 / Virus Database: 265.6.8 - Release Date: 3-1-2005
>
>
> ---------------------------------------------------------------------
> 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: Context availability during method invocation / ReferenceInsertionEventHandler

Posted by Mike Kienenberger <mk...@alaska.net>.
Vincent van Beveren <vi...@nazarene.nl> wrote:
> I would like to simplify the 
> following piece Velocity code:
> 
> $locale = ... user defined locale ...      // this is done while setting 
> up the context
> 
> Description: $product.description.toString($locale)
> Title: $product.title.toString($locale)
> 
> In which the class product has a method 'getDescription' which returens 
> a home-made object of the class LocaleData. LocaleData is basically a 
> map with as key a locale and as value an object, usually a string. 
> Somewhat like a ResourceBundle (but not quite)
> 
> The simplified version would be like this.
> 
> $locale = ... user defined locale ...// this is done while setting up 
> the context
> 
> Description: $product.description
> Title: $product.title
> 
> Anyone has any idea how to accompish automatic parsing of localized data?

What about setting up a localizer velocity tool helper class that handles 
this for you?

] $localizer = ... helper tool with user defined locale ...// this is done 
while setting up the context
] 
] Description: $localizer.get($product.description)
] Title: $localizer.get($product.title)

Or if you wanted to get the localization completely out of the template, use

] Description: $product.localeDescription
] Title: $product.localeTitle

and have those two methods directly call the localizer helper class.


Note that this is actually a question about the use of velocity and not the 
development of velocity, so I've changed the destination mailing list from 
velocity-dev@jakarta.apache.org to velocity-user@jakarta.apache.org

-Mike

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