/// <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="out"> 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 static bool Evaluate(IContext context, TextWriter writer, String logTag, TextReader reader) { SimpleNode nodeTree = null; try { nodeTree = RuntimeSingleton.parse(reader, logTag); } catch (ParseException pex) { throw new ParseErrorException(pex.Message); } /* * now we want to init and render */ if (nodeTree != null) { InternalContextAdapterImpl ica = new InternalContextAdapterImpl(context); ica.PushCurrentTemplateName(logTag); try { try { nodeTree.init(ica, RuntimeSingleton.RuntimeServices); } catch (Exception e) { RuntimeSingleton.error("Velocity.evaluate() : init exception for tag = " + logTag + " : " + e); } /* * now render, and let any exceptions fly */ nodeTree.render(ica, writer); } finally { ica.PopCurrentTemplateName(); } return(true); } return(false); }
/// <summary> Default constructor: sets up the Velocity /// Runtime, creates the visitor for traversing /// the node structure and then produces the /// visual representation by the visitation. /// </summary> public TemplateNodeView(System.String template) { try { RuntimeSingleton.init("velocity.properties"); System.IO.StreamReader isr = new InputStreamReader(new System.IO.FileStream(template, System.IO.FileMode.Open, System.IO.FileAccess.Read), RuntimeSingleton.getString(RuntimeSingleton.INPUT_ENCODING)) ; //UPGRADE_ISSUE: The equivalent of constructor 'java.io.BufferedReader.BufferedReader' is incompatible with the expected type in C#. 'ms-help://MS.VSCC/commoner/redir/redirect.htm?keyword="jlca1109"' System.IO.StreamReader br = new System.IO.StreamReader(isr.BaseStream); document = RuntimeSingleton.parse(br, template) ; visitor = new NodeViewMode(); visitor.Context = null; //UPGRADE_ISSUE: The equivalent of parameter java.lang.System.out is incompatible with the expected type in C#. 'ms-help://MS.VSCC/commoner/redir/redirect.htm?keyword="jlca1109"' visitor.Writer = new System.IO.StreamWriter(System.Console.Out); document.jjtAccept(visitor, null); } catch (System.Exception e) { System.Console.Out.WriteLine(e); SupportClass.WriteStackTrace(e, Console.Error); } }