use of org.apache.wicket.markup.MarkupStream in project wicket by apache.
the class HtmlHeaderContainer method getMarkup.
@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)) {
ComponentTag tag = stream.getTag();
if (tag.isOpen() || tag.isOpenClose()) {
if (tag instanceof WicketTag) {
WicketTag wtag = (WicketTag) tag;
if (wtag.isHeadTag() || wtag.isHeaderItemsTag()) {
headerMarkup = stream.getMarkupFragment();
break;
}
} else if (tag.getName().equalsIgnoreCase("head") && tag.isAutoComponentTag()) {
headerMarkup = stream.getMarkupFragment();
break;
}
}
stream.next();
}
setMarkup(headerMarkup);
return headerMarkup;
}
use of org.apache.wicket.markup.MarkupStream in project wicket by apache.
the class AssociatedMarkupSourcingStrategy method renderHeadFromAssociatedMarkupFile.
/**
* Called by components like Panel and Border which have associated Markup and which may have a
* <wicket:head> tag.
* <p>
* Whereas 'this' might be a Panel or Border, the HtmlHeaderContainer parameter has been added
* to the Page as a container for all headers any of its components might wish to contribute to.
* <p>
* The headers contributed are rendered in the standard way.
*
* @param container
* @param htmlContainer
* The HtmlHeaderContainer added to the Page
*/
public final void renderHeadFromAssociatedMarkupFile(final WebMarkupContainer container, final HtmlHeaderContainer htmlContainer) {
// reset for each render in case the strategy is re-used
noMoreWicketHeadTagsAllowed = false;
// Gracefully getAssociateMarkupStream. Throws no exception in case
// markup is not found
final MarkupStream markupStream = container.getAssociatedMarkupStream(false);
if (markupStream == null) {
return;
}
// Position pointer at current (first) header
noMoreWicketHeadTagsAllowed = false;
while (nextHeaderMarkup(markupStream) != -1) {
// found <wicket:head>
String headerId = getHeaderId(container, markupStream);
// Create a HeaderPartContainer and associate the markup
HeaderPartContainer headerPart = getHeaderPart(container, headerId, markupStream.getMarkupFragment());
if (headerPart != null) {
// to the page or any other container in the hierarchy.
if (htmlContainer.okToRenderComponent(headerPart.getScope(), headerPart.getId())) {
// make sure the Page is accessible
headerPart.setParent(htmlContainer);
headerPart.render();
}
}
// Position the stream after <wicket:head>
markupStream.skipComponent();
}
}
use of org.apache.wicket.markup.MarkupStream in project wicket by apache.
the class AssociatedMarkupSourcingStrategy method findMarkupInAssociatedFileHeader.
/**
* Search the child's markup in the header section of the markup
*
* @param container
* @param child
* @return Null, if not found
*/
public IMarkupFragment findMarkupInAssociatedFileHeader(final MarkupContainer container, final Component child) {
// Get the associated markup
IMarkupFragment markup = container.getAssociatedMarkup();
IMarkupFragment childMarkup = null;
// MarkupStream is good at searching markup
MarkupStream stream = new MarkupStream(markup);
while (stream.skipUntil(ComponentTag.class) && (childMarkup == null)) {
ComponentTag tag = stream.getTag();
if (TagUtils.isWicketHeadTag(tag)) {
if (tag.getMarkupClass() == null) {
// find() can still fail an return null => continue the search
childMarkup = stream.getMarkupFragment().find(child.getId());
}
} else if (TagUtils.isHeadTag(tag)) {
// find() can still fail an return null => continue the search
childMarkup = stream.getMarkupFragment().find(child.getId());
}
// Must be a direct child. We are not interested in grand children
if (tag.isOpen() && !tag.hasNoCloseTag()) {
stream.skipToMatchingCloseTag(tag);
}
stream.next();
}
return childMarkup;
}
use of org.apache.wicket.markup.MarkupStream in project wicket by apache.
the class MarkupUtil method findStartTag.
/**
* Searches for {@code tagName} in the given {@code markup}.
*
* @param markup
* @param tagName
* @return The {@link IMarkupFragment} corresponding to {@code tagName}. Null, if such {@code tagName} is not found
*/
public static IMarkupFragment findStartTag(final IMarkupFragment markup, final String tagName) {
MarkupStream stream = new MarkupStream(markup);
while (stream.skipUntil(WicketTag.class)) {
ComponentTag tag = stream.getTag();
if (tag.isOpen() || tag.isOpenClose()) {
WicketTag wtag = (WicketTag) tag;
if (tagName.equalsIgnoreCase(wtag.getName())) {
return stream.getMarkupFragment();
}
stream.skipToMatchingCloseTag(tag);
}
stream.next();
}
return null;
}
use of org.apache.wicket.markup.MarkupStream in project wicket by apache.
the class TransparentWebMarkupContainer method renderHeadForInnerSiblings.
/**
* Renders head for embedded component, i.e. those who are not added
* directly to this container but have the markup inside it.
*
* @param container
* The HtmlHeaderContainer
*/
private void renderHeadForInnerSiblings(HtmlHeaderContainer container) {
MarkupStream stream = new MarkupStream(getMarkup());
while (stream.isCurrentIndexInsideTheStream()) {
MarkupElement childOpenTag = stream.nextOpenTag();
if ((childOpenTag instanceof ComponentTag) && !stream.atCloseTag()) {
// Get element as tag
final ComponentTag tag = (ComponentTag) childOpenTag;
// Get component id
final String id = tag.getId();
Component component = null;
if (get(id) == null) {
component = ComponentResolvers.resolveByComponentHierarchy(this, stream, tag);
}
if (component != null) {
component.internalRenderHead(container);
}
// consider just direct children
stream.skipToMatchingCloseTag(tag);
}
}
}
Aggregations