Search in sources :

Example 1 with MarkupNotFoundException

use of org.apache.wicket.markup.MarkupNotFoundException in project wicket by apache.

the class InheritedMarkupMarkupLoader method loadMarkup.

/**
 * Load the markup from the resource stream with the base MarkupLoader provided, than check if
 * markup inheritance must be applied. If yes, than load the base markup and merge them.
 */
@Override
public final Markup loadMarkup(final MarkupContainer container, final MarkupResourceStream markupResourceStream, final IMarkupLoader baseLoader, final boolean enforceReload) throws IOException, ResourceStreamNotFoundException {
    // read and parse the markup
    Markup markup = baseLoader.loadMarkup(container, markupResourceStream, null, enforceReload);
    // Check if markup contains <wicket:extend> which tells us that
    // we need to read the inherited markup as well.
    int extendIndex = requiresBaseMarkup(markup);
    if (extendIndex == -1) {
        return markup;
    }
    // Load the base markup
    final Markup baseMarkup = getBaseMarkup(container, markup, enforceReload);
    if ((baseMarkup == null) || (baseMarkup == Markup.NO_MARKUP)) {
        throw new MarkupNotFoundException("Base markup of inherited markup not found. Component class: " + markup.getMarkupResourceStream().getContainerInfo().getContainerClass().getName() + ". Enable debug messages for " + ResourceStreamLocator.class.getName() + " to get a list of all filenames tried.");
    }
    // Merge base and derived markup
    return new MergedMarkup(markup, baseMarkup, extendIndex);
}
Also used : Markup(org.apache.wicket.markup.Markup) MergedMarkup(org.apache.wicket.markup.MergedMarkup) MergedMarkup(org.apache.wicket.markup.MergedMarkup) ResourceStreamLocator(org.apache.wicket.core.util.resource.locator.ResourceStreamLocator) MarkupNotFoundException(org.apache.wicket.markup.MarkupNotFoundException)

Example 2 with MarkupNotFoundException

use of org.apache.wicket.markup.MarkupNotFoundException in project wicket by apache.

the class Component method getMarkup.

/**
 * Get the Markup associated with the Component. If not subclassed, the parent container is
 * asked to return the markup of this child component.
 * <p/>
 * Components like Panel and Border should return the "calling" markup fragment, e.g.
 * <code>&lt;span wicket:id="myPanel"&gt;body&lt;/span&gt;</code>. You may use
 * Panel/Border/Enclosure.getMarkup(null) to return the associated markup file. And
 * Panel/Border/Enclosure.getMarkup(child) will search the child in the appropriate markup
 * fragment.
 *
 * @see MarkupContainer#getMarkup(Component)
 *
 * @return The markup fragment
 */
public IMarkupFragment getMarkup() {
    // Markup already determined or preset?
    if (markup != null) {
        return markup;
    }
    // No parent, than check associated markup files
    if (parent == null) {
        // Must be a MarkupContainer to have associated markup file
        if (this instanceof MarkupContainer) {
            MarkupContainer container = (MarkupContainer) this;
            Markup associatedMarkup = container.getAssociatedMarkup();
            if (associatedMarkup != null) {
                markup = associatedMarkup;
                return markup;
            }
        }
        // Don't know how to find the markup
        throw new MarkupNotFoundException("Can not determine Markup. Component is not yet connected to a parent. " + toString());
    }
    // Ask the parent for find the markup for me
    markup = parent.getMarkup(this);
    return markup;
}
Also used : Markup(org.apache.wicket.markup.Markup) MarkupNotFoundException(org.apache.wicket.markup.MarkupNotFoundException)

Example 3 with MarkupNotFoundException

use of org.apache.wicket.markup.MarkupNotFoundException in project wicket by apache.

the class Component method internalRender.

/**
 * Performs a render of this component as part of a Page level render process.
 */
private void internalRender() {
    // Make sure there is a markup available for the Component
    IMarkupFragment markup = getMarkup();
    if (markup == null) {
        throw new MarkupNotFoundException("Markup not found for Component: " + toString());
    }
    // MarkupStream is an Iterator for the markup
    MarkupStream markupStream = new MarkupStream(markup);
    MarkupElement elem = markup.get(0);
    if (elem instanceof ComponentTag) {
        // Guarantee that the markupStream is set and determineVisibility not yet tested
        // See WICKET-2049
        ((ComponentTag) elem).onBeforeRender(this, markupStream);
    }
    // and the isVisible property.
    if (determineVisibility()) {
        setFlag(FLAG_HAS_BEEN_RENDERED, true);
        // Rendering is beginning
        if (log.isDebugEnabled()) {
            log.debug("Begin render {}", this);
        }
        try {
            notifyBehaviorsComponentBeforeRender();
            onRender();
            notifyBehaviorsComponentRendered();
            // Component has been rendered
            rendered();
        } catch (RuntimeException ex) {
            onException(ex);
        }
        if (log.isDebugEnabled()) {
            log.debug("End render {}", this);
        }
    } else // elem is null when rendering a page
    if ((elem != null) && (elem instanceof ComponentTag)) {
        if (getFlag(FLAG_PLACEHOLDER)) {
            renderPlaceholderTag((ComponentTag) elem, getResponse());
        }
    }
}
Also used : ComponentTag(org.apache.wicket.markup.ComponentTag) MarkupStream(org.apache.wicket.markup.MarkupStream) MarkupNotFoundException(org.apache.wicket.markup.MarkupNotFoundException) IMarkupFragment(org.apache.wicket.markup.IMarkupFragment) MarkupElement(org.apache.wicket.markup.MarkupElement)

Example 4 with MarkupNotFoundException

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

Example 5 with MarkupNotFoundException

use of org.apache.wicket.markup.MarkupNotFoundException 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());
}
Also used : WicketTag(org.apache.wicket.markup.WicketTag) MarkupContainer(org.apache.wicket.MarkupContainer) Markup(org.apache.wicket.markup.Markup) MarkupNotFoundException(org.apache.wicket.markup.MarkupNotFoundException) IMarkupFragment(org.apache.wicket.markup.IMarkupFragment) MarkupElement(org.apache.wicket.markup.MarkupElement) MarkupException(org.apache.wicket.markup.MarkupException)

Aggregations

MarkupNotFoundException (org.apache.wicket.markup.MarkupNotFoundException)5 IMarkupFragment (org.apache.wicket.markup.IMarkupFragment)3 Markup (org.apache.wicket.markup.Markup)3 MarkupElement (org.apache.wicket.markup.MarkupElement)2 MarkupContainer (org.apache.wicket.MarkupContainer)1 ResourceStreamLocator (org.apache.wicket.core.util.resource.locator.ResourceStreamLocator)1 ComponentTag (org.apache.wicket.markup.ComponentTag)1 MarkupException (org.apache.wicket.markup.MarkupException)1 MarkupStream (org.apache.wicket.markup.MarkupStream)1 MergedMarkup (org.apache.wicket.markup.MergedMarkup)1 WicketTag (org.apache.wicket.markup.WicketTag)1