Ejemplo n.º 1
0
 public static bool MergeTemplate(String templateName, IContext context, TextWriter writer)
 {
     return
         (MergeTemplate(templateName,
                        RuntimeSingleton.getString(RuntimeConstants.INPUT_ENCODING, RuntimeConstants.ENCODING_DEFAULT),
                        context, writer));
 }
Ejemplo n.º 2
0
        public static bool Evaluate(IContext context, TextWriter writer, string logTag, Stream instream)
        {
            TextReader reader = null;
            string     text   = null;

            try
            {
                text   = RuntimeSingleton.getString("input.encoding", "ISO-8859-1");
                reader = new StreamReader(new StreamReader(instream, Encoding.GetEncoding(text)).BaseStream);
            }
            catch (IOException innerException)
            {
                string exceptionMessage = "Unsupported input encoding : " + text + " for template " + logTag;
                throw new ParseErrorException(exceptionMessage, innerException);
            }
            return(Velocity.Evaluate(context, writer, logTag, reader));
        }
Ejemplo n.º 3
0
        public static bool Evaluate(IContext context, TextWriter writer, String logTag, Stream instream)
        {
            // first, parse - convert ParseException if thrown
            TextReader reader   = null;
            String     encoding = null;

            try
            {
                encoding = RuntimeSingleton.getString(RuntimeConstants.INPUT_ENCODING, RuntimeConstants.ENCODING_DEFAULT);
                reader   = new StreamReader(new StreamReader(instream, Encoding.GetEncoding(encoding)).BaseStream);
            }
            catch (IOException ioException)
            {
                String msg = string.Format("Unsupported input encoding : {0} for template {1}", encoding, logTag);
                throw new ParseErrorException(msg, ioException);
            }

            return(Evaluate(context, writer, logTag, reader));
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Renders the input stream 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="instream">input stream containing the VTL to be rendered
        /// </param>
        /// <returns>true if successful, false otherwise.  If false, see
        /// Velocity runtime log
        /// </returns>
        /// <deprecated>Use
        /// {@link #evaluate( Context context, Writer writer,
        /// String logTag, Reader reader ) }
        /// </deprecated>
        public static bool Evaluate(IContext context, TextWriter writer, String logTag, Stream instream)
        {
            /*
             *  first, parse - convert ParseException if thrown
             */

            TextReader reader   = null;
            String     encoding = null;

            try
            {
                encoding = RuntimeSingleton.getString(RuntimeConstants_Fields.INPUT_ENCODING, RuntimeConstants_Fields.ENCODING_DEFAULT);
                reader   = new StreamReader(new StreamReader(instream, Encoding.GetEncoding(encoding)).BaseStream);
            }
            catch (IOException uce)
            {
                String msg = "Unsupported input encoding : " + encoding + " for template " + logTag;
                throw new ParseErrorException(msg);
            }

            return(Evaluate(context, writer, logTag, reader));
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Implementation of IHttpHandler method, called by container upon
        /// loading (is Isreusable returns true, instances may be pooled)
        /// </summary>
        /// <param name="context"></param>
        /// <param name="requestType"></param>
        /// <param name="url"></param>
        /// <param name="pathTranslated"></param>
        public virtual void Init(HttpContext context, String requestType, String url, String pathTranslated)
        {
            this.context        = context;
            this.requestType    = requestType;
            this.url            = url;
            this.pathTranslated = pathTranslated;

            lock (this) {
                if (!initialized)
                {
                    // do whatever we have to do to init Velocity
                    InitVelocity();

                    // we can get these now that velocity is initialized
                    defaultContentType = RuntimeSingleton.getString(CONTENT_TYPE, DEFAULT_CONTENT_TYPE);
                    encoding           = RuntimeSingleton.getString(RuntimeConstants_Fields.OUTPUT_ENCODING, DEFAULT_OUTPUT_ENCODING);

                    initialized = true;
                }
            }

            return;
        }
Ejemplo n.º 6
0
 public static bool MergeTemplate(string templateName, IContext context, TextWriter writer)
 {
     return(Velocity.MergeTemplate(templateName, RuntimeSingleton.getString("input.encoding", "ISO-8859-1"), context, writer));
 }
Ejemplo n.º 7
0
        /// <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);
            }
        }