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
_______________________________________________
devs mailing list
[email protected]
http://lists.xwiki.org/mailman/listinfo/devs

Reply via email to