Search in sources :

Example 21 with MarkupStream

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>
 * &lt;div wicket:id=&quot;outerTransparent&quot;&gt;
 *	&lt;div wicket:id=&quot;innerTransparent&quot;&gt;
 *	 &lt;span wicket:id=&quot;childComponent&quot;&gt;&lt;/span&gt;
 *	&lt;/div&gt;
 * &lt;/div&gt;
 * </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;
}
Also used : MarkupContainer(org.apache.wicket.MarkupContainer) ComponentTag(org.apache.wicket.markup.ComponentTag) MarkupStream(org.apache.wicket.markup.MarkupStream) ArrayList(java.util.ArrayList) List(java.util.List) IMarkupFragment(org.apache.wicket.markup.IMarkupFragment) Component(org.apache.wicket.Component) IComponentResolver(org.apache.wicket.markup.resolver.IComponentResolver)

Example 22 with MarkupStream

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]";
    }
}
Also used : WicketRuntimeException(org.apache.wicket.WicketRuntimeException) MarkupStream(org.apache.wicket.markup.MarkupStream) MarkupException(org.apache.wicket.markup.MarkupException)

Example 23 with MarkupStream

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);
    }
}
Also used : WicketTag(org.apache.wicket.markup.WicketTag) ComponentTag(org.apache.wicket.markup.ComponentTag) MarkupStream(org.apache.wicket.markup.MarkupStream) MarkupElement(org.apache.wicket.markup.MarkupElement)

Example 24 with MarkupStream

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);
}
Also used : MarkupStream(org.apache.wicket.markup.MarkupStream)

Aggregations

MarkupStream (org.apache.wicket.markup.MarkupStream)24 ComponentTag (org.apache.wicket.markup.ComponentTag)14 IMarkupFragment (org.apache.wicket.markup.IMarkupFragment)6 MarkupException (org.apache.wicket.markup.MarkupException)6 WicketRuntimeException (org.apache.wicket.WicketRuntimeException)5 MarkupElement (org.apache.wicket.markup.MarkupElement)5 WicketTag (org.apache.wicket.markup.WicketTag)5 Component (org.apache.wicket.Component)3 MarkupContainer (org.apache.wicket.MarkupContainer)3 IOException (java.io.IOException)2 MarkupNotFoundException (org.apache.wicket.markup.MarkupNotFoundException)2 Label (org.apache.wicket.markup.html.basic.Label)2 Response (org.apache.wicket.request.Response)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Locale (java.util.Locale)1 Page (org.apache.wicket.Page)1 AuthorizationException (org.apache.wicket.authorization.AuthorizationException)1 UnauthorizedActionException (org.apache.wicket.authorization.UnauthorizedActionException)1 IResourceStreamLocator (org.apache.wicket.core.util.resource.locator.IResourceStreamLocator)1