Search in sources :

Example 1 with MarkupElement

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

the class TransparentWebMarkupContainer method renderHeadForInnerSiblings.

/**
 * Renders head for embedded component, i.e. those who are not added
 * directly to this container but have the markup inside it.
 *
 * @param container
 * 				The HtmlHeaderContainer
 */
private void renderHeadForInnerSiblings(HtmlHeaderContainer container) {
    MarkupStream stream = new MarkupStream(getMarkup());
    while (stream.isCurrentIndexInsideTheStream()) {
        MarkupElement childOpenTag = stream.nextOpenTag();
        if ((childOpenTag instanceof ComponentTag) && !stream.atCloseTag()) {
            // Get element as tag
            final ComponentTag tag = (ComponentTag) childOpenTag;
            // Get component id
            final String id = tag.getId();
            Component component = null;
            if (get(id) == null) {
                component = ComponentResolvers.resolveByComponentHierarchy(this, stream, tag);
            }
            if (component != null) {
                component.internalRenderHead(container);
            }
            // consider just direct children
            stream.skipToMatchingCloseTag(tag);
        }
    }
}
Also used : ComponentTag(org.apache.wicket.markup.ComponentTag) MarkupStream(org.apache.wicket.markup.MarkupStream) MarkupElement(org.apache.wicket.markup.MarkupElement) Component(org.apache.wicket.Component)

Example 2 with MarkupElement

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

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

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

the class OpenCloseTagExpanderTest method doNotExpandVoidElements.

/**
 * https://issues.apache.org/jira/browse/WICKET-5237
 *
 * @throws ParseException
 */
@Test
public void doNotExpandVoidElements() throws ParseException {
    String[] htmlVoidElements = new String[] { "area", "base", "br", "col", "command", "embed", "hr", "img", "input", "keygen", "link", "meta", "param", "source", "track", "wbr" };
    for (String htmlVoidElement : htmlVoidElements) {
        OpenCloseTagExpander expander = new OpenCloseTagExpander() {

            @Override
            public IMarkupFilter getNextFilter() {
                return new AbstractMarkupFilter() {

                    @Override
                    protected MarkupElement onComponentTag(ComponentTag tag) throws ParseException {
                        return null;
                    }

                    @Override
                    public MarkupElement nextElement() throws ParseException {
                        return new TestMarkupElement();
                    }
                };
            }
        };
        ComponentTag tag = new ComponentTag(htmlVoidElement, XmlTag.TagType.OPEN_CLOSE);
        expander.onComponentTag(tag);
        MarkupElement markupElement = expander.nextElement();
        // assert the next element is returned by the parent
        assertThat(markupElement, instanceOf(TestMarkupElement.class));
    }
}
Also used : AbstractMarkupFilter(org.apache.wicket.markup.parser.AbstractMarkupFilter) ComponentTag(org.apache.wicket.markup.ComponentTag) MarkupElement(org.apache.wicket.markup.MarkupElement) Test(org.junit.Test)

Example 5 with MarkupElement

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

the class OpenCloseTagExpanderTest method expandWicketTagWithSameNamespace.

/**
 * Verifies that the namespace of the created closing tag is the same
 * as of the opening one
 *
 * @throws ParseException
 */
@Test
public void expandWicketTagWithSameNamespace() throws ParseException {
    final String namespace = "customNS";
    OpenCloseTagExpander expander = new OpenCloseTagExpander() {

        @Override
        protected String getWicketNamespace() {
            return namespace;
        }
    };
    ComponentTag tag = new ComponentTag(HtmlHeaderResolver.HEADER_ITEMS, XmlTag.TagType.OPEN_CLOSE);
    tag.setNamespace(namespace);
    expander.onComponentTag(tag);
    MarkupElement markupElement = expander.nextElement();
    assertThat(markupElement, CoreMatchers.instanceOf(WicketTag.class));
    assertTrue(markupElement.closes(tag));
    assertEquals(namespace, ((ComponentTag) markupElement).getNamespace());
}
Also used : WicketTag(org.apache.wicket.markup.WicketTag) ComponentTag(org.apache.wicket.markup.ComponentTag) MarkupElement(org.apache.wicket.markup.MarkupElement) Test(org.junit.Test)

Aggregations

MarkupElement (org.apache.wicket.markup.MarkupElement)14 ComponentTag (org.apache.wicket.markup.ComponentTag)8 WicketTag (org.apache.wicket.markup.WicketTag)6 MarkupStream (org.apache.wicket.markup.MarkupStream)5 IMarkupFragment (org.apache.wicket.markup.IMarkupFragment)3 Test (org.junit.Test)3 WicketRuntimeException (org.apache.wicket.WicketRuntimeException)2 Markup (org.apache.wicket.markup.Markup)2 MarkupException (org.apache.wicket.markup.MarkupException)2 MarkupNotFoundException (org.apache.wicket.markup.MarkupNotFoundException)2 Response (org.apache.wicket.request.Response)2 Component (org.apache.wicket.Component)1 MarkupContainer (org.apache.wicket.MarkupContainer)1 MarkupFragment (org.apache.wicket.markup.MarkupFragment)1 RawMarkup (org.apache.wicket.markup.RawMarkup)1 BorderMarkupSourcingStrategy (org.apache.wicket.markup.html.panel.BorderMarkupSourcingStrategy)1 AbstractMarkupFilter (org.apache.wicket.markup.parser.AbstractMarkupFilter)1