{
stack.pop();
}
else
{
throw new WicketParseException("Tag does not have a close tag:", top);
}
}
return tag;
}
if (log.isDebugEnabled())
{
log.debug("tag: " + tag.toUserDebugString() + ", stack: " + stack);
}
// Check tag type
if (tag.isOpen())
{
// Push onto stack
stack.push(tag);
}
else if (tag.isClose())
{
// Check that there is something on the stack
if (stack.size() > 0)
{
// Pop the top tag off the stack
ComponentTag top = stack.pop();
// If the name of the current close tag does not match the
// tag on the stack then we may have a mismatched close tag
boolean mismatch = !top.hasEqualTagName(tag);
if (mismatch)
{
top.setHasNoCloseTag(true);
// Pop any simple tags off the top of the stack
while (mismatch && !requiresCloseTag(top.getName()))
{
top.setHasNoCloseTag(true);
// Pop simple tag
if (stack.isEmpty())
{
break;
}
top = stack.pop();
// Does new top of stack mismatch too?
mismatch = !top.hasEqualTagName(tag);
}
// If adjusting for simple tags did not fix the problem,
// it must be a real mismatch.
if (mismatch)
{
throw new ParseException("Tag " + top.toUserDebugString() +
" has a mismatched close tag at " + tag.toUserDebugString(),
top.getPos());
}
}
// Tag matches, so add pointer to matching tag
tag.setOpenTag(top);
}
else
{
throw new WicketParseException("Tag does not have a matching open tag:", tag);
}
}
else if (tag.isOpenClose())
{
// Tag closes itself