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);
}
}
}
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);
}
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());
}
}
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));
}
}
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());
}
Aggregations