use of org.apache.wicket.markup.MarkupStream 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.MarkupStream in project wicket by apache.
the class ExceptionErrorPage method getErrorMessage.
/**
* Converts a Throwable to a string.
*
* @param throwable
* The throwable
* @return The string
*/
public String getErrorMessage(final Throwable throwable) {
if (throwable != null) {
StringBuilder sb = new StringBuilder(256);
// first print the last cause
List<Throwable> al = convertToList(throwable);
int length = al.size() - 1;
Throwable cause = al.get(length);
sb.append("Last cause: ").append(cause.getMessage()).append('\n');
if (throwable instanceof WicketRuntimeException) {
String msg = throwable.getMessage();
if ((msg != null) && (msg.equals(cause.getMessage()) == false)) {
if (throwable instanceof MarkupException) {
MarkupStream stream = ((MarkupException) throwable).getMarkupStream();
if (stream != null) {
String text = "\n" + stream.toString();
if (msg.endsWith(text)) {
msg = msg.substring(0, msg.length() - text.length());
}
}
}
sb.append("WicketMessage: ");
sb.append(msg);
sb.append("\n\n");
}
}
return sb.toString();
} else {
return "[Unknown]";
}
}
use of org.apache.wicket.markup.MarkupStream in project wicket by apache.
the class MarkupContainer method renderAssociatedMarkup.
/**
* Renders the entire associated markup for a container such as a Border or Panel. Any leading
* or trailing raw markup in the associated markup is skipped.
*
* @param openTagName
* the tag to render the associated markup for
* @param exceptionMessage
* message that will be used for exceptions
*/
public final void renderAssociatedMarkup(final String openTagName, final String exceptionMessage) {
// Get associated markup file for the Border or Panel component
final MarkupStream associatedMarkupStream = new MarkupStream(getMarkup(null));
// Get open tag in associated markup of border component
MarkupElement elem = associatedMarkupStream.get();
if ((elem instanceof ComponentTag) == false) {
associatedMarkupStream.throwMarkupException("Expected the open tag. " + exceptionMessage);
}
// Check for required open tag name
ComponentTag associatedMarkupOpenTag = (ComponentTag) elem;
if (!(associatedMarkupOpenTag.isOpen() && (associatedMarkupOpenTag instanceof WicketTag))) {
associatedMarkupStream.throwMarkupException(exceptionMessage);
}
try {
setIgnoreAttributeModifier(true);
renderComponentTag(associatedMarkupOpenTag);
associatedMarkupStream.next();
String className = null;
final boolean outputClassName = getApplication().getDebugSettings().isOutputMarkupContainerClassName();
if (outputClassName) {
className = Classes.name(getClass());
getResponse().write("<!-- MARKUP FOR ");
getResponse().write(className);
getResponse().write(" BEGIN -->");
}
renderComponentTagBody(associatedMarkupStream, associatedMarkupOpenTag);
if (outputClassName) {
getResponse().write("<!-- MARKUP FOR ");
getResponse().write(className);
getResponse().write(" END -->");
}
renderClosingComponentTag(associatedMarkupStream, associatedMarkupOpenTag, false);
} finally {
setIgnoreAttributeModifier(false);
}
}
use of org.apache.wicket.markup.MarkupStream in project wicket by apache.
the class Page method onRender.
@Override
protected void onRender() {
// Loop through the markup in this container
MarkupStream markupStream = new MarkupStream(getMarkup());
renderAll(markupStream, null);
}
Aggregations