Search in sources :

Example 1 with MarkupType

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

the class BorderBehavior method findMarkupStream.

/**
 * @param owner
 * @return markup stream
 */
private MarkupStream findMarkupStream(final Component owner) {
    final MarkupType markupType = getMarkupType(owner);
    if (markupType == null) {
        return null;
    }
    // TODO we need to expose this functionality for any class not just for
    // markupcontainers in markupcache so we don't have to replicate this
    // logic here
    // Get locator to search for the resource
    final IResourceStreamLocator locator = Application.get().getResourceSettings().getResourceStreamLocator();
    final String style = owner.getStyle();
    final String variation = owner.getVariation();
    final Locale locale = owner.getLocale();
    MarkupResourceStream markupResourceStream = null;
    Class<?> containerClass = getClass();
    while (!(containerClass.equals(BorderBehavior.class))) {
        String path = containerClass.getName().replace('.', '/');
        IResourceStream resourceStream = locator.locate(containerClass, path, style, variation, locale, markupType.getExtension(), false);
        // Did we find it already?
        if (resourceStream != null) {
            ContainerInfo ci = new ContainerInfo(containerClass, locale, style, variation, markupType);
            markupResourceStream = new MarkupResourceStream(resourceStream, ci, containerClass);
            break;
        }
        // Walk up the class hierarchy one level, if markup has not
        // yet been found
        containerClass = containerClass.getSuperclass();
    }
    if (markupResourceStream == null) {
        throw new WicketRuntimeException("Could not find markup for component border `" + getClass().getName() + "`");
    }
    try {
        IMarkupFragment markup = MarkupFactory.get().newMarkupParser(markupResourceStream).parse();
        return new MarkupStream(markup);
    } catch (Exception e) {
        throw new WicketRuntimeException("Could not parse markup from markup resource stream: " + markupResourceStream.toString(), e);
    } finally {
        try {
            markupResourceStream.close();
        } catch (IOException e) {
            throw new WicketRuntimeException("Cannot close markup resource stream: " + markupResourceStream, e);
        }
    }
}
Also used : Locale(java.util.Locale) IResourceStream(org.apache.wicket.util.resource.IResourceStream) WicketRuntimeException(org.apache.wicket.WicketRuntimeException) IResourceStreamLocator(org.apache.wicket.core.util.resource.locator.IResourceStreamLocator) MarkupResourceStream(org.apache.wicket.markup.MarkupResourceStream) MarkupStream(org.apache.wicket.markup.MarkupStream) IOException(java.io.IOException) WicketRuntimeException(org.apache.wicket.WicketRuntimeException) IOException(java.io.IOException) ContainerInfo(org.apache.wicket.markup.ContainerInfo) IMarkupFragment(org.apache.wicket.markup.IMarkupFragment) MarkupType(org.apache.wicket.markup.MarkupType)

Aggregations

IOException (java.io.IOException)1 Locale (java.util.Locale)1 WicketRuntimeException (org.apache.wicket.WicketRuntimeException)1 IResourceStreamLocator (org.apache.wicket.core.util.resource.locator.IResourceStreamLocator)1 ContainerInfo (org.apache.wicket.markup.ContainerInfo)1 IMarkupFragment (org.apache.wicket.markup.IMarkupFragment)1 MarkupResourceStream (org.apache.wicket.markup.MarkupResourceStream)1 MarkupStream (org.apache.wicket.markup.MarkupStream)1 MarkupType (org.apache.wicket.markup.MarkupType)1 IResourceStream (org.apache.wicket.util.resource.IResourceStream)1