Ejemplo n.º 1
0
        /* Override this method if you want to customize how the node dumps
         * out its children. */

        public void Dump(String prefix)
        {
            Console.Out.WriteLine(ToString(prefix));
            if (children != null)
            {
                for (int i = 0; i < children.Length; ++i)
                {
                    SimpleNode n = (SimpleNode)children[i];
                    if (n != null)
                    {
                        n.Dump(string.Format("{0} ", prefix));
                    }
                }
            }
        }
Ejemplo n.º 2
0
        public override object Value(IInternalContextAdapter context)
        {
            int         childrenCount = base.ChildrenCount;
            IDictionary dictionary    = new Hashtable();

            for (int i = 0; i < childrenCount; i += 2)
            {
                SimpleNode simpleNode  = (SimpleNode)base.GetChild(i);
                SimpleNode simpleNode2 = (SimpleNode)base.GetChild(i + 1);
                object     key         = (simpleNode == null) ? null : simpleNode.Value(context);
                object     value       = (simpleNode2 == null) ? null : simpleNode2.Value(context);
                dictionary.Add(key, value);
            }
            return(dictionary);
        }
Ejemplo n.º 3
0
        /* Override this method if you want to customize how the node dumps
         *      out its children. */

        public virtual void  dump(System.String prefix)
        {
            System.Console.Out.WriteLine(toString(prefix));
            if (children != null)
            {
                for (int i = 0; i < children.Length; ++i)
                {
                    SimpleNode n = (SimpleNode)children[i];
                    if (n != null)
                    {
                        n.dump(prefix + " ");
                    }
                }
            }
        }
Ejemplo n.º 4
0
 public void Dump(string prefix)
 {
     Console.Out.WriteLine(this.ToString(prefix));
     if (this.children != null)
     {
         for (int i = 0; i < this.children.Length; i++)
         {
             SimpleNode simpleNode = (SimpleNode)this.children[i];
             if (simpleNode != null)
             {
                 simpleNode.Dump(prefix + " ");
             }
         }
     }
 }
Ejemplo n.º 5
0
        private object EvaluateInPlace(string content, IInternalContextAdapter context)
        {
            try
            {
                SimpleNode inlineNode = runtimeServices.Parse(new StringReader(content), context.CurrentTemplateName, false);

                inlineNode.Init(context, runtimeServices);

                return(Evaluate(inlineNode, context));
            }
            catch (Exception)
            {
                throw new ArgumentException(string.Format("Problem evaluating dictionary entry with content {0}", content));
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        /// parses the macro.  We need to do this here, at init time, or else
        /// the local-scope template feature is hard to get to work :)
        /// </summary>
        private void  parseTree(System.String[] callArgs)
        {
            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);

                /*
                 *  now parse the macro - and don't dump the namespace
                 */

                nodeTree = rsvc.parse(br, namespace_Renamed, false);

                /*
                 *  now, to make null references render as proper schmoo
                 *  we need to tweak the tree and change the literal of
                 *  the appropriate references
                 *
                 *  we only do this at init time, so it's the overhead
                 *  is irrelevant
                 */
                Hashtable hm = new Hashtable();

                for (int i = 1; i < argArray.Length; i++)
                {
                    System.String arg = callArgs[i - 1];

                    /*
                     *  if the calling arg is indeed a reference
                     *  then we add to the map.  We ignore other
                     *  stuff
                     */
                    if (arg[0] == '$')
                    {
                        hm[argArray[i]] = arg;
                    }
                }

                /*
                 *  now make one of our reference-munging visitor, and
                 *  let 'er rip
                 */
                VMReferenceMungeVisitor v = new VMReferenceMungeVisitor(hm);
                nodeTree.jjtAccept(v, null);
            } catch (System.Exception e) {
                rsvc.error("VelocimacroManager.parseTree() : exception " + macroName + " : " + StringUtils.stackTrace(e));
            }
        }
