use of org.apache.wicket.markup.resolver.IComponentResolver in project wicket by apache.
the class Enclosure method getChildComponent.
/**
* Resolves the child component which is the controller of this Enclosure
*
* @param markupStream
* the markup stream of this Enclosure
* @param enclosureParent
* the non-auto parent component of this Enclosure
* @return The component associated with the {@linkplain #childId}
*/
private Component getChildComponent(final MarkupStream markupStream, MarkupContainer enclosureParent) {
String fullChildId = getChildId();
Component controller = enclosureParent.get(fullChildId);
if (controller == null) {
int orgIndex = markupStream.getCurrentIndex();
try {
while (markupStream.isCurrentIndexInsideTheStream()) {
markupStream.next();
if (markupStream.skipUntil(ComponentTag.class)) {
ComponentTag tag = markupStream.getTag();
if ((tag != null) && (tag.isOpen() || tag.isOpenClose())) {
String tagId = tag.getId();
if (fullChildId.equals(tagId)) {
ComponentTag fullComponentTag = new ComponentTag(tag);
fullComponentTag.setId(childId.toString());
controller = ComponentResolvers.resolve(enclosureParent, markupStream, fullComponentTag, new ResolverFilter() {
@Override
public boolean ignoreResolver(final IComponentResolver resolver) {
return resolver instanceof EnclosureHandler;
}
});
break;
} else if (fullChildId.startsWith(tagId + PATH_SEPARATOR)) {
fullChildId = Strings.afterFirst(fullChildId, PATH_SEPARATOR);
}
}
}
}
} finally {
markupStream.setCurrentIndex(orgIndex);
}
}
checkChildComponent(controller);
return controller;
}
use of org.apache.wicket.markup.resolver.IComponentResolver 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.resolver.IComponentResolver 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;
}
Aggregations