/** * Gets the header part of the Panel/Border. Returns null if it doesn't have a header tag. * * @param container * @param id * @param markup * @return the header part for this panel/border or null if it doesn't have a wicket:head tag. */ private HeaderPartContainer getHeaderPart( final WebMarkupContainer container, final String id, final IMarkupFragment markup) { // Create a HtmlHeaderContainer for the header tag found final MarkupElement element = markup.get(0); if (element instanceof WicketTag) { final WicketTag wTag = (WicketTag) element; if ((wTag.isHeadTag() == true) && (wTag.getNamespace() != null)) { // Create the header container and associate the markup with it return new HeaderPartContainer(id, container, markup); } } throw new WicketRuntimeException( "Programming error: expected a WicketTag: " + markup.toString()); }
/** * Search for <wicket:panel ...> on the same level. * * @param markup * @return null, if not found */ private final IMarkupFragment findStartTag(final IMarkupFragment markup) { MarkupStream stream = new MarkupStream(markup); while (stream.skipUntil(ComponentTag.class)) { ComponentTag tag = stream.getTag(); if (tag.isOpen() || tag.isOpenClose()) { if (tag instanceof WicketTag) { WicketTag wtag = (WicketTag) tag; if (tagName.equalsIgnoreCase(wtag.getName())) { return stream.getMarkupFragment(); } } stream.skipToMatchingCloseTag(tag); } stream.next(); } return null; }
@Override public IMarkupFragment getMarkup() { if (getParent() == null) { throw new WicketRuntimeException( "Bug: The Wicket internal instance of HtmlHeaderContainer is not connected to a parent"); } // Get the page markup IMarkupFragment markup = getPage().getMarkup(); if (markup == null) { throw new MarkupException("Unable to get page markup: " + getPage().toString()); } // Find the markup fragment MarkupStream stream = new MarkupStream(markup); IMarkupFragment headerMarkup = null; while (stream.skipUntil(ComponentTag.class) && (headerMarkup == null)) { ComponentTag tag = stream.getTag(); if (tag.isOpen() || tag.isOpenClose()) { if (tag instanceof WicketTag) { WicketTag wtag = (WicketTag) tag; if (wtag.isHeadTag()) { if (tag.getMarkupClass() == null) { headerMarkup = stream.getMarkupFragment(); } } } else if (tag.getName().equalsIgnoreCase("head")) { headerMarkup = stream.getMarkupFragment(); } } stream.next(); } setMarkup(headerMarkup); return headerMarkup; }
/** * Process next header markup fragment. * * @param associatedMarkupStream * @return index or -1 when done */ private int nextHeaderMarkup(final MarkupStream associatedMarkupStream) { // No associated markup => no header section if (associatedMarkupStream == null) { return -1; } // Scan the markup for <wicket:head>. MarkupElement elem = associatedMarkupStream.get(); while (elem != null) { if (elem instanceof WicketTag) { WicketTag tag = (WicketTag) elem; if (tag.isOpen() && tag.isHeadTag()) { if (noMoreWicketHeadTagsAllowed == true) { throw new MarkupException( "<wicket:head> tags are only allowed before <body>, </head>, <wicket:panel> etc. tag"); } return associatedMarkupStream.getCurrentIndex(); } // wicket:head must be before border, panel or extend // @TODO why is that? Why can't it be anywhere? (except inside wicket:fragment) else if (tag.isOpen() && (tag.isPanelTag() || tag.isBorderTag() || tag.isExtendTag())) { noMoreWicketHeadTagsAllowed = true; } } else if (elem instanceof ComponentTag) { ComponentTag tag = (ComponentTag) elem; // wicket:head must be before </head> // @TODO why?? if (tag.isClose() && TagUtils.isHeadTag(tag)) { noMoreWicketHeadTagsAllowed = true; } // wicket:head must be before <body> // @TODO why?? else if (tag.isOpen() && TagUtils.isBodyTag(tag)) { noMoreWicketHeadTagsAllowed = true; } } elem = associatedMarkupStream.next(); } // No (more) wicket:head found return -1; }