Search in sources :

Example 11 with IResourceStreamLocator

use of org.apache.wicket.core.util.resource.locator.IResourceStreamLocator in project wiquery by WiQuery.

the class DatePickerLanguageResourceReferenceTestCase method testGetDatePickerLanguages.

@Test
public void testGetDatePickerLanguages() {
    Locale nonavailableLocale = new Locale("wiquery");
    Locale availableLocale = DatePickerLanguages.ARMENIAN.getLocale();
    assertNull(DatePickerLanguages.getDatePickerLanguages(nonavailableLocale));
    assertNull(DatePickerLanguageResourceReference.get(nonavailableLocale));
    assertNotNull(DatePickerLanguages.getDatePickerLanguages(availableLocale));
    assertNotNull(DatePickerLanguageResourceReference.get(availableLocale));
    for (DatePickerLanguages language : DatePickerLanguages.values()) {
        // assert if the language getter is implemented correctly to return
        // the exact variant.
        assertEquals(language, DatePickerLanguages.getDatePickerLanguages(language.getLocale()));
        // assert if the reference getter is implemented correctly to return
        // a reference to the exact variant.
        DatePickerLanguageResourceReference ref = DatePickerLanguageResourceReference.get(language.getLocale());
        assertNotNull(ref);
        // assert if the file is actually there.
        IResourceStreamLocator locator = Application.get().getResourceSettings().getResourceStreamLocator();
        String absolutePath = Packages.absolutePath(DatePickerLanguageResourceReference.class, DatePickerLanguages.getJsFileName(language));
        assertNotNull("Resource " + DatePickerLanguages.getJsFileName(language) + " for locale " + language.getLocale() + " does not exist!", locator.locate(DatePickerLanguageResourceReference.class, absolutePath));
    }
}
Also used : Locale(java.util.Locale) IResourceStreamLocator(org.apache.wicket.core.util.resource.locator.IResourceStreamLocator) DatePickerLanguages(org.odlabs.wiquery.ui.datepicker.DatePickerLanguageResourceReference.DatePickerLanguages) Test(org.junit.Test)

Example 12 with IResourceStreamLocator

use of org.apache.wicket.core.util.resource.locator.IResourceStreamLocator 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)

Example 13 with IResourceStreamLocator

use of org.apache.wicket.core.util.resource.locator.IResourceStreamLocator in project wicket by apache.

the class ResourceSettings method getResourceStreamLocator.

public IResourceStreamLocator getResourceStreamLocator() {
    if (resourceStreamLocator == null) {
        // Create compound resource locator using source path from
        // application settings
        resourceStreamLocator = new ResourceStreamLocator(getResourceFinders());
        resourceStreamLocator = new CachingResourceStreamLocator(resourceStreamLocator);
    }
    return resourceStreamLocator;
}
Also used : CachingResourceStreamLocator(org.apache.wicket.core.util.resource.locator.caching.CachingResourceStreamLocator) IResourceStreamLocator(org.apache.wicket.core.util.resource.locator.IResourceStreamLocator) CachingResourceStreamLocator(org.apache.wicket.core.util.resource.locator.caching.CachingResourceStreamLocator) ResourceStreamLocator(org.apache.wicket.core.util.resource.locator.ResourceStreamLocator)

Example 14 with IResourceStreamLocator

use of org.apache.wicket.core.util.resource.locator.IResourceStreamLocator in project wicket by apache.

the class ResourceStreamLocatorTest method locateInClasspath.

/**
 * Test locating a resource.
 */
