/// <summary> /// ajax method for demo of parsing NVelocity Temp with VelocityEngine /// </summary> /// <param name="template"></param> /// <param name="dirctionary"></param> public void getParseResult(string template,string dirctionary) { if ((template == null) || (dirctionary == null)) { CancelView(); return; } var map=Newtonsoft.Json.JavaScriptConvert.DeserializeObject<Hashtable>(dirctionary); var writer = new System.IO.StringWriter(); var nve = new NVelocity.App.VelocityEngine(); nve.Init(); var context = new NVelocity.VelocityContext(map); nve.Evaluate(context, writer, "", template); RenderText(writer.GetStringBuilder().ToString()); writer.Close(); CancelView(); }
public static bool RenderStringTemplateToString(string templateString, Map dati, out string ret) { NVelocity.App.VelocityEngine engine = new NVelocity.App.VelocityEngine(); engine.Init(); NVelocity.VelocityContext vc = new NVelocity.VelocityContext(dati); StringBuilder sb = new StringBuilder(); string logMsg = null; bool bOk = false; try { using (StringWriter wr = new StringWriter(sb)) using (StringReader rdr = new StringReader(templateString)) bOk = engine.Evaluate(vc, wr, logMsg, rdr); ret = bOk ? sb.ToString() : logMsg; } catch (Exception e) { Logger.Warn("Errore in RenderStringTemplateToString", e); ret = e.Message; } return bOk; }