[xwiki-devs] Some quesiton regarding development of xwiki macro / extensions / plugins
Hello, To customize our entreprise wiki, we have identified a few plugins / macros that we need to develop. I have checked the online xwiki documentation / tutorial, but i find them quite uncomplete, so here i am with my questions :) 1) It is my understanding that, if my macro need some specific javascript (eg jquery.js) and css, i must use xwiki skin extension. While i can find easily how to create xwiki velocity code that use those extension, i found no explanation on how to do this in java from within "public List<Block> execute(T parameters, String content, MacroTransformationContext context)"? Where can i find example of embedding javascript/css inside a java macro jar or xar? 2) Extensions are provided as xar, maven archetype for xwiki java macro generates a .jar. How do i generate a xar with maven so that in one archive i have both my macro, the css and the js? 3) Most extension referenced on xwiki main site are open source, but where are the source? I can only find the compiled xar files on download 4) Is there some recommanded way to pass complex parameters to macros? I need to create some dynamic menu that will get as parameter a list of node + links + icon to show + subnodes + for each subnodes icons / links + subsubnode etc. Is it good practice to just put some kind of json in the body of macro, something like {{mymenu width="200px"}} [ { name: "node1", link: "MySpace.MyPage1", icon: "somelinktoanattachement"} , { name: "node2", link: "MySpace.MyPage2", icon: "somelinktoanattachement"}, { name: "node3", link: "MySpace.MyPage3", submenu: [ { name: "node3.1", link: "MySpace.MyPage31", icon: "somelinktoanattachement"}, { name: "node3.2", link: "MySpace.MyPage32", icon: "somelinktoanattachement"} ] } ] {{/mymenu}} And in this case, are there already some stock xwiki methode to transform json into objet array? Thank you, David Delbecq
On Tue, Jun 12, 2012 at 3:46 PM, David Delbecq <[email protected]> wrote:
Hello,
To customize our entreprise wiki, we have identified a few plugins / macros that we need to develop. I have checked the online xwiki documentation / tutorial, but i find them quite uncomplete, so here i am with my questions :)
1) It is my understanding that, if my macro need some specific javascript (eg jquery.js) and css, i must use xwiki skin extension. While i can find easily how to create xwiki velocity code that use those extension, i found no explanation on how to do this in java from within "public List<Block> execute(T parameters, String content, MacroTransformationContext context)"? Where can i find example of embedding javascript/css inside a java macro jar or xar?
2) Extensions are provided as xar, maven archetype for xwiki java macro generates a .jar. How do i generate a xar with maven so that in one archive i have both my macro, the css and the js?
No, what we call "extension" can be anything, including jar. They xar and jar are just not put in the same place. A XAR is a set of wiki pages, nothing more.
3) Most extension referenced on xwiki main site are open source, but where are the source? I can only find the compiled xar files on download
There is a source field to put a link on the sources, it's possible some of them are not properly setup and should be fixed. Also a XAR does not contains binary, it's a zip containing pages as XML which are the source too so you always have the sources when talking about a XAR.
4) Is there some recommanded way to pass complex parameters to macros? I need to create some dynamic menu that will get as parameter a list of node + links + icon to show + subnodes + for each subnodes icons / links + subsubnode etc. Is it good practice to just put some kind of json in the body of macro, something like
{{mymenu width="200px"}} [ { name: "node1", link: "MySpace.MyPage1", icon: "somelinktoanattachement"} , { name: "node2", link: "MySpace.MyPage2", icon: "somelinktoanattachement"}, { name: "node3", link: "MySpace.MyPage3", submenu: [ { name: "node3.1", link: "MySpace.MyPage31", icon: "somelinktoanattachement"}, { name: "node3.2", link: "MySpace.MyPage32", icon: "somelinktoanattachement"} ] } ]
{{/mymenu}}
Yes when you need so very advanced data for the macro we generally pass it in the content. See http://extensions.xwiki.org/xwiki/bin/view/Extension/Chart+Macro for example.
And in this case, are there already some stock xwiki methode to transform json into objet array?
I'm sure there is plenty of tools in Java to parse JSON so no need for XWiki to provide an dedicated API for it. In standard XE we embedded http://json-lib.sourceforge.net/ by default which seems to be what you need. What we use generally is wiki table syntax (like in chart macro) and then use the wiki syntax parse to get it. There is no real recommended syntax in general, you need to use what you think is best to represent your datas.
Thank you,
David Delbecq
_______________________________________________ devs mailing list [email protected] http://lists.xwiki.org/mailman/listinfo/devs
-- Thomas Mortagne
On 06/12/2012 09:46 AM, David Delbecq wrote:
Hello,
To customize our entreprise wiki, we have identified a few plugins / macros that we need to develop. I have checked the online xwiki documentation / tutorial, but i find them quite uncomplete, so here i am with my questions :)
1) It is my understanding that, if my macro need some specific javascript (eg jquery.js) and css, i must use xwiki skin extension. While i can find easily how to create xwiki velocity code that use those extension, i found no explanation on how to do this in java from within "public List<Block> execute(T parameters, String content, MacroTransformationContext context)"? Where can i find example of embedding javascript/css inside a java macro jar or xar?
You declare a dependency on the org.xwiki.platform:xwiki-platform-skin-api module in your project, and you declare a dependency on one or more org.xwiki.skinx.SkinExtension fields with the right hint. For example: @Inject @Named("jsrx") private SkinExtension jsrx; Then you can call jsrx.use("jquery.js") if that file is packaged as a resource whenever your macro is used. If you'r
2) Extensions are provided as xar, maven archetype for xwiki java macro generates a .jar. How do i generate a xar with maven so that in one archive i have both my macro, the css and the js?
Not true, extensions can be both jars or xars, depending on what kind of extensions they are. If you're deploying a java macro, then it's right to have a jar extension. A xar is used when you're providing wiki documents that should be installed in the wiki.
3) Most extension referenced on xwiki main site are open source, but where are the source? I can only find the compiled xar files on download
A xar is just a zip file holding wiki documents, and you can always edit those wiki documents to see their "source". A xar is both the source and the binary. Some extensions do have a separate link to a repository if they have one, especially those hosted on the official xwiki or xwiki-contrib repositories.
4) Is there some recommanded way to pass complex parameters to macros? I need to create some dynamic menu that will get as parameter a list of node + links + icon to show + subnodes + for each subnodes icons / links + subsubnode etc. Is it good practice to just put some kind of json in the body of macro, something like
{{mymenu width="200px"}} [ { name: "node1", link: "MySpace.MyPage1", icon: "somelinktoanattachement"} , { name: "node2", link: "MySpace.MyPage2", icon: "somelinktoanattachement"}, { name: "node3", link: "MySpace.MyPage3", submenu: [ { name: "node3.1", link: "MySpace.MyPage31", icon: "somelinktoanattachement"}, { name: "node3.2", link: "MySpace.MyPage32", icon: "somelinktoanattachement"} ] } ]
{{/mymenu}}
Unfortunately, macro calls are in text mode, so you don't have much of a choice. You could define a variable somewhere in Velocity and then read it in Java from the VelocityContext, but that's not very safe and might break in the future.
And in this case, are there already some stock xwiki methode to transform json into objet array?
I'm not sure of the status, but there was a proposal recently to include a JSoN tool in the platform. I think it wasn't committed yet, Reading from http://markmail.org/message/k4izx6re4lvdynx3 I think that you should use the Jackson library, available as a maven dependency from http://search.maven.org/#search|ga|1|a%3A%22jackson-core-lgpl%22
Thank you,
David Delbecq
-- Sergiu Dumitriu http://purl.org/net/sergiu/
On Wed, Jun 13, 2012 at 1:48 AM, Sergiu Dumitriu <[email protected]> wrote:
On 06/12/2012 09:46 AM, David Delbecq wrote:
Hello,
To customize our entreprise wiki, we have identified a few plugins / macros that we need to develop. I have checked the online xwiki documentation / tutorial, but i find them quite uncomplete, so here i am with my questions :)
1) It is my understanding that, if my macro need some specific javascript (eg jquery.js) and css, i must use xwiki skin extension. While i can find easily how to create xwiki velocity code that use those extension, i found no explanation on how to do this in java from within "public List<Block> execute(T parameters, String content, MacroTransformationContext context)"? Where can i find example of embedding javascript/css inside a java macro jar or xar?
You declare a dependency on the org.xwiki.platform:xwiki-platform-skin-api module in your project, and you declare a dependency on one or more org.xwiki.skinx.SkinExtension fields with the right hint. For example:
@Inject @Named("jsrx") private SkinExtension jsrx;
Then you can call jsrx.use("jquery.js") if that file is packaged as a resource whenever your macro is used.
If you'r
2) Extensions are provided as xar, maven archetype for xwiki java macro generates a .jar. How do i generate a xar with maven so that in one archive i have both my macro, the css and the js?
Not true, extensions can be both jars or xars, depending on what kind of extensions they are. If you're deploying a java macro, then it's right to have a jar extension. A xar is used when you're providing wiki documents that should be installed in the wiki.
3) Most extension referenced on xwiki main site are open source, but where are the source? I can only find the compiled xar files on download
A xar is just a zip file holding wiki documents, and you can always edit those wiki documents to see their "source". A xar is both the source and the binary.
Some extensions do have a separate link to a repository if they have one, especially those hosted on the official xwiki or xwiki-contrib repositories.
4) Is there some recommanded way to pass complex parameters to macros? I need to create some dynamic menu that will get as parameter a list of node + links + icon to show + subnodes + for each subnodes icons / links + subsubnode etc. Is it good practice to just put some kind of json in the body of macro, something like
{{mymenu width="200px"}} [ { name: "node1", link: "MySpace.MyPage1", icon: "somelinktoanattachement"} , { name: "node2", link: "MySpace.MyPage2", icon: "somelinktoanattachement"}, { name: "node3", link: "MySpace.MyPage3", submenu: [ { name: "node3.1", link: "MySpace.MyPage31", icon: "somelinktoanattachement"}, { name: "node3.2", link: "MySpace.MyPage32", icon: "somelinktoanattachement"} ] } ]
{{/mymenu}}
Unfortunately, macro calls are in text mode, so you don't have much of a choice.
You could define a variable somewhere in Velocity and then read it in Java from the VelocityContext, but that's not very safe and might break in the future.
And in this case, are there already some stock xwiki methode to transform json into objet array?
I'm not sure of the status, but there was a proposal recently to include a JSoN tool in the platform. I think it wasn't committed yet,
It was committed, http://extensions.xwiki.org/xwiki/bin/view/Extension/Velocity+Module#HJSONTo... , but it is useful in Velocity code. For Java code you should use directly the available JSON library (e.g. json-lib as suggested by Thomas). Hope this helps, Marius
Reading from http://markmail.org/message/k4izx6re4lvdynx3 I think that you should use the Jackson library, available as a maven dependency from http://search.maven.org/#search|ga|1|a%3A%22jackson-core-lgpl%22
Thank you,
David Delbecq
-- Sergiu Dumitriu http://purl.org/net/sergiu/
_______________________________________________ devs mailing list [email protected] http://lists.xwiki.org/mailman/listinfo/devs
i see ssrx and jsrx are for including javascript / css in document. I will also need access to pictures stored in the jar, is there some way to access those? Or will i have to create both a jar (code) + a xar (images attached to a document) ----- Mail original ----- De: "Sergiu Dumitriu" <[email protected]> À: "XWiki Developers" <[email protected]> Envoyé: Mercredi 13 Juin 2012 00:48:25 Objet: Re: [xwiki-devs] Some quesiton regarding development of xwiki macro / extensions / plugins On 06/12/2012 09:46 AM, David Delbecq wrote:
Hello,
To customize our entreprise wiki, we have identified a few plugins / macros that we need to develop. I have checked the online xwiki documentation / tutorial, but i find them quite uncomplete, so here i am with my questions :)
1) It is my understanding that, if my macro need some specific javascript (eg jquery.js) and css, i must use xwiki skin extension. While i can find easily how to create xwiki velocity code that use those extension, i found no explanation on how to do this in java from within "public List<Block> execute(T parameters, String content, MacroTransformationContext context)"? Where can i find example of embedding javascript/css inside a java macro jar or xar?
You declare a dependency on the org.xwiki.platform:xwiki-platform-skin-api module in your project, and you declare a dependency on one or more org.xwiki.skinx.SkinExtension fields with the right hint. For example: @Inject @Named("jsrx") private SkinExtension jsrx; Then you can call jsrx.use("jquery.js") if that file is packaged as a resource whenever your macro is used. If you'r
participants (4)
-
David Delbecq -
Marius Dumitru Florea -
Sergiu Dumitriu -
Thomas Mortagne