Beispiel #1
0
        /*
         * CODE FOR ALTERNATE IMPL : please ignore.  I will remove when confortable with current.
         */

        /// <summary>  not used in current impl
        /// *
        /// Constructor for alternate impl where VelProxy class would make new
        /// VMProxyArg objects, and use this contructor to avoid reparsing the
        /// reference args
        /// *
        /// that impl also had the VMProxyArg carry it's context
        /// </summary>
        public VMProxyArg(VMProxyArg model, InternalContextAdapter c)
        {
            usercontext      = c;
            contextReference = model.ContextReference;
            callerReference  = model.CallerReference;
            nodeTree         = model.NodeTree;
            staticObject     = model.StaticObject;
            type             = model.Type;

            if (nodeTree != null)
            {
                numTreeChildren = nodeTree.jjtGetNumChildren();
            }

            if (type == NVelocity.Runtime.Parser.ParserTreeConstants.JJTREFERENCE)
            {
                if (numTreeChildren == 0)
                {
                    /*
                     *  use the reference node to do this...
                     */
                    singleLevelRef = ((ASTReference)nodeTree).RootString;
                }
            }
        }
Beispiel #2
0
        /// <summary>  Parse the input and return the root of the AST node structure.
        /// *
        /// </summary>
        /// <param name="InputStream">inputstream retrieved by a resource loader
        /// </param>
        /// <param name="String">name of the template being parsed
        /// </param>
        /// <param name="dumpNamespace">flag to dump the Velocimacro namespace for this template
        ///
        /// </param>
        public virtual SimpleNode parse(System.IO.TextReader reader, System.String templateName, bool dumpNamespace)
        {
            SimpleNode ast = null;

            Parser.Parser parser  = (Parser.Parser)parserPool.get();
            bool          madeNew = false;

            if (parser == null)
            {
                /*
                 *  if we couldn't get a parser from the pool
                 *  make one and log it.
                 */

                error("Runtime : ran out of parsers. Creating new.  " + " Please increment the parser.pool.size property." + " The current value is too small.");

                parser = createNewParser();

                if (parser != null)
                {
                    madeNew = true;
                }
            }

            /*
             *  now, if we have a parser
             */

            if (parser != null)
            {
                try {
                    /*
                     *  dump namespace if we are told to.  Generally, you want to
                     *  do this - you don't in special circumstances, such as
                     *  when a VM is getting init()-ed & parsed
                     */

                    if (dumpNamespace)
                    {
                        dumpVMNamespace(templateName);
                    }

                    ast = parser.parse(reader, templateName);
                } finally {
                    /*
                     *  if this came from the pool, then put back
                     */
                    if (!madeNew)
                    {
                        parserPool.put(parser);
                    }
                }
            }
            else
            {
                error("Runtime : ran out of parsers and unable to create more.");
            }
            return(ast);
        }
Beispiel #3
0
            internal virtual void  parseTree(InternalContextAdapter ica)
            {
                try {
                    //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(macrobody);

                    nodeTree = Enclosing_Instance.rsvc.parse(br, "VM:" + macroname, true);
                    nodeTree.init(ica, null);
                } catch (System.Exception e) {
                    Enclosing_Instance.rsvc.error("VelocimacroManager.parseTree() : exception " + macroname + " : " + StringUtils.stackTrace(e));
                }
            }
