use of org.xwiki.velocity.VelocityManager in project xwiki-platform by xwiki.
the class MailSenderPlugin method evaluate.
private String evaluate(String content, String name, VelocityContext vcontext, XWikiContext context) {
StringWriter writer = new StringWriter();
try {
VelocityManager velocityManager = Utils.getComponent(VelocityManager.class);
velocityManager.getVelocityEngine().evaluate(vcontext, writer, name, content);
return writer.toString();
} catch (Exception e) {
LOGGER.error("Error while parsing velocity template namespace [{}]", name, e);
Object[] args = { name };
XWikiException xe = new XWikiException(XWikiException.MODULE_XWIKI_RENDERING, XWikiException.ERROR_XWIKI_RENDERING_VELOCITY_EXCEPTION, "Error while parsing velocity page {0}", e, args);
return Util.getHTMLExceptionMessage(xe, context);
}
}
use of org.xwiki.velocity.VelocityManager in project xwiki-platform by xwiki.
the class DefaultOldRendering method parseContent.
@Override
public String parseContent(String content, XWikiContext xcontext) {
try {
if (StringUtils.isNotEmpty(content)) {
VelocityManager velocityManager = this.velocityManagerProvider.get();
VelocityContext velocityContext = velocityManager.getVelocityContext();
VelocityEngine velocityEngine = velocityManager.getVelocityEngine();
StringWriter writer = new StringWriter();
velocityEngine.evaluate(velocityContext, writer, xcontext.getDoc().getPrefixedFullName(), content);
return writer.toString();
}
} catch (XWikiVelocityException e) {
this.logger.error("Faield to parse content [" + content + "]", e);
}
return "";
}
use of org.xwiki.velocity.VelocityManager in project xwiki-platform by xwiki.
the class IncludeMacroTest method runIncludeMacroWithPreVelocity.
private List<Block> runIncludeMacroWithPreVelocity(Context context, String velocity, String includedContent) throws Exception {
VelocityManager velocityManager = getComponentManager().getInstance(VelocityManager.class);
StringWriter writer = new StringWriter();
velocityManager.getVelocityEngine().evaluate(velocityManager.getVelocityContext(), writer, "wiki:Space.IncludingPage", velocity);
return runIncludeMacro(context, includedContent);
}
use of org.xwiki.velocity.VelocityManager in project xwiki-platform by xwiki.
the class CacheMacroTest method executeWhenNoIdAndSameContent.
@Test
public void executeWhenNoIdAndSameContent() throws Exception {
String expected = "beginDocument\n" + "beginMacroMarkerStandalone [velocity] [] [$var]\n" + "beginParagraph\n" + "onWord [content]\n" + "endParagraph\n" + "endMacroMarkerStandalone [velocity] [] [$var]\n" + "endDocument";
CacheMacroParameters params = new CacheMacroParameters();
MacroTransformationContext context = createMacroTransformationContext();
VelocityManager velocityManager = getComponentManager().getInstance(VelocityManager.class);
StringWriter writer = new StringWriter();
velocityManager.getVelocityEngine().evaluate(velocityManager.getVelocityContext(), writer, "template", "#set ($var = 'content')");
List<Block> result = this.cacheMacro.execute(params, "{{velocity}}$var{{/velocity}}", context);
assertBlocks(expected, result, this.rendererFactory);
// Execute a second time with a different value for the velocity $var variable to ensure the returned result
// is the cached one.
velocityManager.getVelocityEngine().evaluate(velocityManager.getVelocityContext(), writer, "template", "#set ($var = 'newcontent')");
result = this.cacheMacro.execute(params, "{{velocity}}$var{{/velocity}}", context);
assertBlocks(expected, result, this.rendererFactory);
}
use of org.xwiki.velocity.VelocityManager in project xwiki-platform by xwiki.
the class CacheMacroTest method executeWhenSameIdAndDifferentContent.
@Test
public void executeWhenSameIdAndDifferentContent() throws Exception {
String expected = "beginDocument\n" + "beginMacroMarkerStandalone [velocity] [] [$var]\n" + "beginParagraph\n" + "onWord [content]\n" + "endParagraph\n" + "endMacroMarkerStandalone [velocity] [] [$var]\n" + "endDocument";
CacheMacroParameters params = new CacheMacroParameters();
params.setId("uniqueid");
MacroTransformationContext context = createMacroTransformationContext();
VelocityManager velocityManager = getComponentManager().getInstance(VelocityManager.class);
StringWriter writer = new StringWriter();
velocityManager.getVelocityEngine().evaluate(velocityManager.getVelocityContext(), writer, "template", "#set ($var = 'content')");
List<Block> result = this.cacheMacro.execute(params, "{{velocity}}$var{{/velocity}}", context);
assertBlocks(expected, result, this.rendererFactory);
// Execute a second time with a different content but with the same id, to ensure the returned result
// is the cached one.
result = this.cacheMacro.execute(params, "whatever here...", context);
assertBlocks(expected, result, this.rendererFactory);
}
Aggregations