[Proposal] Use JSON in Wiki Components

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

[Proposal] Use JSON in Wiki Components

Guillaume Delhumeau
Hi devs.

In XWiki, we have the ability to create wiki components. It means that each
extension can define a custom XClass which is used to create a component
when a corresponding XObject exists.

Sometimes, this XObject contains a textarea where the developer could write
velocity code. The velocity code is rendered, and the result is parsed in
order to complete other actions. For example, velocity can render a
boolean, or a list of documents, etc... The reason why Velocity is used is
because it does not require programming rights. On the other-side, it can
only return a string: the rendered content.

My use-case is to generate a specific list of users when an event is
triggered, to perform some actions with these users.

Currently, we have no recommended practice about this
"velocity-rendered-fields".

That's what I propose to always use JSON when velocity is used to render
data in a wiki component. The reason is that JSON is standard and easy to
parse.

Use case:
In the Event Stream module [1], the XClass
"XWiki.EventStream.Code.EventClass" is used to trigger custom events when
some event occurs.
Example: if a DocumentUpdatedEvent is triggered and that event contains an
XObject of type "Meeting", you can send a new "Meeting Created" event.
There is a "Validation Expression" field used to determine either or not
the custom event should be sent. Now I need to add an other field to
determine which user should receive the event notifications. For example:
if userA and userB have been invited to MeetingC, I need to send an event
"Meeting Created" only for user A and user B.

Here is my +1,

Thanks,

[1]
http://extensions.xwiki.org/xwiki/bin/view/Extension/Event%20Stream%20Module#HDefinecustomeventsinwikipages

--
Guillaume Delhumeau ([hidden email])
Research & Development Engineer at XWiki SAS
Committer on the XWiki.org project
Reply | Threaded
Open this post in threaded view
|

Re: [Proposal] Use JSON in Wiki Components

Thomas Mortagne
Administrator
On Wed, Jan 3, 2018 at 4:02 PM, Guillaume Delhumeau
<[hidden email]> wrote:

> Hi devs.
>
> In XWiki, we have the ability to create wiki components. It means that each
> extension can define a custom XClass which is used to create a component
> when a corresponding XObject exists.
>
> Sometimes, this XObject contains a textarea where the developer could write
> velocity code. The velocity code is rendered, and the result is parsed in
> order to complete other actions. For example, velocity can render a
> boolean, or a list of documents, etc... The reason why Velocity is used is
> because it does not require programming rights. On the other-side, it can
> only return a string: the rendered content.

Actually this is not true, you can "return" anything you want using
$output.setValue($someStuff).

>
> My use-case is to generate a specific list of users when an event is
> triggered, to perform some actions with these users.
>
> Currently, we have no recommended practice about this
> "velocity-rendered-fields".
>
> That's what I propose to always use JSON when velocity is used to render
> data in a wiki component. The reason is that JSON is standard and easy to
> parse.
>
> Use case:
> In the Event Stream module [1], the XClass
> "XWiki.EventStream.Code.EventClass" is used to trigger custom events when
> some event occurs.
> Example: if a DocumentUpdatedEvent is triggered and that event contains an
> XObject of type "Meeting", you can send a new "Meeting Created" event.
> There is a "Validation Expression" field used to determine either or not
> the custom event should be sent. Now I need to add an other field to
> determine which user should receive the event notifications. For example:
> if userA and userB have been invited to MeetingC, I need to send an event
> "Meeting Created" only for user A and user B.
>
> Here is my +1,
>
> Thanks,
>
> [1]
> http://extensions.xwiki.org/xwiki/bin/view/Extension/Event%20Stream%20Module#HDefinecustomeventsinwikipages
>
> --
> Guillaume Delhumeau ([hidden email])
> Research & Development Engineer at XWiki SAS
> Committer on the XWiki.org project



--
Thomas Mortagne
Reply | Threaded
Open this post in threaded view
|

Re: [Proposal] Use JSON in Wiki Components

Thomas Mortagne
Administrator
On Wed, Jan 3, 2018 at 4:30 PM, Thomas Mortagne
<[hidden email]> wrote:

> On Wed, Jan 3, 2018 at 4:02 PM, Guillaume Delhumeau
> <[hidden email]> wrote:
>> Hi devs.
>>
>> In XWiki, we have the ability to create wiki components. It means that each
>> extension can define a custom XClass which is used to create a component
>> when a corresponding XObject exists.
>>
>> Sometimes, this XObject contains a textarea where the developer could write
>> velocity code. The velocity code is rendered, and the result is parsed in
>> order to complete other actions. For example, velocity can render a
>> boolean, or a list of documents, etc... The reason why Velocity is used is
>> because it does not require programming rights. On the other-side, it can
>> only return a string: the rendered content.
>
> Actually this is not true, you can "return" anything you want using
> $output.setValue($someStuff).