Beispiel #4
0
        /// <summary>
        /// Renders the input reader 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="reader">Reader containing the VTL to be rendered</param>
        /// <returns>true if successful, false otherwise.  If false, see Velocity runtime log</returns>
        public static bool Evaluate(IContext context, TextWriter writer, System.String logTag, TextReader reader)
        {
            SimpleNode nodeTree = null;

            try {
                nodeTree = RuntimeSingleton.parse(reader, logTag);
            } catch (ParseException pex) {
                throw new ParseErrorException(pex.Message);
            }

            /*
             * now we want to init and render
             */

            if (nodeTree != null)
            {
                InternalContextAdapterImpl ica = new InternalContextAdapterImpl(context);

                ica.PushCurrentTemplateName(logTag);

                try {
                    try {
                        nodeTree.init(ica, RuntimeSingleton.RuntimeServices);
                    } catch (System.Exception e) {
                        RuntimeSingleton.error("Velocity.evaluate() : init exception for tag = " + logTag + " : " + e);
                    }

                    /*
                     *  now render, and let any exceptions fly
                     */

                    nodeTree.render(ica, writer);
                } finally {
                    ica.PopCurrentTemplateName();
                }

                return(true);
            }

            return(false);
        }
	/*
	* CODE FOR ALTERNATE IMPL : please ignore.  I will remove when confortable with current.
	*/

	/// <summary>  not used in current impl
	/// *
	/// Constructor for alternate impl where VelProxy class would make new
	/// VMProxyArg objects, and use this contructor to avoid reparsing the
	/// reference args
	/// *
	/// that impl also had the VMProxyArg carry it's context
	/// </summary>
	public VMProxyArg(VMProxyArg model, InternalContextAdapter c) {
	    usercontext = c;
	    contextReference = model.ContextReference;
	    callerReference = model.CallerReference;
	    nodeTree = model.NodeTree;
	    staticObject = model.StaticObject;
	    type = model.Type;

	    if (nodeTree != null)
		numTreeChildren = nodeTree.jjtGetNumChildren();

	    if (type == NVelocity.Runtime.Parser.ParserTreeConstants.JJTREFERENCE) {
		if (numTreeChildren == 0) {
		    /*
		    *  use the reference node to do this...
		    */
		    singleLevelRef = ((ASTReference) nodeTree).RootString;
		}
	    }
	}
	/// <summary>  does the housekeeping upon creationg.  If a dynamic type
	/// it needs to make an AST for further get()/set() operations
	/// Anything else is constant.
	/// </summary>
	private void  setup() {
	    switch (type) {

		case NVelocity.Runtime.Parser.ParserTreeConstants.JJTINTEGERRANGE:
		case NVelocity.Runtime.Parser.ParserTreeConstants.JJTREFERENCE:
		case NVelocity.Runtime.Parser.ParserTreeConstants.JJTOBJECTARRAY:
		case NVelocity.Runtime.Parser.ParserTreeConstants.JJTSTRINGLITERAL:
		case NVelocity.Runtime.Parser.ParserTreeConstants.JJTTEXT: {
			/*
			*  dynamic types, just render
			*/

			constant = false;

			try {
			    /*
			    *  fakie : wrap in  directive to get the parser to treat our args as args
			    *   it doesn't matter that #include() can't take all these types, because we 
			    *   just want the parser to consider our arg as a Directive/VM arg rather than
			    *   as if inline in schmoo
			    */

			    System.String buff = "#include(" + callerReference + " ) ";

			    //ByteArrayInputStream inStream = new ByteArrayInputStream( buff.getBytes() );

			    //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(buff);

			    nodeTree = rsvc.parse(br, "VMProxyArg:" + callerReference, true);

			    /*
			    *  now, our tree really is the first DirectiveArg(), and only one
			    */

			    nodeTree = (SimpleNode) nodeTree.jjtGetChild(0).jjtGetChild(0);

			    /*
			    * sanity check
			    */

			    if (nodeTree != null && nodeTree.Type != type) {
				rsvc.error("VMProxyArg.setup() : programmer error : type doesn't match node type.");
			    }

			    /*
			    *  init.  We can do this as they are only references
			    */

			    nodeTree.init(null, rsvc);
			} catch (System.Exception e) {
			    rsvc.error("VMProxyArg.setup() : exception " + callerReference + " : " + StringUtils.stackTrace(e));
			}

			break;
		    }



		case NVelocity.Runtime.Parser.ParserTreeConstants.JJTTRUE: {
			constant = true;
			staticObject = true;
			break;
		    }



		case NVelocity.Runtime.Parser.ParserTreeConstants.JJTFALSE: {
			constant = true;
			staticObject = false;
			break;
		    }



		case NVelocity.Runtime.Parser.ParserTreeConstants.JJTNUMBERLITERAL: {
			constant = true;
			staticObject = System.Int32.Parse(callerReference);
			break;
		    }



		case NVelocity.Runtime.Parser.ParserTreeConstants.JJTWORD: {
			/*
			*  this is technically an error...
			*/

			rsvc.error("Unsupported arg type : " + callerReference + "  You most likely intended to call a VM with a string literal, so enclose with ' or \" characters. (VMProxyArg.setup())");
			constant = true;
			staticObject = new System.String(callerReference.ToCharArray());

			break;
		    }



		default: {
			rsvc.error(" VMProxyArg.setup() : unsupported type : " + callerReference);
		    }
		    break;

	    }
	}
	    internal virtual void  parseTree(InternalContextAdapter ica) {
		try {
		    //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(macrobody);

		    nodeTree = Enclosing_Instance.rsvc.parse(br, "VM:" + macroname, true);
		    nodeTree.init(ica, null);
		} catch (System.Exception e) {
		    Enclosing_Instance.rsvc.error("VelocimacroManager.parseTree() : exception " + macroname + " : " + StringUtils.stackTrace(e));
		}
	    }
