use of org.apache.wicket.markup.IMarkupFragment 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.IMarkupFragment 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.IMarkupFragment in project wicket by apache.
the class HeaderPartContainer method getScopeFromMarkup.
/**
* @return get "wicket:scope" attribute from <wicket:head> tag
*/
private String getScopeFromMarkup() {
IMarkupFragment markup = getMarkup();
String namespace = markup.getMarkupResourceStream().getWicketNamespace();
ComponentTag tag = (ComponentTag) markup.get(0);
return tag.getAttributes().getString(namespace + ":scope");
}
use of org.apache.wicket.markup.IMarkupFragment in project wicket by apache.
the class MarkupUtil method isMarkupHtml5Compliant.
/**
* @param container
* @return True if the Page and all it's Panels, Borders etc. have HTML5 compliant markup. HTML5
* markup is identified by <DOCTYPE html>
*/
public static boolean isMarkupHtml5Compliant(final MarkupContainer container) {
Args.notNull(container, "container");
Page page = container.getPage();
final boolean[] rtn = new boolean[] { true };
page.visitChildren(MarkupContainer.class, new IVisitor<MarkupContainer, Void>() {
@Override
public void component(final MarkupContainer comp, final IVisit<Void> visit) {
IMarkupFragment associatedMarkup = comp.getAssociatedMarkup();
if (associatedMarkup != null) {
MarkupResourceStream rs = associatedMarkup.getMarkupResourceStream();
if (rs.isHtml5() == false) {
rtn[0] = false;
visit.stop();
}
}
}
});
return rtn[0];
}
use of org.apache.wicket.markup.IMarkupFragment in project wicket by apache.
the class Border method getMarkup.
/**
* Search for the child markup in the file associated with the Border. The child markup must in
* between the <wicket:border> tags.
*/
@Override
public IMarkupFragment getMarkup(final Component child) {
// Border require an associated markup resource file
IMarkupFragment markup = getAssociatedMarkup();
if (markup == null) {
throw new MarkupException("Unable to find associated markup file for Border: " + this.toString());
}
// Find <wicket:border>
IMarkupFragment borderMarkup = null;
for (int i = 0; i < markup.size(); i++) {
MarkupElement elem = markup.get(i);
if (TagUtils.isWicketBorderTag(elem)) {
borderMarkup = new MarkupFragment(markup, i);
break;
}
}
if (borderMarkup == null) {
throw new MarkupException(markup.getMarkupResourceStream(), "Unable to find <wicket:border> tag in associated markup file for Border: " + this.toString());
}
// If child == null, return the markup fragment starting with the <wicket:border> tag
if (child == null) {
return borderMarkup;
}
// Is child == BorderBody?
if (child == body) {
// Get the <wicket:body> markup
return body.getMarkup();
}
// Find the markup for the child component
IMarkupFragment childMarkup = borderMarkup.find(child.getId());
if (childMarkup != null) {
return childMarkup;
}
return ((BorderMarkupSourcingStrategy) getMarkupSourcingStrategy()).findMarkupInAssociatedFileHeader(this, child);
}
Aggregations