public Tag scan (Tag tag, Lexer lexer, NodeList stack) throws ParserException
{
Node node;
Tag next;
String name;
Scanner scanner;
Tag ret;
ret = tag;
if (ret.isEmptyXmlTag ())
ret.setEndTag (ret);
else
do
{
node = lexer.nextNode (false);
if (null != node)
{
if (node instanceof Tag)
{
next = (Tag)node;
name = next.getTagName ();
// check for normal end tag
if (next.isEndTag () && name.equals (ret.getTagName ()))
{
ret.setEndTag (next);
node = null;
}
else if (isTagToBeEndedFor (ret, next)) // check DTD
{
// backup one node. insert a virtual end tag later
lexer.setPosition (next.getStartPosition ());
node = null;
}
else if (!next.isEndTag ())
{
// now recurse if there is a scanner for this type of tag
scanner = next.getThisScanner ();
if (null != scanner)
{
if (mUseJVMStack)
{ // JVM stack recursion
node = scanner.scan (next, lexer, stack);
addChild (ret, node);
}
else
{
// fake recursion:
if (scanner == this)
{
if (next.isEmptyXmlTag ())
{
next.setEndTag (next);
finishTag (next, lexer);
addChild (ret, next);
}
else
{
stack.add (ret);
ret = next;
}
}
else
{ // normal recursion if switching scanners
node = scanner.scan (next, lexer, stack);
addChild (ret, node);
}
}
}
else