Search in sources :

Example 6 with CachingResourceStreamLocator

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

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

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

Example 9 with CachingResourceStreamLocator

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

the class CachingResourceStreamLocatorTest method lightweightResource.

/**
 * Tests light weight resource streams (everything but FileResourceStream and
 * UrlResourceStream). These should <strong>not</strong> be cached.
 */
@Test
public void lightweightResource() {
    IResourceStreamLocator resourceStreamLocator = mock(IResourceStreamLocator.class);
    StringResourceStream srs = new StringResourceStream("anything");
    when(resourceStreamLocator.locate(String.class, "path", "style", "variation", null, "extension", true)).thenReturn(srs);
    CachingResourceStreamLocator cachingLocator = new CachingResourceStreamLocator(resourceStreamLocator);
    cachingLocator.locate(String.class, "path", "style", "variation", null, "extension", true);
    cachingLocator.locate(String.class, "path", "style", "variation", null, "extension", true);
    // lightweight resource streams should not be cached so expect just a call to the delegate
    // for each call to the caching locator
    verify(resourceStreamLocator, times(2)).locate(String.class, "path", "style", "variation", null, "extension", true);
}
Also used : CachingResourceStreamLocator(org.apache.wicket.core.util.resource.locator.caching.CachingResourceStreamLocator) IResourceStreamLocator(org.apache.wicket.core.util.resource.locator.IResourceStreamLocator) StringResourceStream(org.apache.wicket.util.resource.StringResourceStream) Test(org.junit.Test)

Aggregations

IResourceStreamLocator (org.apache.wicket.core.util.resource.locator.IResourceStreamLocator)9 CachingResourceStreamLocator (org.apache.wicket.core.util.resource.locator.caching.CachingResourceStreamLocator)9 Test (org.junit.Test)8 ResourceStreamLocator (org.apache.wicket.core.util.resource.locator.ResourceStreamLocator)4 Locale (java.util.Locale)3 ClassPathResourceFinder (org.apache.wicket.core.util.resource.ClassPathResourceFinder)3 IResourceStream (org.apache.wicket.util.resource.IResourceStream)3 File (java.io.File)2 FileResourceStream (org.apache.wicket.util.resource.FileResourceStream)2 URL (java.net.URL)1 UrlResourceStream (org.apache.wicket.core.util.resource.UrlResourceStream)1 StringResourceStream (org.apache.wicket.util.resource.StringResourceStream)1