On 02/01/2010 10:41 AM, Jeremie BOUSQUET wrote:
Thanks Vincent,
You're right it will be easier through context...
Do "$context" (velocity) and "context" (groovy) variables refer to
the
application context or to the session context ?
Neither, it's a custom context valid for one request. You can get either
of the session/application context starting from the $request (velocity)
request (groovy) variable, which internally is a HttpServletRequest,
look at its documentation for more details:
http://java.sun.com/j2ee/sdk_1.3/techdocs/api/javax/servlet/http/HttpServle…
Jeremie
2010/2/1 Vincent Massol<vincent(a)massol.net>
> Hi Jeremie,
>
> On Feb 1, 2010, at 10:11 AM, Jeremie BOUSQUET wrote:
>
>> Hi all,
>>
>> I use method parseGroovyFromPage() to instantiate an object from a Groovy
>> class stored in a page.
>>
>> It works well, but now I would like to forbid multiple executions of this
>> class. To do so, I changed it to be a singleton, setting the constructor
> as
>> private.
>> Of course, now, parseGroovyFromPage() returns that the object can't be
>> instantiated ... As the call to the constructor is inside this method, I
>> can't change it to just call getInstance().
>>
>> Are there any workarounds, or other ways to achieve this ?
>
> Why do you need to use this method?
>
> With XWiki Syntax 2.0 we now have the ability to do:
>
> {{include document="groovypage"/}}
>
> where groovypage is a page using the {{groovy}} macro to define groovy
> code.
>
> If you want to forbid several executions of the {{groovy}} script you could
> use an if() inside it and check if a value is present in the session or
> application context (depending if you want it called once per user or per
> application).
--
Sergiu Dumitriu
http://purl.org/net/sergiu/