Ejemplo n.º 7
0
        /// <seealso cref="NVelocity.Runtime.Paser.Node.SimpleNode.Value(NVelocity.Context.IInternalContextAdapter)">
        /// </seealso>
        public override object Value(IInternalContextAdapter context)
        {
            int size = GetNumChildren();

            System.Collections.IDictionary objectMap = new System.Collections.Hashtable();

            for (int i = 0; i < size; i += 2)
            {
                SimpleNode keyNode   = (SimpleNode)GetChild(i);
                SimpleNode valueNode = (SimpleNode)GetChild(i + 1);

                object key   = (keyNode == null ? null : keyNode.Value(context));
                object value = (valueNode == null ? null : valueNode.Value(context));

                objectMap[key] = value;
            }

            return(objectMap);
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Evaluate the node.
        /// </summary>
        public override Object Value(IInternalContextAdapter context)
        {
            int size = ChildrenCount;

            IDictionary objectMap = new Hashtable();

            for (int i = 0; i < size; i += 2)
            {
                SimpleNode keyNode   = (SimpleNode)GetChild(i);
                SimpleNode valueNode = (SimpleNode)GetChild(i + 1);

                Object key   = (keyNode == null ? null : keyNode.Value(context));
                Object value = (valueNode == null ? null : valueNode.Value(context));

                objectMap.Add(key, value);
            }

            return(objectMap);
        }
Ejemplo n.º 9
0
		/// <summary>  does the housekeeping upon creating.  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 ParserTreeConstants.INTEGER_RANGE:
				case ParserTreeConstants.REFERENCE:
				case ParserTreeConstants.OBJECT_ARRAY:
				case ParserTreeConstants.STRING_LITERAL:
				case ParserTreeConstants.TEXT:
					{
						/*
			*  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
			    */

							String buff = string.Format("#include({0} ) ", 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"'
							TextReader br = new StringReader(buff);

							nodeTree = runtimeServices.Parse(br, string.Format("VMProxyArg:{0}", callerReference), true);

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

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

							/*
			    * sanity check
			    */

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

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

							nodeTree.Init(null, runtimeServices);
						}
						catch(Exception e)
						{
							runtimeServices.Error(string.Format("VMProxyArg.setup() : exception {0} : {1}", callerReference, e));
						}

						break;
					}

				case ParserTreeConstants.TRUE:
					{
						constant = true;
						staticObject = true;
						break;
					}

				case ParserTreeConstants.FALSE:
					{
						constant = true;
						staticObject = false;
						break;
					}

				case ParserTreeConstants.NUMBER_LITERAL:
					{
						constant = true;
						staticObject = Int32.Parse(callerReference);
						break;
					}

				case ParserTreeConstants.WORD:
					{
						/*
						*  this is technically an error...
						*/

						runtimeServices.Error(
							string.Format(
								"Unsupported arg type : {0}  You most likely intended to call a VM with a string literal, so enclose with ' or \" characters. (VMProxyArg.setup())",
								callerReference));
						constant = true;
						staticObject = new String(callerReference.ToCharArray());

						break;
					}

				default:
					{
						runtimeServices.Error(string.Format(" VMProxyArg.setup() : unsupported type : {0}", callerReference));
					}
					break;
			}
		}
Ejemplo n.º 10
0
		/// <summary>
		/// parses the macro.  We need to do this here, at init time, or else
		/// the local-scope template feature is hard to get to work :)
		/// </summary>
		private void parseTree(String[] callArgs)
		{
			try
			{
				TextReader br = new StringReader(macroBody);

				// now parse the macro - and don't dump the namespace
				nodeTree = rsvc.Parse(br, ns, false);

				// now, to make null references render as proper schmoo
				// we need to tweak the tree and change the literal of
				// the appropriate references

				// we only do this at init time, so it's the overhead
				// is irrelevant
				Hashtable hm = new Hashtable();

				for(int i = 1; i < argArray.Length; i++)
				{
					String arg = callArgs[i - 1];

					// if the calling arg is indeed a reference
					// then we add to the map.  We ignore other
					// stuff
					if (arg[0] == '$')
					{
						hm[argArray[i]] = arg;
					}
				}

				// now make one of our reference-munging visitor, and 
				// let 'er rip
				VMReferenceMungeVisitor v = new VMReferenceMungeVisitor(hm);
				nodeTree.Accept(v, null);
			}
			catch(Exception e)
			{
				rsvc.Error("VelocimacroManager.parseTree() : exception " + macroName + " : " + e);
			}
		}
