[xwiki-devs] Help getting started on a table-generating extension
I'm appreciate some pointers on getting started on writing an extension component that retrieves data from an external database and presents it as a table. I have reviewed a lot of the available documentation, but must admit to getting a little lost with the various changes in standards, as a lot of the available code and documentation describes macros, which I believe are now deprecated in favour of components. I am happy creating a new component using the Maven archetype, and writing the necessary code to retrieve data from the external database. What I would like help with are: 1) How can I get the current user, so that I can use this contextual information in my query? 2) How should I return the tabular data? I'm sure these are very naïve questions, but please take pity on me and by all means point me at the relevant documentation if it exists already.
Hi 2014-10-02 2:23 GMT+02:00 Bryn Jeffries <[email protected]>:
I'm appreciate some pointers on getting started on writing an extension component that retrieves data from an external database and presents it as a table. I have reviewed a lot of the available documentation, but must admit to getting a little lost with the various changes in standards, as a lot of the available code and documentation describes macros, which I believe are now deprecated in favour of components.
There is a lot of options. You can either: - write a new component indeed, and a script service to expose it to the scripting languages that we have on XWiki: http://extensions.xwiki.org/xwiki/bin/view/Extension/Script+Module - write it directly in Groovy inside the wiki: http://platform.xwiki.org/xwiki/bin/view/DevGuide/Scripting My extension already does something similar, see: http://extensions.xwiki.org/xwiki/bin/view/Extension/SQL+Tools
I am happy creating a new component using the Maven archetype, and writing the necessary code to retrieve data from the external database. What I would like help with are:
1) How can I get the current user, so that I can use this contextual information in my query?
You have this information in the XWikiContext object, that you can inject in your component via a provider. (like this: https://github.com/xwiki/xwiki-platform/blob/master/xwiki-platform-core/xwik... ) If you are scripting, it is $xcontext.user.
2) How should I return the tabular data?
I'm sure these are very naïve questions, but please take pity on me and by all means point me at the relevant documentation if it exists already.
Maybe you should return a Map that you then display with some velocity code in a page.
_______________________________________________ devs mailing list [email protected] http://lists.xwiki.org/mailman/listinfo/devs
I hope it helps, -- Guillaume Delhumeau ([email protected]) Research & Development Engineer at XWiki SAS Committer on the XWiki.org project
Guillaume "Louis-Marie" Delhumeau:
You can either: - write a new component indeed, and a script service to expose it to the scripting languages that we have on XWiki: http://extensions.xwiki.org/xwiki/bin/view/Extension/Script+Module
- write it directly in Groovy inside the wiki: http://platform.xwiki.org/xwiki/bin/view/DevGuide/Scripting My extension already does something similar, see: http://extensions.xwiki.org/xwiki/bin/view/Extension/SQL+Tools
Yes, the Groovy stuff is very impressive. My preference for Java was to restrict access to the code, as I still feel uneasy about the possibility that somebody could hijack the code.
1) How can I get the current user, so that I can use this contextual information in my query?
You have this information in the XWikiContext object, that you can inject in your component via a provider. (like this: https://github.com/xwiki/xwiki-platform/blob/master/xwiki-platform-core/xwik... default/src/main/java/org/xwiki/wiki/internal/manager/DefaultWikiManager.java#L55 )
OK, so this is something that has got me thoroughly confused, since http://platform.xwiki.org/xwiki/bin/view/DevGuide/WritingComponents#HTheXWik... seems to be saying you should not be using xwikicontext any more, but I couldn't see any details about how to do something like get the user from the execution.getContext(). This is one of those areas where the different revisions of various documentation have sent me round in circles :-(
2) How should I return the tabular data?
Maybe you should return a Map that you then display with some velocity code in a page.
OK, good advice, thanks.
Guillaume "Louis-Marie" said:
You can either: - write a new component indeed, and a script service to expose it to the scripting languages that we have on XWiki: http://extensions.xwiki.org/xwiki/bin/view/Extension/Script+Module
- write it directly in Groovy inside the wiki: http://platform.xwiki.org/xwiki/bin/view/DevGuide/Scripting My extension already does something similar, see: http://extensions.xwiki.org/xwiki/bin/view/Extension/SQL+Tools
Looking at this approach more carefully, it looks as though Groovy requires programming privileges, but Velocity does not. So is it possible to write the more sensitive parts in Groovy and then call it from a velocity page with lower privileges?
Hi Bryn, On 2 Oct 2014 at 22:23:35, Bryn Jeffries ([email protected](mailto:[email protected])) wrote:
Guillaume "Louis-Marie" said:
You can either: - write a new component indeed, and a script service to expose it to the scripting languages that we have on XWiki: http://extensions.xwiki.org/xwiki/bin/view/Extension/Script+Module
- write it directly in Groovy inside the wiki: http://platform.xwiki.org/xwiki/bin/view/DevGuide/Scripting My extension already does something similar, see: http://extensions.xwiki.org/xwiki/bin/view/Extension/SQL+Tools
Looking at this approach more carefully, it looks as though Groovy requires programming privileges, but Velocity does not. So is it possible to write the more sensitive parts in Groovy and then call it from a velocity page with lower privileges?
I haven’t followed this thread but I’ll reply to this point only: yes it’s possible. See http://platform.xwiki.org/xwiki/bin/view/DevGuide/Scripting#HSharevariablebe... Thanks -Vincent
On Fri, Oct 3, 2014 at 8:52 AM, [email protected] <[email protected]> wrote:
Hi Bryn,
On 2 Oct 2014 at 22:23:35, Bryn Jeffries ([email protected](mailto:[email protected])) wrote:
Guillaume "Louis-Marie" said:
You can either: - write a new component indeed, and a script service to expose it to the scripting languages that we have on XWiki: http://extensions.xwiki.org/xwiki/bin/view/Extension/Script+Module
- write it directly in Groovy inside the wiki: http://platform.xwiki.org/xwiki/bin/view/DevGuide/Scripting My extension already does something similar, see: http://extensions.xwiki.org/xwiki/bin/view/Extension/SQL+Tools
Looking at this approach more carefully, it looks as though Groovy requires programming privileges, but Velocity does not. So is it possible to write the more sensitive parts in Groovy and then call it from a velocity page with lower privileges?
I haven’t followed this thread but I’ll reply to this point only: yes it’s possible.
See http://platform.xwiki.org/xwiki/bin/view/DevGuide/Scripting#HSharevariablebe...
Except that you need PR in http://platform.xwiki.org/xwiki/bin/view/DevGuide/Scripting#HSharevariablebe... use case since you are going to execute both groovy and velocity. Script service is the best to provide reusable APIs. An alternative not listed by Guillaume depending on what is your need is to put your groovy code in a wiki macro which is then used from any wiki code (in that case only the wiki macro document require programming right). There is several kinds of "macros" in XWiki, wiki macros as in http://platform.xwiki.org/xwiki/bin/view/DevGuide/WikiMacroTutorial as not deprecated, on the contrary (they actually are components).
Thanks -Vincent
_______________________________________________ devs mailing list [email protected] http://lists.xwiki.org/mailman/listinfo/devs
-- Thomas Mortagne
participants (4)
-
Bryn Jeffries -
Guillaume "Louis-Marie" Delhumeau -
Thomas Mortagne -
vincent@massol.net