Search in sources :

Example 6 with MarkupStream

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

the class BorderBehavior method afterRender.

@Override
public void afterRender(final Component component) {
    final MarkupStream stream = getMarkupStream(component);
    final Response response = component.getResponse();
    while (stream.isCurrentIndexInsideTheStream()) {
        MarkupElement elem = stream.get();
        stream.next();
        if (elem instanceof WicketTag) {
            WicketTag wTag = (WicketTag) elem;
            if (wTag.isBorderTag() && wTag.isClose()) {
                break;
            } else {
                throw new WicketRuntimeException("Unexpected tag encountered in markup of component border " + getClass().getName() + ". Tag: " + wTag.toString() + ", expected tag: </wicket:border>");
            }
        }
        response.write(elem.toCharSequence());
    }
}
Also used : Response(org.apache.wicket.request.Response) WicketTag(org.apache.wicket.markup.WicketTag) WicketRuntimeException(org.apache.wicket.WicketRuntimeException) MarkupStream(org.apache.wicket.markup.MarkupStream) MarkupElement(org.apache.wicket.markup.MarkupElement)

Example 7 with MarkupStream

use of org.apache.wicket.markup.MarkupStream 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 8 with MarkupStream

use of org.apache.wicket.markup.MarkupStream 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)

Example 9 with MarkupStream

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

the class FragmentMarkupSourcingStrategy method onComponentTagBody.

/**
 * Skip the body markup associated with the 'component'. The body markup is expected to be raw
 * markup only, not containing an wicket component. The body markup may serve documentary
 * purposes for the developer / designer.
 * <p>
 * Than search for the markup of the fragment, effectively replacing the original markup.
 */
@Override
public void onComponentTagBody(final Component component, final MarkupStream markupStream, final ComponentTag openTag) {
    // Skip the body markup making sure it contains only raw markup
    super.onComponentTagBody(component, markupStream, openTag);
    // Get the fragments open tag
    MarkupStream stream = new MarkupStream(getMarkup((MarkupContainer) component, null));
    ComponentTag fragmentOpenTag = stream.getTag();
    // if it is an open close tag, skip this fragment.
    if (!fragmentOpenTag.isOpenClose()) {
        // We'll completely ignore the fragments open tag. It'll not be rendered
        stream.next();
        // Render the body of the fragment
        component.onComponentTagBody(stream, fragmentOpenTag);
    }
}
Also used : MarkupContainer(org.apache.wicket.MarkupContainer) ComponentTag(org.apache.wicket.markup.ComponentTag) MarkupStream(org.apache.wicket.markup.MarkupStream)

Example 10 with MarkupStream

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

the class HeaderSectionMyLabel method newMarkupSourcingStrategy.

@Override
protected IMarkupSourcingStrategy newMarkupSourcingStrategy() {
    return new PanelMarkupSourcingStrategy(false) {

        @Override
        public IMarkupFragment getMarkup(final MarkupContainer parent, final Component child) {
            MarkupStream markup = new MarkupStream(parent.getAssociatedMarkup());
            markup.skipRawMarkup();
            return markup.getMarkupFragment();
        }

        @Override
        public void onComponentTagBody(Component component, MarkupStream markupStream, ComponentTag openTag) {
            HeaderSectionMyLabel.this.onComponentTagBody(markupStream, openTag);
        }
    };
}
Also used : WebMarkupContainer(org.apache.wicket.markup.html.WebMarkupContainer) MarkupContainer(org.apache.wicket.MarkupContainer) PanelMarkupSourcingStrategy(org.apache.wicket.markup.html.panel.PanelMarkupSourcingStrategy) ComponentTag(org.apache.wicket.markup.ComponentTag) MarkupStream(org.apache.wicket.markup.MarkupStream) Component(org.apache.wicket.Component)

Aggregations

MarkupStream (org.apache.wicket.markup.MarkupStream)24 ComponentTag (org.apache.wicket.markup.ComponentTag)14 IMarkupFragment (org.apache.wicket.markup.IMarkupFragment)6 MarkupException (org.apache.wicket.markup.MarkupException)6 WicketRuntimeException (org.apache.wicket.WicketRuntimeException)5 MarkupElement (org.apache.wicket.markup.MarkupElement)5 WicketTag (org.apache.wicket.markup.WicketTag)5 Component (org.apache.wicket.Component)3 MarkupContainer (org.apache.wicket.MarkupContainer)3 IOException (java.io.IOException)2 MarkupNotFoundException (org.apache.wicket.markup.MarkupNotFoundException)2 Label (org.apache.wicket.markup.html.basic.Label)2 Response (org.apache.wicket.request.Response)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Locale (java.util.Locale)1 Page (org.apache.wicket.Page)1 AuthorizationException (org.apache.wicket.authorization.AuthorizationException)1 UnauthorizedActionException (org.apache.wicket.authorization.UnauthorizedActionException)1 IResourceStreamLocator (org.apache.wicket.core.util.resource.locator.IResourceStreamLocator)1