Search in sources :

Example 6 with ResourceStreamLocator

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

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

Example 8 with ResourceStreamLocator

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

the class CachingResourceStreamLocatorTest method nonStrictMatchingDoesntResultInInvalidStrictMatch.

/**
 * Tests non-strict before strict matching with a specific locale.
 */
@Test
public void nonStrictMatchingDoesntResultInInvalidStrictMatch() {
    IResourceStreamLocator resourceStreamLocator = new ResourceStreamLocator(new ClassPathResourceFinder(""));
    CachingResourceStreamLocator cachingLocator = new CachingResourceStreamLocator(resourceStreamLocator);
    String style = null;
    String variation = null;
    Locale locale = new Locale("nl", "NL");
    String extension = null;
    String filename = "org/apache/wicket/ajax/res/js/wicket-ajax-jquery-debug.js";
    // a non-strict lookup with a specific locale should find the non-localized resource
    IResourceStream nonStrictLocate = cachingLocator.locate(AbstractDefaultAjaxBehavior.class, filename, style, variation, locale, extension, false);
    assertThat(nonStrictLocate, is(not(nullValue())));
    // but a strict lookup with a specific locale should not fall back to the non-localized
    // resource
    IResourceStream strictLocate = cachingLocator.locate(AbstractDefaultAjaxBehavior.class, filename, style, variation, locale, extension, true);
    assertThat(strictLocate, is(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

ResourceStreamLocator (org.apache.wicket.core.util.resource.locator.ResourceStreamLocator)8 IResourceStreamLocator (org.apache.wicket.core.util.resource.locator.IResourceStreamLocator)7 Test (org.junit.Test)5 ClassPathResourceFinder (org.apache.wicket.core.util.resource.ClassPathResourceFinder)4 CachingResourceStreamLocator (org.apache.wicket.core.util.resource.locator.caching.CachingResourceStreamLocator)4 IResourceStream (org.apache.wicket.util.resource.IResourceStream)4 Locale (java.util.Locale)3 IOException (java.io.IOException)1 Application (org.apache.wicket.Application)1 PageExpiredErrorPage (org.apache.wicket.markup.html.pages.PageExpiredErrorPage)1 ResourceStreamNotFoundException (org.apache.wicket.util.resource.ResourceStreamNotFoundException)1