Example #1
0
        /// <summary>
        /// merges a template and puts the rendered stream into the writer
        /// </summary>
        /// <param name="templateName">name of template to be used in merge</param>
        /// <param name="encoding">encoding used in template</param>
        /// <param name="context"> filled context to be used in merge</param>
        /// <param name="writer"> writer to write template into</param>
        /// <returns>true if successful, false otherwise.  Errors logged to velocity log</returns>
        public bool MergeTemplate(String templateName, String encoding, IContext context, TextWriter writer)
        {
            Template template = runtimeInstance.GetTemplate(templateName, encoding);

            if (template == null)
            {
                runtimeInstance.Error(string.Format("Velocity.parseTemplate() failed loading template '{0}'", templateName));
                return(false);
            }
            else
            {
                template.Merge(context, writer);
                return(true);
            }
        }
        /// <summary>  merges a template and puts the rendered stream into the writer
        ///
        /// </summary>
        /// <param name="templateName">name of template to be used in merge
        /// </param>
        /// <param name="encoding">encoding used in template
        /// </param>
        /// <param name="context"> filled context to be used in merge
        /// </param>
        /// <param name="writer"> writer to write template into
        ///
        /// </param>
        /// <returns> true if successful, false otherwise.  Errors
        /// logged to velocity Log
        /// </returns>
        /// <throws>  ResourceNotFoundException </throws>
        /// <throws>  ParseErrorException </throws>
        /// <throws>  MethodInvocationException </throws>
        /// <throws>  Exception </throws>
        /// <summary>
        /// </summary>
        /// <since> Velocity v1.1
        /// </since>

        public virtual bool MergeTemplate(string templateName, string encoding, IContext context, TextWriter writer)
        {
            Template template = ri.GetTemplate(templateName, encoding);

            if (template == null)
            {
                string msg = "VelocityEngine.mergeTemplate() was unable to load template '" + templateName + "'";
                Log.Error(msg);
                throw new ResourceNotFoundException(msg);
            }
            else
            {
                template.Merge(context, writer);
                return(true);
            }
        }