[xwiki-devs] Programmed Macro with Velocity Inside
Hello All, i use a XWiki.WikiMacroClass with a big Velocity-Script in the "Macro Code"-Section. Now i want to transfer it to a Java-Macro as described in http://rendering.xwiki.org/xwiki/bin/view/Main/ExtendingMacro. I am not sure where i have to place the code inside the Java-Macro. I tried @Inject private MacroContentParser contentParser; and in the method public List<Block> execute(...) { Strong code = "{{velocity}}\n" + "$doc\n"+"{{/velocity}}"; List<Block> result = this.contentParser.parse(code, context, true, context.isInline()).getChildren(); return result; } But this give no code-result back in The Page when i use the macro. Is that the right way? Regards, Matthias -- View this message in context: http://xwiki.475771.n2.nabble.com/Programmed-Macro-with-Velocity-Inside-tp75... Sent from the XWiki- Dev mailing list archive at Nabble.com.
On 11/16/2013 04:42 PM, Matthias Wegner wrote:
Hello All,
i use a XWiki.WikiMacroClass with a big Velocity-Script in the "Macro Code"-Section. Now i want to transfer it to a Java-Macro as described in http://rendering.xwiki.org/xwiki/bin/view/Main/ExtendingMacro. I am not sure where i have to place the code inside the Java-Macro.
I tried
@Inject private MacroContentParser contentParser;
and in the method
public List<Block> execute(...) { Strong code = "{{velocity}}\n" + "$doc\n"+"{{/velocity}}"; List<Block> result = this.contentParser.parse(code, context, true, context.isInline()).getChildren(); return result; }
But this give no code-result back in The Page when i use the macro. Is that the right way?
Since Velocity is a programming language, and Java is a more powerful programming language, the rightest solution is to rewrite the velocity code into Java. Since the method you're calling is named "parse", that's all it does, parse. It doesn't execute anything. Macros are evaluated using transformations (xwiki-rendering-transformation-macro to be more precise). You should use the TransformationManager component to performTransformations if you really want to keep the code in Velocity. -- Sergiu Dumitriu http://purl.org/net/sergiu
Hello Sergiu, for some reason i want to hold the velocity-code. The injection of TransformationManager helps. Perfect. Thanks. Regards, Matthias -- View this message in context: http://xwiki.475771.n2.nabble.com/Programmed-Macro-with-Velocity-Inside-tp75... Sent from the XWiki- Dev mailing list archive at Nabble.com.
participants (2)
-
Matthias Wegner -
Sergiu Dumitriu