[xwiki-users] Using a local class within a wiki page
Why does a page containing just the following produce no output?: {{groovy}} class Callee { void hello() { println "hello, world" } } c = new Callee() c.hello() {{/groovy}} I have programming rights, and running scripts in general works fine. It's just when I try to invoke a method from a locally defined class that I hit problems.
On 18 Dec 2014 at 22:10:54, Bryn Jeffries ([email protected](mailto:[email protected])) wrote:
Why does a page containing just the following produce no output?:
{{groovy}} class Callee { void hello() { println "hello, world" } } c = new Callee() c.hello() {{/groovy}}
Actually this is a good question! I don’t know… I’ve tried it in the groovy web console and it works so it’s something specific to the way XWiki uses Groovy. Could be because that we use the Scripting API (JSR 223) to access Groovy. It probably means that the output is not wired when inside the class scope but I’m not sure why… The method is invoked for since the following works fine: {{groovy}} class Callee { String hello() { return "hello, world" } } c = new Callee() println c.hello() {{/groovy}} If someone has an idea… Thanks -Vincent
I have programming rights, and running scripts in general works fine. It's just when I try to invoke a method from a locally defined class that I hit problems.
Ok I think I know... Actually the message is printed in the console. You see something in the page only if you print in the global scope because this is what gets returned by script evaluation. Calling “println” in a class doesn’t return anything in the evaluation and thus you don’t see anything. That’s why the examples at http://extensions.xwiki.org/xwiki/bin/view/Extension/Groovy+Macro work. Thanks -Vincent On 18 Dec 2014 at 22:10:54, Bryn Jeffries ([email protected](mailto:[email protected])) wrote:
Why does a page containing just the following produce no output?:
{{groovy}} class Callee { void hello() { println "hello, world" } } c = new Callee() c.hello() {{/groovy}}
Actually this is a good question! I don’t know… I’ve tried it in the groovy web console and it works so it’s something specific to the way XWiki uses Groovy. Could be because that we use the Scripting API (JSR 223) to access Groovy. It probably means that the output is not wired when inside the class scope but I’m not sure why… The method is invoked for since the following works fine: {{groovy}} class Callee { String hello() { return "hello, world" } } c = new Callee() println c.hello() {{/groovy}} If someone has an idea… Thanks -Vincent
I have programming rights, and running scripts in general works fine. It's just when I try to invoke a method from a locally defined class that I hit problems.
Vincent Massol said:
Ok I think I know... Actually the message is printed in the console. You see something in the page only if you print in the global scope because this is what gets returned by script evaluation. Calling “println” in a class doesn’t return anything in the evaluation and thus you don’t see anything. That’s why the examples at http://extensions.xwiki.org/xwiki/bin/view/Extension/Groovy+Macro work.
Right, makes sense. So looks like the best fix is to return the string and print it from global (script) scope. This works: {{groovy}} class Callee { def hello() { return "hello, world" } } c = new Callee() println c.hello() {{/groovy}}
Ok I’ve discussed with Guillaume Laforge from Groovy fame and here are more details: * In our code we capture the output of the script and use it to display the rendered page so any println located directly in the script will work. * However for a println in a Class, Groovy call System.out.println(…) - which is why it goes in the xwiki logs - and we would need to capture that in a thread safe way to redirect it to the page rendering this is a bit more involved: ** Use System.set(PrintStream) with a custom PrintStream that would use for example a threadlocal variable to direct the content to our page being rendered ** Use Groovy’s runtime metaprogramming feature, for example: PrintStream.metaClass.println = { String s -> ...handle thread safety here.. }. ** Use Groovy’s compile-time metaprogramming feature and implement a Groovy AST Transformation to transform all println calls into something else. For example by adding a binding to the ScriptContext and using that binding instead of println. This requires using a CompilationCustomizer (we already do that in XWiki btw) which returns an ASTTransformationCustomizer to do the work. Thanks -Vincent On 19 Dec 2014 at 00:10:18, Bryn Jeffries ([email protected](mailto:[email protected])) wrote:
Vincent Massol said:
Ok I think I know... Actually the message is printed in the console. You see something in the page only if you print in the global scope because this is what gets returned by script evaluation. Calling “println” in a class doesn’t return anything in the evaluation and thus you don’t see anything. That’s why the examples at http://extensions.xwiki.org/xwiki/bin/view/Extension/Groovy+Macro work.
Right, makes sense. So looks like the best fix is to return the string and print it from global (script) scope. This works:
{{groovy}} class Callee { def hello() { return "hello, world" } } c = new Callee() println c.hello() {{/groovy}}
Hi all, I’m trying to get us migrated from several installations of MediaWiki to one XWiki. I have installed XWiki 6.3 just fine… but the big problem is migrating the data over. So far all the options I’ve found have been sorely lacking. -The method provided on the Encodo blog, uses the XMLRPC API which has since been deprecated -The Mediawiki to Xwiki Migration Toolkit requires setting up an entire development environment with a special customized version of XWiki just to do the import, which is unnecessarily complex and error-prone. -A few other methods which may work, but omit portions such as history. Is there a relatively simple batch import mechanism that works with the current versions of xwiki, or am I relegated to importing stuff manually? I *could* write my own import tool, but if I have to go that route we may as well just do it manually because we will need to audit and clean up the articles anyway. Ilsa
Last time I did a mediawiki import I used https://github.com/xwiki-contrib/sandbox/tree/master/xwiki-wikiimporter, worked reasonably well but yes there is no release of it (but it's easy to build it with Maven). Ideally someone need to spend some time converting and improving the mediawiki part it as an input module for the new XWiki Filter module (see http://extensions.xwiki.org/xwiki/bin/view/Extension/Filter+Module). On Fri, Dec 19, 2014 at 5:08 PM, Ilsa Loving <[email protected]> wrote:
Hi all,
I’m trying to get us migrated from several installations of MediaWiki to one XWiki. I have installed XWiki 6.3 just fine… but the big problem is migrating the data over.
So far all the options I’ve found have been sorely lacking.
-The method provided on the Encodo blog, uses the XMLRPC API which has since been deprecated -The Mediawiki to Xwiki Migration Toolkit requires setting up an entire development environment with a special customized version of XWiki just to do the import, which is unnecessarily complex and error-prone. -A few other methods which may work, but omit portions such as history.
Is there a relatively simple batch import mechanism that works with the current versions of xwiki, or am I relegated to importing stuff manually? I *could* write my own import tool, but if I have to go that route we may as well just do it manually because we will need to audit and clean up the articles anyway.
Ilsa
_______________________________________________ users mailing list [email protected] http://lists.xwiki.org/mailman/listinfo/users
-- Thomas Mortagne
participants (4)
-
Bryn Jeffries -
Ilsa Loving -
Thomas Mortagne -
vincent@massol.net