Ejemplo n.º 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 static bool MergeTemplate(String templateName, String encoding, IContext context, TextWriter writer)
        {
            Template template = RuntimeSingleton.GetTemplate(templateName, encoding);

            if (template == null)
            {
                RuntimeSingleton.Error(string.Format("Velocity.parseTemplate() failed loading template '{0}'", templateName));
                return(false);
            }
            else
            {
                template.Merge(context, writer);
                return(true);
            }
        }
Ejemplo n.º 2
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>
        /// <throws>  ParseErrorException The template could not be parsed. </throws>
        /// <throws>  MethodInvocationException A method on a context object could not be invoked. </throws>
        /// <throws>  ResourceNotFoundException A referenced resource could not be loaded. </throws>
        /// <throws>  Exception Any other exception. </throws>
        /// <summary>
        /// </summary>
        /// <since> Velocity v1.1
        /// </since>

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

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

                return(true);
            }
        }
Ejemplo n.º 3
0
        public static bool MergeTemplate(string templateName, string encoding, IContext context, TextWriter writer)
        {
            Template template = RuntimeSingleton.GetTemplate(templateName, encoding);
            bool     result;

            if (template == null)
            {
                RuntimeSingleton.Error("Velocity.parseTemplate() failed loading template '" + templateName + "'");
                result = false;
            }
            else
            {
                template.Merge(context, writer);
                result = true;
            }
            return(result);
        }
Ejemplo n.º 4
0
 /// <summary>
 /// Returns a <code>Template</code> from the Velocity
 /// resource management system.
 /// </summary>
 /// <param name="name">The file name of the desired template.</param>
 /// <param name="encoding">The character encoding to use for the template.</param>
 /// <returns>The <see cref="Template"/> instance.</returns>
 /// <exception cref="ResourceNotFoundException">
 /// If template is not found from any available source.
 /// </exception>
 /// <exception cref="ParseErrorException">
 /// If template cannot be parsed due to syntax (or other) error.
 /// </exception>
 /// <exception cref="Exception">
 /// If an error occurs in template initialization.
 /// </exception>
 public static Template GetTemplate(String name, String encoding)
 {
     return(RuntimeSingleton.GetTemplate(name, encoding));
 }
Ejemplo n.º 5
0
 /// <summary>
 /// Returns a <code>Template</code> from the Velocity
 /// resource management system.
 /// </summary>
 /// <param name="name">The file name of the desired template.
 /// </param>
 /// <returns>    The template.
 /// @throws ResourceNotFoundException if template not found
 /// from any available source.
 /// @throws ParseErrorException if template cannot be parsed due
 /// to syntax (or other) error.
 /// @throws Exception if an error occurs in template initialization
 /// </returns>
 public static Template GetTemplate(String name)
 {
     return(RuntimeSingleton.GetTemplate(name));
 }