Search in sources :

Example 1 with IMarkupFragment

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;
}
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 IMarkupFragment

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

Example 3 with IMarkupFragment

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

Example 4 with IMarkupFragment

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];
}
Also used : MarkupContainer(org.apache.wicket.MarkupContainer) Page(org.apache.wicket.Page) MarkupResourceStream(org.apache.wicket.markup.MarkupResourceStream) IMarkupFragment(org.apache.wicket.markup.IMarkupFragment)

Example 5 with IMarkupFragment

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 &lt;wicket:border&gt; 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)

Aggregations

IMarkupFragment (org.apache.wicket.markup.IMarkupFragment)26 Test (org.junit.Test)8 Page (org.apache.wicket.Page)6 ComponentTag (org.apache.wicket.markup.ComponentTag)6 MarkupStream (org.apache.wicket.markup.MarkupStream)6 MarkupContainer (org.apache.wicket.MarkupContainer)5 MarkupException (org.apache.wicket.markup.MarkupException)4 Component (org.apache.wicket.Component)3 MarkupElement (org.apache.wicket.markup.MarkupElement)3 MarkupNotFoundException (org.apache.wicket.markup.MarkupNotFoundException)3 ArrayList (java.util.ArrayList)2 Locale (java.util.Locale)2 WicketRuntimeException (org.apache.wicket.WicketRuntimeException)2 MarkupResourceStream (org.apache.wicket.markup.MarkupResourceStream)2 WicketTag (org.apache.wicket.markup.WicketTag)2 Border (org.apache.wicket.markup.html.border.Border)2 Panel (org.apache.wicket.markup.html.panel.Panel)2 IComponentResolver (org.apache.wicket.markup.resolver.IComponentResolver)2 IOException (java.io.IOException)1 List (java.util.List)1