use of org.apache.wicket.markup.MarkupException 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.MarkupException 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);
}
use of org.apache.wicket.markup.MarkupException in project wicket by apache.
the class HtmlHandler method postProcess.
@Override
public void postProcess(final Markup markup) {
// If there's still a non-simple tag left, it's an error
while (stack.size() > 0) {
final ComponentTag top = stack.peek();
if (!requiresCloseTag(top.getName())) {
stack.pop();
top.setHasNoCloseTag(true);
} else {
throw new MarkupException(markup, "Tag does not have a close tag", null);
}
}
}
use of org.apache.wicket.markup.MarkupException in project wicket by apache.
the class HtmlHeaderSectionHandler method handleHeadTag.
/**
* Handle tag <head>
* @param tag
*/
private void handleHeadTag(ComponentTag tag) {
// we found <head>
if (tag.isOpen()) {
if (foundHead) {
throw new MarkupException(new MarkupStream(markup), "Tag <head> is not allowed at this position (do you have multiple <head> tags in your markup?).");
}
foundHead = true;
if (tag.getId() == null) {
tag.setId(HEADER_ID);
tag.setAutoComponentTag(true);
tag.setModified(true);
tag.setAutoComponentFactory(HTML_HEADER_FACTORY);
}
} else if (tag.isClose()) {
if (foundHeaderItemsTag) {
// revert the settings from above
ComponentTag headOpenTag = tag.getOpenTag();
// change the id because it is special. See HtmlHeaderResolver
headOpenTag.setId(HEADER_ID + "-Ignored");
headOpenTag.setAutoComponentTag(false);
headOpenTag.setModified(false);
headOpenTag.setFlag(ComponentTag.RENDER_RAW, true);
headOpenTag.setAutoComponentFactory(null);
}
foundClosingHead = true;
}
}
use of org.apache.wicket.markup.MarkupException in project wicket by apache.
the class HtmlHeaderSectionHandler method handleHeaderItemsTag.
/**
* Handle tag <wicket:header-items>
*
* @param tag
*/
private void handleHeaderItemsTag(ComponentTag tag) {
if ((tag.isOpen() || tag.isOpenClose()) && foundHeaderItemsTag) {
throw new MarkupException(new MarkupStream(markup), "More than one <wicket:header-items/> detected in the <head> element. Only one is allowed.");
} else if (foundClosingHead) {
throw new MarkupException(new MarkupStream(markup), "Detected <wicket:header-items/> after the closing </head> element.");
}
foundHeaderItemsTag = true;
tag.setId(HEADER_ID);
tag.setAutoComponentTag(true);
tag.setModified(true);
tag.setAutoComponentFactory(HTML_HEADER_ITEMS_FACTORY);
}
Aggregations