Beispiel #8
0
        /// <summary>  does the housekeeping upon creationg.  If a dynamic type
        /// it needs to make an AST for further get()/set() operations
        /// Anything else is constant.
        /// </summary>
        private void  setup()
        {
            switch (type)
            {
            case NVelocity.Runtime.Parser.ParserTreeConstants.JJTINTEGERRANGE:
            case NVelocity.Runtime.Parser.ParserTreeConstants.JJTREFERENCE:
            case NVelocity.Runtime.Parser.ParserTreeConstants.JJTOBJECTARRAY:
            case NVelocity.Runtime.Parser.ParserTreeConstants.JJTSTRINGLITERAL:
            case NVelocity.Runtime.Parser.ParserTreeConstants.JJTTEXT: {
                /*
                 *  dynamic types, just render
                 */

                constant = false;

                try {
                    /*
                     *  fakie : wrap in  directive to get the parser to treat our args as args
                     *   it doesn't matter that #include() can't take all these types, because we
                     *   just want the parser to consider our arg as a Directive/VM arg rather than
                     *   as if inline in schmoo
                     */

                    System.String buff = "#include(" + callerReference + " ) ";

                    //ByteArrayInputStream inStream = new ByteArrayInputStream( buff.getBytes() );

                    //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(buff);

                    nodeTree = rsvc.parse(br, "VMProxyArg:" + callerReference, true);

                    /*
                     *  now, our tree really is the first DirectiveArg(), and only one
                     */

                    nodeTree = (SimpleNode)nodeTree.jjtGetChild(0).jjtGetChild(0);

                    /*
                     * sanity check
                     */

                    if (nodeTree != null && nodeTree.Type != type)
                    {
                        rsvc.error("VMProxyArg.setup() : programmer error : type doesn't match node type.");
                    }

                    /*
                     *  init.  We can do this as they are only references
                     */

                    nodeTree.init(null, rsvc);
                } catch (System.Exception e) {
                    rsvc.error("VMProxyArg.setup() : exception " + callerReference + " : " + StringUtils.stackTrace(e));
                }

                break;
            }



            case NVelocity.Runtime.Parser.ParserTreeConstants.JJTTRUE: {
                constant     = true;
                staticObject = true;
                break;
            }



            case NVelocity.Runtime.Parser.ParserTreeConstants.JJTFALSE: {
                constant     = true;
                staticObject = false;
                break;
            }



            case NVelocity.Runtime.Parser.ParserTreeConstants.JJTNUMBERLITERAL: {
                constant     = true;
                staticObject = System.Int32.Parse(callerReference);
                break;
            }



            case NVelocity.Runtime.Parser.ParserTreeConstants.JJTWORD: {
                /*
                 *  this is technically an error...
                 */

                rsvc.error("Unsupported arg type : " + callerReference + "  You most likely intended to call a VM with a string literal, so enclose with ' or \" characters. (VMProxyArg.setup())");
                constant     = true;
                staticObject = new System.String(callerReference.ToCharArray());

                break;
            }



            default: {
                rsvc.error(" VMProxyArg.setup() : unsupported type : " + callerReference);
            }
            break;
            }
        }