Search in sources :

Example 1 with MarkupException

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;
}
Also used : WicketTag(org.apache.wicket.markup.WicketTag) ComponentTag(org.apache.wicket.markup.ComponentTag) WicketRuntimeException(org.apache.wicket.WicketRuntimeException) MarkupStream(org.apache.wicket.markup.MarkupStream) IMarkupFragment(org.apache.wicket.markup.IMarkupFragment) MarkupException(org.apache.wicket.markup.MarkupException)

Example 2 with MarkupException

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);
}
Also used : BorderMarkupSourcingStrategy(org.apache.wicket.markup.html.panel.BorderMarkupSourcingStrategy) MarkupFragment(org.apache.wicket.markup.MarkupFragment) IMarkupFragment(org.apache.wicket.markup.IMarkupFragment) IMarkupFragment(org.apache.wicket.markup.IMarkupFragment) MarkupElement(org.apache.wicket.markup.MarkupElement) MarkupException(org.apache.wicket.markup.MarkupException)

Example 3 with MarkupException

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);
        }
    }
}
Also used : ComponentTag(org.apache.wicket.markup.ComponentTag) MarkupException(org.apache.wicket.markup.MarkupException)

Example 4 with MarkupException

use of org.apache.wicket.markup.MarkupException in project wicket by apache.

the class HtmlHeaderSectionHandler method handleHeadTag.

/**
 * Handle tag &lt;head&gt;
 * @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;
    }
}
Also used : ComponentTag(org.apache.wicket.markup.ComponentTag) MarkupStream(org.apache.wicket.markup.MarkupStream) MarkupException(org.apache.wicket.markup.MarkupException)

Example 5 with MarkupException

use of org.apache.wicket.markup.MarkupException in project wicket by apache.

the class HtmlHeaderSectionHandler method handleHeaderItemsTag.

/**
 * Handle tag &lt;wicket:header-items&gt;
 *
 * @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);
}
Also used : MarkupStream(org.apache.wicket.markup.MarkupStream) MarkupException(org.apache.wicket.markup.MarkupException)

Aggregations

MarkupException (org.apache.wicket.markup.MarkupException)10 MarkupStream (org.apache.wicket.markup.MarkupStream)5 ComponentTag (org.apache.wicket.markup.ComponentTag)4 IMarkupFragment (org.apache.wicket.markup.IMarkupFragment)4 WicketTag (org.apache.wicket.markup.WicketTag)3 WicketRuntimeException (org.apache.wicket.WicketRuntimeException)2 MarkupElement (org.apache.wicket.markup.MarkupElement)2 MarkupContainer (org.apache.wicket.MarkupContainer)1 Markup (org.apache.wicket.markup.Markup)1 MarkupFragment (org.apache.wicket.markup.MarkupFragment)1 MarkupNotFoundException (org.apache.wicket.markup.MarkupNotFoundException)1 BorderMarkupSourcingStrategy (org.apache.wicket.markup.html.panel.BorderMarkupSourcingStrategy)1 DebugSettings (org.apache.wicket.settings.DebugSettings)1 ExceptionSettings (org.apache.wicket.settings.ExceptionSettings)1 IValueMap (org.apache.wicket.util.value.IValueMap)1