Exemplo n.º 1
0
        /// <summary>  init : we don't have to do much.  Init the tree (there
        /// shouldn't be one) and then see if interpolation is turned on.
        /// </summary>
        public override Object init(InternalContextAdapter context, Object data)
        {
            /*
             *  simple habit...  we prollie don't have an AST beneath us
             */

            base.init(context, data);

            /*
             *  the stringlit is set at template parse time, so we can
             *  do this here for now.  if things change and we can somehow
             * create stringlits at runtime, this must
             *  move to the runtime execution path
             *
             *  so, only if interpolation is turned on AND it starts
             *  with a " AND it has a  directive or reference, then we
             *  can  interpolate.  Otherwise, don't bother.
             */

            interpolate = rsvc.getBoolean(RuntimeConstants_Fields.INTERPOLATE_STRINGLITERALS, true) && FirstToken.image.StartsWith("\"") && ((FirstToken.image.IndexOf((Char)'$') != -1) || (FirstToken.image.IndexOf((Char)'#') != -1));

            /*
             *  get the contents of the string, minus the '/" at each end
             */

            image = FirstToken.image.Substring(1, (FirstToken.image.Length - 1) - (1));

            /*
             * tack a space on the end (dreaded <MORE> kludge)
             */

            interpolateimage = image + " ";

            if (interpolate)
            {
                /*
                 *  now parse and init the nodeTree
                 */
                //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"'
                TextReader br = new StringReader(interpolateimage);

                /*
                 * it's possible to not have an initialization context - or we don't
                 * want to trust the caller - so have a fallback value if so
                 *
                 *  Also, do *not* dump the VM namespace for this template
                 */

                nodeTree = rsvc.parse(br, (context != null) ? context.CurrentTemplateName : "StringLiteral", false);

                /*
                 *  init with context. It won't modify anything
                 */

                nodeTree.init(context, rsvc);
            }

            return(data);
        }
Exemplo n.º 2
0
        /// <summary> Return name of this Velocimacro.
        /// </summary>

        /// <summary> Velocimacros are always LINE
        /// type directives.
        /// </summary>

        /// <summary>   sets the directive name of this VM
        /// </summary>

        /// <summary>  sets the array of arguments specified in the macro definition
        /// </summary>


        /// <summary>  returns the number of ars needed for this VM
        /// </summary>

        /// <summary>   Sets the orignal macro body.  This is simply the cat of the macroArray, but the
        /// Macro object creates this once during parsing, and everyone shares it.
        /// Note : it must not be modified.
        /// </summary>


        /// <summary>   Renders the macro using the context
        /// </summary>
        public override bool render(InternalContextAdapter context, System.IO.TextWriter writer, INode node)
        {
            try {
                /*
                 *  it's possible the tree hasn't been parsed yet, so get
                 *  the VMManager to parse and init it
                 */

                if (nodeTree != null)
                {
                    if (!init_Renamed_Field)
                    {
                        nodeTree.init(context, rsvc);
                        init_Renamed_Field = true;
                    }

                    /*
                     *  wrap the current context and add the VMProxyArg objects
                     */

                    VMContext vmc = new VMContext(context, rsvc);

                    for (int i = 1; i < argArray.Length; i++)
                    {
                        /*
                         *  we can do this as VMProxyArgs don't change state. They change
                         *  the context.
                         */

                        VMProxyArg arg = (VMProxyArg)proxyArgHash[argArray[i]];
                        vmc.AddVMProxyArg(arg);
                    }

                    /*
                     *  now render the VM
                     */

                    nodeTree.render(vmc, writer);
                }
                else
                {
                    rsvc.error("VM error : " + macroName + ". Null AST");
                }
            } catch (System.Exception e) {
                /*
                 *  if it's a MIE, it came from the render.... throw it...
                 */

                if (e is MethodInvocationException)
                {
                    throw (MethodInvocationException)e;
                }

                rsvc.error("VelocimacroProxy.render() : exception VM = #" + macroName + "() : " + StringUtils.stackTrace(e));
            }

            return(true);
        }
	/// <summary>  init : we don't have to do much.  Init the tree (there
	/// shouldn't be one) and then see if interpolation is turned on.
	/// </summary>
	public override System.Object init(InternalContextAdapter context, System.Object data) {
	    /*
	    *  simple habit...  we prollie don't have an AST beneath us
	    */

	    base.init(context, data);

	    /*
	    *  the stringlit is set at template parse time, so we can 
	    *  do this here for now.  if things change and we can somehow 
	    * create stringlits at runtime, this must
	    *  move to the runtime execution path
	    *
	    *  so, only if interpolation is turned on AND it starts 
	    *  with a " AND it has a  directive or reference, then we 
	    *  can  interpolate.  Otherwise, don't bother.
	    */

	    interpolate = rsvc.getBoolean(NVelocity.Runtime.RuntimeConstants_Fields.INTERPOLATE_STRINGLITERALS, true) && FirstToken.image.StartsWith("\"") && ((FirstToken.image.IndexOf((System.Char) '$') != - 1) || (FirstToken.image.IndexOf((System.Char) '#') != - 1));

	    /*
	    *  get the contents of the string, minus the '/" at each end
	    */

	    image = FirstToken.image.Substring(1, (FirstToken.image.Length - 1) - (1));

	    /*
	    * tack a space on the end (dreaded <MORE> kludge)
	    */

	    interpolateimage = image + " ";

	    if (interpolate) {
		/*
		*  now parse and init the nodeTree
		*/
		//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.TextReader br = new System.IO.StringReader(interpolateimage);

		/*
		* it's possible to not have an initialization context - or we don't
		* want to trust the caller - so have a fallback value if so
		*
		*  Also, do *not* dump the VM namespace for this template
		*/

		nodeTree = rsvc.parse(br, (context != null)?context.CurrentTemplateName:"StringLiteral", false);

		/*
		*  init with context. It won't modify anything
		*/

		nodeTree.init(context, rsvc);
	    }

	    return data;
	}