Search in sources :

Example 1 with AbstractMarkupFilter

use of org.apache.wicket.markup.parser.AbstractMarkupFilter 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 2 with AbstractMarkupFilter

use of org.apache.wicket.markup.parser.AbstractMarkupFilter in project wicket by apache.

the class OpenCloseTagExpanderTest method expandNonVoidElements.

/**
 * https://issues.apache.org/jira/browse/WICKET-5237
 *
 * @throws ParseException
 */
@Test
public void expandNonVoidElements() throws ParseException {
    for (String htmlNonVoidElement : OpenCloseTagExpander.REPLACE_FOR_TAGS) {
        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(htmlNonVoidElement, XmlTag.TagType.OPEN_CLOSE);
        expander.onComponentTag(tag);
        ComponentTag markupElement = (ComponentTag) expander.nextElement();
        // assert the next element is returned by the parent
        assertEquals(htmlNonVoidElement, markupElement.getName());
        assertTrue(markupElement.closes(tag));
    }
}
Also used : AbstractMarkupFilter(org.apache.wicket.markup.parser.AbstractMarkupFilter) ComponentTag(org.apache.wicket.markup.ComponentTag) Test(org.junit.Test)

Aggregations

ComponentTag (org.apache.wicket.markup.ComponentTag)2 AbstractMarkupFilter (org.apache.wicket.markup.parser.AbstractMarkupFilter)2 Test (org.junit.Test)2 MarkupElement (org.apache.wicket.markup.MarkupElement)1