/// <summary> Visit this node.</summary>
		/// <param name="visitor">The visitor that is visiting this node.
		/// </param>
		public abstract void  Accept(NodeVisitor visitor);
示例#2
0
		/// <summary> Utility to apply a visitor to a node list.
		/// Provides for a visitor to modify the contents of a page and get the
		/// modified HTML as a string with code like this:
		/// <pre>
		/// Parser parser = new Parser ("http://whatever");
		/// NodeList list = parser.parse (null); // no filter
		/// list.visitAllNodesWith (visitor);
		/// System.out.println (list.toHtml ());
		/// </pre>
		/// </summary>
		public virtual void VisitAllNodesWith(NodeVisitor visitor)
		{
			INode node;
			
			visitor.BeginParsing();
			for (int i = 0; i < m_iSize; i++)
			{
				node = nodeData[i];
				node.Accept(visitor);
			}
			visitor.FinishedParsing();
		}
		/// <summary> Default tag visiting code.
		/// Based on <code>isEndTag()</code>, calls either <code>visitTag()</code> or
		/// <code>visitEndTag()</code>.
		/// </summary>
		/// <param name="visitor">The visitor that is visiting this node.
		/// </param>
		public override void  Accept(NodeVisitor visitor)
		{
			if (IsEndTag())
				visitor.VisitEndTag(this as ITag);
			else
				visitor.VisitTag(this as ITag);
		}
		/// <summary> Apply the given visitor to the current page.
		/// The visitor is passed to the <code>accept()</code> method of each node
		/// in the page in a depth first traversal. The visitor
		/// <code>beginParsing()</code> method is called prior to processing the
		/// page and <code>finishedParsing()</code> is called after the processing.
		/// </summary>
		/// <param name="visitor">The visitor to visit all nodes with.
		/// </param>
		/// <throws>  ParserException If a parse error occurs while traversing </throws>
		/// <summary> the page with the visitor.
		/// </summary>
		public virtual void VisitAllNodesWith(NodeVisitor visitor)
		{
			INode node;
			visitor.BeginParsing();
			for (INodeIterator e = Elements(); e.HasMoreNodes(); )
			{
				node = e.NextNode();
				node.Accept(visitor);
			}
			visitor.FinishedParsing();
		}
		/// <summary> String visiting code.</summary>
		/// <param name="visitor">The <code>NodeVisitor</code> object to invoke 
		/// <code>visitStringNode()</code> on.
		/// </param>
		public override void Accept(NodeVisitor visitor)
		{
			visitor.VisitStringNode(this);
		}
示例#6
0
		/// <summary> Tag visiting code.
		/// Invokes <code>accept()</code> on the start tag and then
		/// walks the child list invoking <code>accept()</code> on each
		/// of the children, finishing up with an <code>accept()</code>
		/// call on the end tag. If <code>shouldRecurseSelf()</code>
		/// returns true it then asks the visitor to visit itself.
		/// </summary>
		/// <param name="visitor">The <code>NodeVisitor</code> object to be signalled
		/// for each child and possibly this tag.
		/// </param>
		public override void Accept(NodeVisitor visitor)
		{
			ISimpleNodeIterator children;
			INode child;
			
			if (visitor.ShouldRecurseSelf())
				visitor.VisitTag(this);
			if (visitor.ShouldRecurseChildren())
			{
				if (null != Children)
				{
					children = GetChildren();
					while (children.HasMoreNodes())
					{
						child = children.NextNode();
						child.Accept(visitor);
					}
				}
				if ((null != GetEndTag()) && (this != GetEndTag()))
					// 2nd guard handles <tag/>
					GetEndTag().Accept(visitor);
			}
		}