/// <summary> /// Renders the input reader using the context into the output writer. /// To be used when a template is dynamically constructed, or want to /// use Velocity as a token replacer. /// </summary> /// <param name="context">context to use in rendering input string</param> /// <param name="writer"> Writer in which to render the output</param> /// <param name="logTag"> string to be used as the template name for log messages in case of error</param> /// <param name="reader">Reader containing the VTL to be rendered</param> /// <returns>true if successful, false otherwise. If false, see Velocity runtime log</returns> public bool Evaluate(IContext context, TextWriter writer, String logTag, TextReader reader) { SimpleNode nodeTree = null; try { nodeTree = runtimeInstance.Parse(reader, logTag); } catch (ParseException parseException) { throw new ParseErrorException(parseException.Message, parseException); } // now we want to init and render if (nodeTree != null) { InternalContextAdapterImpl internalContextAdapterImpl = new InternalContextAdapterImpl(context); internalContextAdapterImpl.PushCurrentTemplateName(logTag); try { try { nodeTree.Init(internalContextAdapterImpl, runtimeInstance); } catch (Exception e) { runtimeInstance.Error(string.Format("Velocity.evaluate() : init exception for tag = {0} : {1}", logTag, e)); } // now render, and let any exceptions fly nodeTree.Render(internalContextAdapterImpl, writer); } finally { internalContextAdapterImpl.PopCurrentTemplateName(); } return(true); } return(false); }