Ejemplo n.º 11
0
	public virtual void RegisterMatch(String xpath, SimpleNode node) {
	    Hashtable foo = new Hashtable();
	    foo["xpath"] = xpath;
	    foo["ast"] = node;
	    xpathList.Add(foo);
	}
Ejemplo n.º 12
0
		/// <summary>Display a SimpleNode
		/// </summary>
		public override Object Visit(SimpleNode node, Object data)
		{
			return ShowNode(node, data);
		}
		private object Evaluate(SimpleNode inlineNode, IInternalContextAdapter context)
		{
			ArrayList values = new ArrayList();

			for(int i = 0; i < inlineNode.ChildrenCount; i++)
			{
				INode node = inlineNode.GetChild(i);

				if (node.Type == ParserTreeConstants.TEXT)
				{
					values.Add(((ASTText) node).Text);
				}
				else
				{
					values.Add(node.Value(context));
				}
			}

			if (values.Count == 0)
			{
				return null;
			}
			else if (values.Count == 1)
			{
				return values[0];
			}
			else
			{
				StringBuilder sb = new StringBuilder();
				foreach(object value in values)
				{
					sb.Append(value);
				}
				return sb.ToString();
			}
		}
Ejemplo n.º 14
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(IInternalContextAdapter context, Object data)
		{
			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 = FirstToken.Image.StartsWith("\"") &&
			              ((FirstToken.Image.IndexOf('$') != - 1) ||
			               (FirstToken.Image.IndexOf('#') != - 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
				*/
				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;
		}
Ejemplo n.º 15
0
		private object Evaluate(SimpleNode inlineNode, IInternalContextAdapter context)
		{
			if (inlineNode.ChildrenCount == 1)
			{
				INode child = inlineNode.GetChild(0);
				return child.Value(context);
			}
			else
			{
				StringBuilder result = new StringBuilder();

				for(int i = 0; i < inlineNode.ChildrenCount; i++)
				{
					INode child = inlineNode.GetChild(i);

					if (child.Type == ParserTreeConstants.REFERENCE)
					{
						result.Append(child.Value(context));
					}
					else
					{
						result.Append(child.Literal);
					}
				}

				return result.ToString();
			}
		}
Ejemplo n.º 16
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>
        /// <param name="context">
        /// </param>
        /// <param name="data">
        /// </param>
        /// <returns> Init result.
        /// </returns>
        /// <throws>  TemplateInitException </throws>
        public override object Init(IInternalContextAdapter 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.INTERPOLATE_STRINGLITERALS, true) && FirstToken.Image.StartsWith("\"") && ((FirstToken.Image.IndexOf('$') != -1) || (FirstToken.Image.IndexOf('#') != -1));

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

            image = FirstToken.Image.Substring(1, (FirstToken.Image.Length - 1) - (1));
            if (FirstToken.Image.StartsWith("\""))
            {
                image = Unescape(image);
            }

            /**
             * note. A kludge on a kludge. The first part, Geir calls this the
             * dreaded <MORE> kludge. Basically, the use of the <MORE> token eats
             * the last character of an interpolated string. EXCEPT when a line
             * comment (##) is in the string this isn't an issue.
             *
             * So, to solve this we look for a line comment. If it isn't found we
             * Add a space here and remove it later.
             */

            /**
             * Note - this should really use a regexp to look for [^\]## but
             * apparently escaping of line comments isn't working right now anyway.
             */
            containsLineComment = (image.IndexOf("##") != -1);

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

            if (!containsLineComment)
            {
                interpolateimage = image + " ";
            }
            else
            {
                interpolateimage = image;
            }

            if (interpolate)
            {
                /*
                 * now parse and Init the nodeTree
                 */
                StringReader 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
                 */

                string templateName = (context != null) ? context.CurrentTemplateName : "StringLiteral";
                try
                {
                    nodeTree = rsvc.Parse(br, templateName, false);
                }
                catch (ParseException e)
                {
                    string msg = "Failed to parse String literal at " + Log.Log.FormatFileString(templateName, Line, Column);
                    throw new TemplateInitException(msg, e, templateName, Column, Line);
                }

                AdjTokenLineNums(nodeTree);

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

                nodeTree.Init(context, rsvc);
            }

            return(data);
        }
Ejemplo n.º 17
0
			internal void parseTree(IInternalContextAdapter 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"'
					TextReader br = new 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 + " : " + e);
				}
			}
