if ((parentMarkup != null) && (markup != parentMarkup))
{
// The component's markup must be in the same file as its parent
if (markup.getMarkupResourceStream() == parentMarkup.getMarkupResourceStream())
{
MarkupStream stream = new MarkupStream(markup);
stream.skipUntil(ComponentTag.class);
ComponentTag openTag = stream.getTag();
if (openTag != null)
{
MarkupStream parentStream = new MarkupStream(parentMarkup);
if (parentStream.skipUntil(ComponentTag.class))
{
parentStream.next();
}
Stack<ComponentTag> stack = new Stack<ComponentTag>();
while (parentStream.skipUntil(ComponentTag.class))
{
ComponentTag tag = parentStream.getTag();
if (openTag == tag)
{
if (stack.isEmpty() == false)
{
// This tag belong to the real parent
final ComponentTag lastTag = stack.pop();
parent.visitChildren(MarkupContainer.class,
new IVisitor<MarkupContainer, Void>()
{
public void component(final MarkupContainer component,
final IVisit<Void> visit)
{
IMarkupFragment m = component.getMarkup();
MarkupStream ms = new MarkupStream(m);
ms.skipUntil(ComponentTag.class);
if (ms.hasMore() && (lastTag == ms.getTag()))
{
component.add(Component.this);
visit.stop();
}
}