actually $xcontext.method.output

See http://extensions.xwiki.org/xwiki/bin/view/Extension/WikiComponent%20Module#HImplementingmethods

>
>>
>> My use-case is to generate a specific list of users when an event is
>> triggered, to perform some actions with these users.
>>
>> Currently, we have no recommended practice about this
>> "velocity-rendered-fields".
>>
>> That's what I propose to always use JSON when velocity is used to render
>> data in a wiki component. The reason is that JSON is standard and easy to
>> parse.
>>
>> Use case:
>> In the Event Stream module [1], the XClass
>> "XWiki.EventStream.Code.EventClass" is used to trigger custom events when
>> some event occurs.
>> Example: if a DocumentUpdatedEvent is triggered and that event contains an
>> XObject of type "Meeting", you can send a new "Meeting Created" event.
>> There is a "Validation Expression" field used to determine either or not
>> the custom event should be sent. Now I need to add an other field to
>> determine which user should receive the event notifications. For example:
>> if userA and userB have been invited to MeetingC, I need to send an event
>> "Meeting Created" only for user A and user B.
>>
>> Here is my +1,
>>
>> Thanks,
>>
>> [1]
>> http://extensions.xwiki.org/xwiki/bin/view/Extension/Event%20Stream%20Module#HDefinecustomeventsinwikipages
>>
>> --
>> Guillaume Delhumeau ([hidden email])
>> Research & Development Engineer at XWiki SAS
>> Committer on the XWiki.org project
>
>
>
> --
> Thomas Mortagne



--
Thomas Mortagne
Reply | Threaded
Open this post in threaded view
|

Re: [Proposal] Use JSON in Wiki Components

Thomas Mortagne
Administrator
Sorry I tough your were talking about the default wiki component implementation.

Anyway any custom wiki component can easily do the same thing (check
the ScriptContext for some special "return" binding) and we could
provide an API that does that automatically in TemplateManager for
example.

On Wed, Jan 3, 2018 at 4:32 PM, Thomas Mortagne
<[hidden email]> wrote:

> On Wed, Jan 3, 2018 at 4:30 PM, Thomas Mortagne
> <[hidden email]> wrote:
>> On Wed, Jan 3, 2018 at 4:02 PM, Guillaume Delhumeau
>> <[hidden email]> wrote:
>>> Hi devs.
>>>
>>> In XWiki, we have the ability to create wiki components. It means that each
>>> extension can define a custom XClass which is used to create a component
>>> when a corresponding XObject exists.
>>>
>>> Sometimes, this XObject contains a textarea where the developer could write
>>> velocity code. The velocity code is rendered, and the result is parsed in
>>> order to complete other actions. For example, velocity can render a
>>> boolean, or a list of documents, etc... The reason why Velocity is used is
>>> because it does not require programming rights. On the other-side, it can
>>> only return a string: the rendered content.
>>
>> Actually this is not true, you can "return" anything you want using
>> $output.setValue($someStuff).
>
> actually $xcontext.method.output
>
> See http://extensions.xwiki.org/xwiki/bin/view/Extension/WikiComponent%20Module#HImplementingmethods
>
>>
>>>
>>> My use-case is to generate a specific list of users when an event is
>>> triggered, to perform some actions with these users.
>>>
>>> Currently, we have no recommended practice about this
>>> "velocity-rendered-fields".
>>>
>>> That's what I propose to always use JSON when velocity is used to render
>>> data in a wiki component. The reason is that JSON is standard and easy to
>>> parse.
>>>
>>> Use case:
>>> In the Event Stream module [1], the XClass
>>> "XWiki.EventStream.Code.EventClass" is used to trigger custom events when
>>> some event occurs.
>>> Example: if a DocumentUpdatedEvent is triggered and that event contains an
>>> XObject of type "Meeting", you can send a new "Meeting Created" event.
>>> There is a "Validation Expression" field used to determine either or not
>>> the custom event should be sent. Now I need to add an other field to
>>> determine which user should receive the event notifications. For example:
>>> if userA and userB have been invited to MeetingC, I need to send an event
>>> "Meeting Created" only for user A and user B.
>>>
>>> Here is my +1,
>>>
>>> Thanks,
>>>
>>> [1]
>>> http://extensions.xwiki.org/xwiki/bin/view/Extension/Event%20Stream%20Module#HDefinecustomeventsinwikipages
>>>
>>> --
>>> Guillaume Delhumeau ([hidden email])
>>> Research & Development Engineer at XWiki SAS
>>> Committer on the XWiki.org project
>>
>>
>>
>> --
>> Thomas Mortagne
>
>
>
> --
> Thomas Mortagne



--
Thomas Mortagne