By the way, realizing something, if your objective is to call a macro from velocity to "reinitialize a sandbox", with passing parameters, why don't you just make it a velocity macro ???
In your SandboxTemplate.ReinitSandboxMacro : #macro (reinitSandbox $source $target $doCleanup) ## ... your macro code ... #end And in your scheduler script: {{include reference="SandboxTemplate.ReinitSandboxMacro"/}} ... #reinitSandbox "space1" "space2" "true" You could even make it a wiki macro [1] ... [1] - http://platform.xwiki.org/xwiki/bin/view/DevGuide/WikiMacroTutorial 2014-08-01 16:30 GMT+02:00 Jeremie BOUSQUET <jeremie.bousq...@gmail.com>: > > > > 2014-08-01 16:26 GMT+02:00 Jeremie BOUSQUET <jeremie.bousq...@gmail.com>: > > Hi, >> >> >> 2014-08-01 15:42 GMT+02:00 Pascal BASTIEN <pbasnews-xw...@yahoo.fr>: >> >> Yes, my scheduler can contain: xcontext.put("DoCleanup", "true") >>> >>> >>> xwiki.getDocument("SandboxTemplate.ReinitSandboxMacro").getRenderedContent() >>> or this >>> xcontext.put("source", "SpaceTemplate") >>> xcontext.put("DoCleanup", "true") >>> >>> xwiki.getDocument("SandboxTemplate.ReinitSandboxMacro").getRenderedContent() >>> >>> or >>> xcontext.put("source", "SpaceTemplate") >>> xcontext.put("target", "SpaceToDeleteAndOverwrite") >>> xcontext.put("DoCleanup", "true") >>> >>> xwiki.getDocument("SandboxTemplate.ReinitSandboxMacro").getRenderedContent() >>> >>> >> I would maybe try to replace the "...getRenderedContent()" by an include >> macro [1] like: >> >> {{include reference="SandboxTemplate.ReinitSandboxMacro"/}} >> >> include macro renders the document in same context as container document. >> >> [1] - http://extensions.xwiki.org/xwiki/bin/view/Extension/Include+Macro >> >> >>> >>> And my SandboxTemplate.ReinitSandboxMacro contain this velocity scipt: >>> >>> #if ($request.get('source') != $null) >>> >> >> If from outside you use "$xcontext.put", you can't expect it to be >> available from "$request.get" ;-) >> You should use "$xcontext.get" here instead. >> >> >>> #set ($Source = "$request.get('source')") >>> #else >>> #set ($Source = "SandboxTemplate") >>> #end >>> >>> #if ($request.get('target') != $null) >>> #set ($Target = "$request.get('target')") >>> #else >>> #set ($Target = "Sandbox") >>> #end >>> >>> #if ($request.confirm == 'true' || $xcontext.get("docleanup") == 'true') >>> >>> >> From where would come this "confirm" request param ? >> From a scheduler job there will not be such request parameter ... unless >> you don't talk about the xwiki Scheduler ? [2] >> >> [2] - >> http://extensions.xwiki.org/xwiki/bin/view/Extension/Scheduler+Application >> >> >>> >>> =>My script is launch >>> >>> This test doesn't work >>> #if (xcontext.get("source") != $null) >>> >> >> Anyway you miss the '$' here --> "$xcontext.get("source") ..." >> Personnally I usually prefer to write: >> >> #if ("$!xcontext.get('source')" != "") >> >> ... but it's a matter of taste... >> > > Sorry, not only a matter of taste, that way you check at once if property > is null OR empty string. Depends on what you need of course. > > >> >> >>> #set ($Source = "xcontext.get("source")") >>> #else >>> #set ($Source = "SandboxTemplate") >>> #end >>> >>> >>> To resume: I'm looking for a test to know if a xcontext.get("parameter") >>> exist or not (in a velocity script) >>> >>> >>> >>> >>> ________________________________ >>> De : Thomas Mortagne <thomas.morta...@xwiki.com> >>> À : Pascal BASTIEN <pbasnews-xw...@yahoo.fr>; XWiki Users < >>> users@xwiki.org> >>> Envoyé le : Vendredi 1 août 2014 15h28 >>> Objet : Re: [xwiki-users] How to check $xcontext.get(xxxx) is empty? >>> >>> >>> It's not very clear how exactly are you executing this wiki content >>> with Velocity in it ? Document#getRenderedContent call from Groovy ? >>> >>> >>> On Fri, Aug 1, 2014 at 3:16 PM, Pascal BASTIEN <pbasnews-xw...@yahoo.fr> >>> wrote: >>> > Hello, >>> > >>> > I have "some" difficulty with my groovy/velocity code: >>> > I manage to pass some parameter between my scheduler/groovy script to >>> my velocity code of my page but I need to check in my velocity code if my >>> parameter exist (or not). >>> > >>> http://maven.xwiki.org/site/docs/xwiki-javadoc-4.1.x/com/xpn/xwiki/api/Context.html#get%28java.lang.String%29 >>> > >>> > By exemple, this code doesn't work: >>> > {{velocity}} >>> > #if ( $xcontext.get("DoCleanup")!=$null) >>> > "DoCleanup" parameter doesn't exist >>> > #else >>> > DoCleanup parameter from groovy code is $xcontext.get("DoCleanup") >>> > #end >>> > {{/velocity}} >>> > >>> > >>> http://maven.xwiki.org/site/docs/xwiki-javadoc-4.1.x/com/xpn/xwiki/api/Context.html#get%28java.lang.String%29 >>> return null if user have PR :-( >>> > >>> > In fact, in my velocity code I need to detect who's launch the >>> velocity script: groovy code of scheduler or manually launch by the page >>> containing velocity code. >>> > >>> > Any idea how can I do? >>> > Thxs. >>> > >>> > Pascal B. >>> > _______________________________________________ >>> > users mailing list >>> > users@xwiki.org >>> > http://lists.xwiki.org/mailman/listinfo/users >>> >>> >>> >>> -- >>> Thomas Mortagne >>> _______________________________________________ >>> users mailing list >>> users@xwiki.org >>> http://lists.xwiki.org/mailman/listinfo/users >>> >> >> > _______________________________________________ users mailing list users@xwiki.org http://lists.xwiki.org/mailman/listinfo/users