@Test
public void locateInClasspath() {
    // Execute without source path
    executeMultiple(new ClassPathResourceFinder(""));
    // Determine source path
    IResourceStreamLocator locator = new ResourceStreamLocator();
    IResourceStream resource = locator.locate(getClass(), this.getClass().getName().replace('.', '/'), null, null, null, "txt", false);
    String path = getPath(resource);
    path = Strings.beforeLastPathComponent(path, '/') + "/sourcePath";
}
Also used : IResourceStreamLocator(org.apache.wicket.core.util.resource.locator.IResourceStreamLocator) ResourceStreamLocator(org.apache.wicket.core.util.resource.locator.ResourceStreamLocator) IResourceStreamLocator(org.apache.wicket.core.util.resource.locator.IResourceStreamLocator) ClassPathResourceFinder(org.apache.wicket.core.util.resource.ClassPathResourceFinder) Test(org.junit.Test)

Example 15 with IResourceStreamLocator

use of org.apache.wicket.core.util.resource.locator.IResourceStreamLocator in project wicket by apache.

the class CachingResourceStreamLocatorTest method strictBeforeNonStrictMatchingWithoutLocaleDoesntResultInInvalidNonStrictMatch.

/**
 * Tests strict before non-strict matching without a specific locale.
 */
@Test
public void strictBeforeNonStrictMatchingWithoutLocaleDoesntResultInInvalidNonStrictMatch() {
    IResourceStreamLocator resourceStreamLocator = new ResourceStreamLocator(new ClassPathResourceFinder(""));
    CachingResourceStreamLocator cachingLocator = new CachingResourceStreamLocator(resourceStreamLocator);
    String style = null;
    String variation = null;
    Locale locale = null;
    String extension = null;
    String filename = "org/apache/wicket/ajax/res/js/wicket-ajax-jquery-debug.js";
    // a strict lookup for the resource with no specific locale results in a match
    IResourceStream strictLocate = cachingLocator.locate(AbstractDefaultAjaxBehavior.class, filename, style, variation, locale, extension, true);
    assertThat(strictLocate, is(not(nullValue())));
    // followed by a non-strict search for the same resource also finds it
    IResourceStream nonStrictLocate = cachingLocator.locate(AbstractDefaultAjaxBehavior.class, filename, style, variation, locale, extension, false);
    assertThat(nonStrictLocate, is(not(nullValue())));
}
Also used : Locale(java.util.Locale) CachingResourceStreamLocator(org.apache.wicket.core.util.resource.locator.caching.CachingResourceStreamLocator) IResourceStream(org.apache.wicket.util.resource.IResourceStream) IResourceStreamLocator(org.apache.wicket.core.util.resource.locator.IResourceStreamLocator) ResourceStreamLocator(org.apache.wicket.core.util.resource.locator.ResourceStreamLocator) IResourceStreamLocator(org.apache.wicket.core.util.resource.locator.IResourceStreamLocator) CachingResourceStreamLocator(org.apache.wicket.core.util.resource.locator.caching.CachingResourceStreamLocator) ClassPathResourceFinder(org.apache.wicket.core.util.resource.ClassPathResourceFinder) Test(org.junit.Test)

Aggregations

IResourceStreamLocator (org.apache.wicket.core.util.resource.locator.IResourceStreamLocator)17 Test (org.junit.Test)11 CachingResourceStreamLocator (org.apache.wicket.core.util.resource.locator.caching.CachingResourceStreamLocator)9 ResourceStreamLocator (org.apache.wicket.core.util.resource.locator.ResourceStreamLocator)7 IResourceStream (org.apache.wicket.util.resource.IResourceStream)7 Locale (java.util.Locale)6 ClassPathResourceFinder (org.apache.wicket.core.util.resource.ClassPathResourceFinder)4 File (java.io.File)2 FileResourceStream (org.apache.wicket.util.resource.FileResourceStream)2 IOException (java.io.IOException)1 URL (java.net.URL)1 WicketRuntimeException (org.apache.wicket.WicketRuntimeException)1 UrlResourceStream (org.apache.wicket.core.util.resource.UrlResourceStream)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 PageExpiredErrorPage (org.apache.wicket.markup.html.pages.PageExpiredErrorPage)1 IFixedLocationResourceStream (org.apache.wicket.util.resource.IFixedLocationResourceStream)1