Search in sources :

Example 31 with VelocityManager

use of org.xwiki.velocity.VelocityManager in project xwiki-platform by xwiki.

the class XWikiDocument 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);
    }
}
Also used : StringWriter(java.io.StringWriter) VelocityManager(org.xwiki.velocity.VelocityManager) XWikiException(com.xpn.xwiki.XWikiException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) DifferentiationFailedException(org.suigeneris.jrcs.diff.DifferentiationFailedException) ExecutionContextException(org.xwiki.context.ExecutionContextException) ComponentLookupException(org.xwiki.component.manager.ComponentLookupException) MissingParserException(org.xwiki.rendering.parser.MissingParserException) IOException(java.io.IOException) ParseException(org.xwiki.rendering.parser.ParseException) TransformationException(org.xwiki.rendering.transformation.TransformationException) QueryException(org.xwiki.query.QueryException) XWikiException(com.xpn.xwiki.XWikiException)

Aggregations

VelocityManager (org.xwiki.velocity.VelocityManager)31 VelocityContext (org.apache.velocity.VelocityContext)19 Test (org.junit.Test)15 VelocityEngine (org.xwiki.velocity.VelocityEngine)15 StringWriter (java.io.StringWriter)12 DocumentReference (org.xwiki.model.reference.DocumentReference)8 Reader (java.io.Reader)6 DocumentAccessBridge (org.xwiki.bridge.DocumentAccessBridge)5 XWikiException (com.xpn.xwiki.XWikiException)4 BaseObject (com.xpn.xwiki.objects.BaseObject)4 IOException (java.io.IOException)4 Writer (java.io.Writer)4 Map (java.util.Map)4 Properties (java.util.Properties)4 Execution (org.xwiki.context.Execution)4 MacroTransformationContext (org.xwiki.rendering.transformation.MacroTransformationContext)4 XWikiDocument (com.xpn.xwiki.doc.XWikiDocument)3 ByteArrayInputStream (java.io.ByteArrayInputStream)3 Expectations (org.jmock.Expectations)3 Invocation (org.jmock.api.Invocation)3