Exemple #1
0
        /// <summary> renders the value of the string literal If the properties allow, and the
        /// string literal contains a $ or a # the literal is rendered against the
        /// context Otherwise, the stringlit is returned.
        ///
        /// </summary>
        /// <param name="context">
        /// </param>
        /// <returns> result of the rendering.
        /// </returns>
        public override object Value(IInternalContextAdapter context)
        {
            if (interpolate)
            {
                try
                {
                    /*
                     * now render against the real context
                     */

                    StringWriter writer = new StringWriter();
                    nodeTree.Render(context, writer);

                    /*
                     * and return the result as a String
                     */

                    string ret = writer.ToString();

                    /*
                     * if appropriate, remove the space from the end (dreaded <MORE>
                     * kludge part deux)
                     */
                    if (!containsLineComment && ret.Length > 0)
                    {
                        return(ret.Substring(0, (ret.Length - 1) - (0)));
                    }
                    else
                    {
                        return(ret);
                    }
                }

                /**
                 * pass through application level runtime exceptions
                 */
                catch (System.IO.IOException e)
                {
                    string msg = "Error in interpolating string literal";
                    log.Error(msg, e);
                    throw new VelocityException(msg, e);
                }
                catch (System.SystemException e)
                {
                    throw e;
                }
            }

            /*
             * ok, either not allowed to Interpolate, there wasn't a ref or
             * directive, or we failed, so just output the literal
             */

            return(image);
        }
Exemple #2
0
        /// <summary>  renders the value of the string literal
        /// If the properties allow, and the string literal contains a $ or a #
        /// the literal is rendered against the context
        /// Otherwise, the stringlit is returned.
        /// </summary>
        public override Object Value(IInternalContextAdapter context)
        {
            string result = image;

            if (IsDictionaryString(result))
            {
                return(InterpolateDictionaryString(result, context));
            }
            else
            {
                if (interpolate)
                {
                    try
                    {
                        TextWriter writer = new StringWriter();
                        nodeTree.Render(context, writer);

                        /*
                         * and return the result as a String
                         */

                        String ret = writer.ToString();

                        /*
                         *  remove the space from the end (dreaded <MORE> kludge)
                         */

                        result = ret.Substring(0, (ret.Length - 1) - (0));
                    }
                    catch (Exception e)
                    {
                        runtimeServices.Error(string.Format("Error in interpolating string literal : {0}", e));
                        result = image;
                    }
                }

                return(result);
            }
        }