use of org.apache.wicket.markup.IMarkupFragment in project wicket by apache.
the class AbstractMarkupSourcingStrategy method searchMarkupInTransparentResolvers.
/**
* If the child has not been directly added to the container, but via a
* TransparentWebMarkupContainer, then we are in trouble. In general Wicket iterates over the
* markup elements and searches for associated components, not the other way around. Because of
* TransparentWebMarkupContainer (or more generally resolvers), there is no "synchronous" search
* possible.
*
* @param container
* the parent container.
* @param
* containerMarkup
* the markup of the parent container.
* @param child
* The component to find the markup for.
* @return the markup fragment for the child, or {@code null}.
*/
protected IMarkupFragment searchMarkupInTransparentResolvers(MarkupContainer container, IMarkupFragment containerMarkup, Component child) {
IMarkupFragment childMarkupFound = null;
Iterator<Component> childrenIterator = container.iterator();
final List<MarkupContainer> componentResolvers = new ArrayList<>();
// collect all "transparent" (i.e. component resolvers) children
container.visitChildren(IComponentResolver.class, new IVisitor<MarkupContainer, Void>() {
@Override
public void component(MarkupContainer child, IVisit<Void> visit) {
componentResolvers.add(child);
}
});
while (childrenIterator.hasNext() && childMarkupFound == null) {
Component sibling = childrenIterator.next();
if (sibling == child || !sibling.isVisible() || !(sibling instanceof MarkupContainer)) {
continue;
}
IMarkupFragment siblingMarkup = containerMarkup.find(sibling.getId());
if (siblingMarkup != null) {
if (sibling instanceof IComponentResolver) {
childMarkupFound = searchInNestedTransparentResolvers(containerMarkup, child, componentResolvers);
} else {
childMarkupFound = searchMarkupInTransparentResolvers((MarkupContainer) sibling, siblingMarkup, child);
}
}
}
return childMarkupFound;
}
use of org.apache.wicket.markup.IMarkupFragment in project wicket by apache.
the class AbstractMarkupSourcingStrategy method searchInNestedTransparentResolvers.
/**
* Search for the markup of a child that might be nested inside
* transparent siblings. For example:
*
* <pre>
* <div wicket:id="outerTransparent">
* <div wicket:id="innerTransparent">
* <span wicket:id="childComponent"></span>
* </div>
* </div>
* </pre>
*
* @param
* containerMarkup
* the markup of the parent container.
* @param child
* The component to find the markup for.
* @param componentResolvers
* the transparent siblings
*
* @return the markup fragment for the child, or {@code null}.
*/
protected IMarkupFragment searchInNestedTransparentResolvers(IMarkupFragment containerMarkup, Component child, List<MarkupContainer> componentResolvers) {
IMarkupFragment childMarkupFound = null;
for (MarkupContainer componentResolver : componentResolvers) {
IMarkupFragment resolverMarkup = containerMarkup.find(componentResolver.getId());
IMarkupFragment childMarkup = resolverMarkup != null ? resolverMarkup.find(child.getId()) : null;
if (childMarkup != null) {
IComponentResolver resolverContainer = (IComponentResolver) componentResolver;
MarkupStream stream = new MarkupStream(childMarkup);
ComponentTag tag = stream.getTag();
Component resolvedComponent = componentResolver.get(tag.getId());
if (resolvedComponent == null) {
resolvedComponent = resolverContainer.resolve(componentResolver, stream, tag);
}
if (child == resolvedComponent) {
childMarkupFound = childMarkup;
}
} else if (resolverMarkup != null) {
List<MarkupContainer> otherResolvers = new ArrayList<>(componentResolvers);
otherResolvers.remove(componentResolver);
childMarkupFound = searchInNestedTransparentResolvers(resolverMarkup, child, otherResolvers);
}
if (childMarkupFound != null) {
break;
}
}
return childMarkupFound;
}
use of org.apache.wicket.markup.IMarkupFragment in project wicket by apache.
the class AssociatedMarkupSourcingStrategy method getMarkup.
/**
* Search for the child's markup in the associated markup file.
*
* @param parent
* The container expected to contain the markup for child
* @param child
* The child component to find the markup for
* @return The markup associated with the child
*/
@Override
public IMarkupFragment getMarkup(final MarkupContainer parent, final Component child) {
Args.notNull(tagName, "tagName");
IMarkupFragment associatedMarkup = parent.getAssociatedMarkup();
if (associatedMarkup == null) {
throw new MarkupNotFoundException("Failed to find markup file associated. " + Classes.simpleName(parent.getClass()) + ": " + parent.toString());
}
// Find <wicket:panel>
IMarkupFragment markup = MarkupUtil.findStartTag(associatedMarkup, tagName);
if (markup == null) {
throw new MarkupNotFoundException("Expected to find <wicket:" + tagName + "> in associated markup file. Markup: " + associatedMarkup.toString());
}
// If child == null, than return the markup fragment starting with <wicket:panel>
if (child == null) {
// clean any markup previously loaded for children
cleanChildrenMarkup(parent);
return markup;
}
// Find the markup for the child component
associatedMarkup = markup.find(child.getId());
if (associatedMarkup != null) {
return associatedMarkup;
}
associatedMarkup = searchMarkupInTransparentResolvers(parent, markup, child);
if (associatedMarkup != null) {
return associatedMarkup;
}
return findMarkupInAssociatedFileHeader(parent, child);
}
use of org.apache.wicket.markup.IMarkupFragment in project wicket by apache.
the class DefaultMarkupSourcingStrategy method getMarkup.
/**
* Get the markup for the child component, which is assumed to be a child of 'container'.
*/
@Override
public IMarkupFragment getMarkup(final MarkupContainer container, final Component child) {
// If the sourcing strategy did not provide one, than ask the component.
// Get the markup for the container
IMarkupFragment containerMarkup = container.getMarkup();
if (containerMarkup == null) {
return null;
}
if (child == null) {
return containerMarkup;
}
// Find the child's markup
IMarkupFragment childMarkup = containerMarkup.find(child.getId());
if (childMarkup != null) {
return childMarkup;
}
return searchMarkupInTransparentResolvers(container, containerMarkup, child);
}
use of org.apache.wicket.markup.IMarkupFragment in project wicket by apache.
the class FragmentMarkupSourcingStrategy method getMarkup.
/**
* Search for the child's markup in the fragment markup.
*/
@Override
public IMarkupFragment getMarkup(final MarkupContainer container, final Component child) {
// Get the markup to search for the fragment markup
IMarkupFragment markup = chooseMarkup(container);
if (markup == null) {
throw new MarkupException("The fragments markup provider has no associated markup. " + "No markup to search for fragment markup with id: " + markupId);
}
// Search for the fragment markup
IMarkupFragment childMarkup = TagUtils.findTagMarkup(markup, markupId, FRAGMENT, 1);
if (childMarkup == null) {
// There is one more option if the markup provider has associated markup
MarkupContainer markupProvider = getMarkupProvider(container);
Markup associatedMarkup = markupProvider.getAssociatedMarkup();
if (associatedMarkup != null) {
markup = associatedMarkup;
if (markup != null) {
childMarkup = markup.find(markupId);
}
}
}
if (childMarkup == null) {
throw new MarkupNotFoundException("No Markup found for Fragment " + markupId + " in providing markup container " + getMarkupProvider(container));
} else {
MarkupElement fragmentTag = childMarkup.get(0);
if ((fragmentTag instanceof WicketTag && ((WicketTag) fragmentTag).isFragmentTag()) == false) {
throw new MarkupNotFoundException("Markup found for Fragment '" + markupId + "' in providing markup container " + getMarkupProvider(container) + " is not a <wicket:fragment> tag");
}
}
if (child == null) {
return childMarkup;
}
// search for the child inside the fragment markup
return childMarkup.find(child.getId());
}
Aggregations