@Override
public Component resolve(final MarkupContainer container, final MarkupStream markupStream,
final ComponentTag tag)
{
final Page page = container.getPage();
// <head> or <wicket:header-items/> component tags have the id == "_header_"
if (tag.getId().equals(HtmlHeaderSectionHandler.HEADER_ID))
{
// Create a special header component which will gather additional
// input the <head> from 'contributors'.
return newHtmlHeaderContainer(HtmlHeaderSectionHandler.HEADER_ID +
page.getAutoIndex(), tag);
}
else if ((tag instanceof WicketTag) && ((WicketTag)tag).isHeadTag())
{
// If we found <wicket:head> without surrounding <head> on a Page,
// then we have to add wicket:head into a automatically generated
// head first.
if (container instanceof WebPage)
{
HtmlHeaderContainer header = container.visitChildren(new IVisitor<Component, HtmlHeaderContainer>()
{
@Override
public void component(final Component component, final IVisit<HtmlHeaderContainer> visit)
{
if (component instanceof HtmlHeaderContainer)
{
visit.stop((HtmlHeaderContainer) component);
} else if (component instanceof TransparentWebMarkupContainer == false)
{
visit.dontGoDeeper();
}
}
});
// It is <wicket:head>. Because they do not provide any
// additional functionality they are merely a means of surrounding relevant
// markup. Thus we simply create a WebMarkupContainer to handle
// the tag.
WebMarkupContainer wicketHeadContainer = new WicketHeadContainer();
if (header == null)
{
// Create a special header component which will gather
// additional input the <head> from 'contributors'.
header = newHtmlHeaderContainer(HtmlHeaderSectionHandler.HEADER_ID +
page.getAutoIndex(), tag);
header.add(wicketHeadContainer);
return header;
}
header.add(wicketHeadContainer);
return wicketHeadContainer;
}
else if (container instanceof HtmlHeaderContainer)
{
// It is <wicket:head>. Because they do not provide any
// additional functionality there are merely a means of surrounding
// relevant markup. Thus we simply create a WebMarkupContainer to handle
// the tag.
WebMarkupContainer header = new WicketHeadContainer();
return header;
}
final String pageClassName = (page != null) ? page.getClass().getName() : "unknown";
final IResourceStream stream = markupStream.getResource();
final String streamName = (stream != null) ? stream.toString() : "unknown";
throw new MarkupException(
"Mis-placed <wicket:head>. <wicket:head> must be outside of <wicket:panel>, <wicket:border>, " +