private bool RenderTemplate(Template template, string arg, TextWriter writer, IInternalContextAdapter context) { bool result = true; try { context.PushCurrentTemplateName(arg); ((SimpleNode)template.Data).Render(context, writer); } catch (System.Exception ex) { if (ex is MethodInvocationException) { throw; } this.rsvc.Error(string.Concat(new object[] { "Exception rendering #parse( ", arg, " ) : ", ex })); result = false; } finally { context.PopCurrentTemplateName(); } return(result); }
private bool RenderTemplate(Template template, String arg, TextWriter writer, IInternalContextAdapter context) { bool result = true; try { context.PushCurrentTemplateName(arg); ((SimpleNode)template.Data).Render(context, writer); } catch (Exception) { // if it's a MIE, it came from the render.... throw it... // if (e is MethodInvocationException) throw; // runtimeServices.Error("Exception rendering #parse( " + arg + " ) : " + e); // result = false; } finally { context.PopCurrentTemplateName(); } return(result); }
/// <summary> /// iterates through the argument list and renders every /// argument that is appropriate. Any non appropriate /// arguments are logged, but render() continues. /// </summary> public override bool Render(IInternalContextAdapter context, TextWriter writer, INode node) { // did we get an argument? if (!AssertArgument(node)) { return(false); } // does it have a value? If you have a null reference, then no. Object value; if (!AssertNodeHasValue(node, context, out value)) { return(false); } // get the path String arg = value.ToString(); AssertTemplateStack(context); Resource current = context.CurrentResource; // get the resource, and assume that we use the encoding of the current template // the 'current resource' can be null if we are processing a stream.... String encoding; if (current == null) { encoding = (String)runtimeServices.GetProperty(RuntimeConstants.INPUT_ENCODING); } else { encoding = current.Encoding; } Template template = VelocityManager.Instance.GetTemplateByVirtualPath(arg); try { context.PushCurrentTemplateName(arg); ((SimpleNode)template.Data).Render(context, writer); } catch (Exception) { // if it's a MIE, it came from the render.... throw it... // if (e is MethodInvocationException) throw; // runtimeServices.Error("Exception rendering #parse( " + arg + " ) : " + e); // result = false; } finally { context.PopCurrentTemplateName(); } return(true); }
private bool RenderView(IInternalContextAdapter context, String viewToRender, Template template, TextWriter writer) { try { context.PushCurrentTemplateName(viewToRender); ((SimpleNode)template.Data).Render(context, writer); } finally { context.PopCurrentTemplateName(); } return(true); }
private bool RenderTemplate(Template template, String arg, TextWriter writer, IInternalContextAdapter context) { bool result = true; try { context.PushCurrentTemplateName(arg); ((SimpleNode) template.Data).Render(context, writer); } catch(Exception) { // if it's a MIE, it came from the render.... throw it... // if (e is MethodInvocationException) throw; // runtimeServices.Error("Exception rendering #parse( " + arg + " ) : " + e); // result = false; } finally { context.PopCurrentTemplateName(); } return result; }
private bool RenderView(IInternalContextAdapter context, String viewToRender, Template template, TextWriter writer) { try { context.PushCurrentTemplateName(viewToRender); ((SimpleNode) template.Data).Render(context, writer); } finally { context.PopCurrentTemplateName(); } return true; }
public void PushCurrentTemplateName(String s) { innerContext.PushCurrentTemplateName(s); }
/// <summary> iterates through the argument list and renders every /// argument that is appropriate. Any non appropriate /// arguments are logged, but render() continues. /// </summary> /// <param name="context"> /// </param> /// <param name="writer"> /// </param> /// <param name="node"> /// </param> /// <returns> True if the directive rendered successfully. /// </returns> /// <throws> IOException </throws> /// <throws> ResourceNotFoundException </throws> /// <throws> ParseErrorException </throws> /// <throws> MethodInvocationException </throws> public override bool Render(IInternalContextAdapter context, System.IO.TextWriter writer, INode node) { /* * if rendering is no longer allowed (after a stop), we can safely * skip execution of all the parse directives. */ if (!context.AllowRendering) { return(true); } /* * did we Get an argument? */ if (node.GetChild(0) == null) { rsvc.Log.Error("#parse() null argument"); return(false); } /* * does it have a value? If you have a null reference, then no. */ object value = node.GetChild(0).Value(context); if (value == null) { rsvc.Log.Error("#parse() null argument"); return(false); } /* * Get the path */ string sourcearg = value.ToString(); /* * check to see if the argument will be changed by the event cartridge */ string arg = EventHandlerUtil.IncludeEvent(rsvc, context, sourcearg, context.CurrentTemplateName, Name); /* * a null return value from the event cartridge indicates we should not * input a resource. */ bool blockinput = false; if (arg == null) { blockinput = true; } if (maxDepth > 0) { /* * see if we have exceeded the configured depth. */ object[] templateStack = context.TemplateNameStack; if (templateStack.Length >= maxDepth) { System.Text.StringBuilder path = new System.Text.StringBuilder(); for (int i = 0; i < templateStack.Length; ++i) { path.Append(" > " + templateStack[i]); } rsvc.Log.Error("Max recursion depth reached (" + templateStack.Length + ')' + " File stack:" + path); return(false); } } /* * now use the Runtime resource loader to Get the template */ Template t = null; try { if (!blockinput) { t = rsvc.GetTemplate(arg, GetInputEncoding(context)); } } catch (ResourceNotFoundException rnfe) { /* * the arg wasn't found. Note it and throw */ rsvc.Log.Error("#parse(): cannot find template '" + arg + "', called at " + Log.Log.FormatFileString(this)); throw rnfe; } catch (ParseErrorException pee) { /* * the arg was found, but didn't parse - syntax Error * note it and throw */ rsvc.Log.Error("#parse(): syntax error in #parse()-ed template '" + arg + "', called at " + Log.Log.FormatFileString(this)); throw pee; } /** * pass through application level runtime exceptions */ catch (System.SystemException e) { rsvc.Log.Error("Exception rendering #parse(" + arg + ") at " + Log.Log.FormatFileString(this)); throw e; } catch (System.Exception e) { string msg = "Exception rendering #parse(" + arg + ") at " + Log.Log.FormatFileString(this); rsvc.Log.Error(msg, e); throw new VelocityException(msg, e); } /** * Add the template name to the macro libraries list */ System.Collections.IList macroLibraries = context.MacroLibraries; /** * if macroLibraries are not set create a new one */ if (macroLibraries == null) { macroLibraries = new System.Collections.ArrayList(); } context.MacroLibraries = macroLibraries; macroLibraries.Add(arg); /* * and render it */ try { if (!blockinput) { context.PushCurrentTemplateName(arg); ((SimpleNode)t.Data).Render(context, writer); } } /** * pass through application level runtime exceptions */ catch (System.SystemException e) { /** * LogMessage #parse errors so the user can track which file called which. */ rsvc.Log.Error("Exception rendering #parse(" + arg + ") at " + Log.Log.FormatFileString(this)); throw e; } catch (System.Exception e) { string msg = "Exception rendering #parse(" + arg + ") at " + Log.Log.FormatFileString(this); rsvc.Log.Error(msg, e); throw new VelocityException(msg, e); } finally { if (!blockinput) { context.PopCurrentTemplateName(); } } /* * note - a blocked input is still a successful operation as this is * expected behavior. */ return(true); }
public void PushCurrentTemplateName(string s) { context.PushCurrentTemplateName(s); }