Ejemplo n.º 18
0
		/*
	* CODE FOR ALTERNATE IMPL : please ignore.  I will remove when comfortable with current.
	*/

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

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

			if (type == ParserTreeConstants.REFERENCE)
			{
				if (numTreeChildren == 0)
				{
					/*
		    *  use the reference node to do this...
		    */
					singleLevelRef = ((ASTReference) nodeTree).RootString;
				}
			}
		}
            internal void parseTree(IInternalContextAdapter internalContextAdapter)
            {
                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"'
                    TextReader br = new StringReader(macroBody);

                    nodeTree = Enclosing_Instance.runtimeServices.Parse(br, string.Format("VM:{0}", macroName), true);
                    nodeTree.Init(internalContextAdapter, null);
                }
                catch(System.Exception e)
                {
                    Enclosing_Instance.runtimeServices.Error(
                        string.Format("VelocimacroManager.parseTree() : exception {0} : {1}", macroName, e));
                }
            }
	/// <summary>
	/// parses the macro.  We need to do this here, at init time, or else
	/// the local-scope template feature is hard to get to work :)
	/// </summary>
	private void  parseTree(System.String[] callArgs) {
	    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);

		/*
		*  now parse the macro - and don't dump the namespace
		*/

		nodeTree = rsvc.parse(br, namespace_Renamed, false);

		/*
		*  now, to make null references render as proper schmoo
		*  we need to tweak the tree and change the literal of
		*  the appropriate references
		*
		*  we only do this at init time, so it's the overhead
		*  is irrelevant
		*/
		Hashtable hm = new Hashtable();

		for (int i = 1; i < argArray.Length; i++) {
		    System.String arg = callArgs[i - 1];

		    /*
		    *  if the calling arg is indeed a reference
		    *  then we add to the map.  We ignore other
		    *  stuff
		    */
		    if (arg[0] == '$') {
			hm[argArray[i]] = arg;
		    }
		}

		/*
		*  now make one of our reference-munging visitor, and 
		*  let 'er rip
		*/
		VMReferenceMungeVisitor v = new VMReferenceMungeVisitor(hm);
		nodeTree.jjtAccept(v, null);
	    } catch (System.Exception e) {
		rsvc.error("VelocimacroManager.parseTree() : exception " + macroName + " : " + StringUtils.stackTrace(e));
	    }
	}
	/// <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;
	}
Ejemplo n.º 22
0
	public virtual System.Object visit(SimpleNode node, System.Object data) {
	    data = node.childrenAccept(this, data);
	    return data;
	}
Ejemplo n.º 23
0
		public virtual Object Visit(SimpleNode node, Object data)
		{
			data = node.ChildrenAccept(this, data);
			return data;
		}
Ejemplo n.º 24
0
 /// <summary>Display a SimpleNode
 /// </summary>
 public override System.Object visit(SimpleNode node, System.Object data)
 {
     return showNode(node, data);
 }