Search in sources :

Example 1 with ClassPathResourceFinder

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

the class CachingResourceStreamLocatorTest method strictMatchingDoesntInvalidateNonStrictMatching.

/**
 * Tests strict before non-strict matching with a specific locale.
 */
@Test
public void strictMatchingDoesntInvalidateNonStrictMatching() {
    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 strict lookup of a localized resource should not find the non-localized resource
    IResourceStream strictLocate = cachingLocator.locate(AbstractDefaultAjaxBehavior.class, filename, style, variation, locale, extension, true);
    assertThat(strictLocate, is(nullValue()));
    // but a non-strict lookup with a locale should fall back to the non-localized resource
    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 2 with ClassPathResourceFinder

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

the class WebApplication method internalInit.

/**
 * THIS METHOD IS NOT PART OF THE WICKET PUBLIC API. DO NOT CALL IT.
 *
 * Internal initialization. First determine the deployment mode. First check the system property
 * -Dwicket.configuration. If it does not exist check the servlet init parameter (
 * <code>&lt;init-param&gt&lt;param-name&gt;configuration&lt;/param-name&gt;</code>). If not
 * found check the servlet context init parameter
 * <code>&lt;context-param&gt&lt;param-name6gt;configuration&lt;/param-name&gt;</code>). If the
 * parameter is "development" (which is default), settings appropriate for development are set.
 * If it's "deployment" , deployment settings are used. If development is specified and a
 * "sourceFolder" init parameter is also set, then resources in that folder will be polled for
 * changes.
 */
@Override
protected void internalInit() {
    super.internalInit();
    getResourceSettings().getResourceFinders().add(new WebApplicationPath(getServletContext(), ""));
    getResourceSettings().getResourceFinders().add(new ClassPathResourceFinder(META_INF_RESOURCES));
    // Set default error pages for HTML markup
    getApplicationSettings().setPageExpiredErrorPage(PageExpiredErrorPage.class);
    getApplicationSettings().setInternalErrorPage(InternalErrorPage.class);
    getApplicationSettings().setAccessDeniedPage(AccessDeniedPage.class);
    // Add resolver for automatically resolving HTML links
    getPageSettings().addComponentResolver(new AutoLinkResolver());
    getPageSettings().addComponentResolver(new AutoLabelResolver());
    getPageSettings().addComponentResolver(new AutoLabelTextResolver());
    getResourceSettings().setFileCleaner(new FileCleaner());
    if (getConfigurationType() == RuntimeConfigurationType.DEVELOPMENT) {
        // Add optional sourceFolder for resources.
        String resourceFolder = getInitParameter("sourceFolder");
        if (resourceFolder != null) {
            getResourceSettings().getResourceFinders().add(new Path(resourceFolder));
        }
    }
    setPageRendererProvider(WebPageRenderer::new);
    setSessionStoreProvider(HttpSessionStore::new);
    setAjaxRequestTargetProvider(AjaxRequestHandler::new);
    getAjaxRequestTargetListeners().add(new AjaxEnclosureListener());
    // Configure the app.
    configure();
}
Also used : Path(org.apache.wicket.util.file.Path) WebApplicationPath(org.apache.wicket.core.util.file.WebApplicationPath) AutoLabelResolver(org.apache.wicket.markup.html.form.AutoLabelResolver) AjaxRequestHandler(org.apache.wicket.ajax.AjaxRequestHandler) WebApplicationPath(org.apache.wicket.core.util.file.WebApplicationPath) AutoLabelTextResolver(org.apache.wicket.markup.html.form.AutoLabelTextResolver) AutoLinkResolver(org.apache.wicket.markup.resolver.AutoLinkResolver) WebPageRenderer(org.apache.wicket.request.handler.render.WebPageRenderer) HttpSessionStore(org.apache.wicket.session.HttpSessionStore) ClassPathResourceFinder(org.apache.wicket.core.util.resource.ClassPathResourceFinder) IFileCleaner(org.apache.wicket.util.file.IFileCleaner) FileCleaner(org.apache.wicket.util.file.FileCleaner)

Example 3 with ClassPathResourceFinder

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

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

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

ClassPathResourceFinder (org.apache.wicket.core.util.resource.ClassPathResourceFinder)6 IResourceStreamLocator (org.apache.wicket.core.util.resource.locator.IResourceStreamLocator)4 ResourceStreamLocator (org.apache.wicket.core.util.resource.locator.ResourceStreamLocator)4 Test (org.junit.Test)4 Locale (java.util.Locale)3 CachingResourceStreamLocator (org.apache.wicket.core.util.resource.locator.caching.CachingResourceStreamLocator)3 IResourceStream (org.apache.wicket.util.resource.IResourceStream)3 AjaxRequestHandler (org.apache.wicket.ajax.AjaxRequestHandler)1 WebApplicationPath (org.apache.wicket.core.util.file.WebApplicationPath)1 AutoLabelResolver (org.apache.wicket.markup.html.form.AutoLabelResolver)1 AutoLabelTextResolver (org.apache.wicket.markup.html.form.AutoLabelTextResolver)1 DefaultButtonImageResourceFactory (org.apache.wicket.markup.html.image.resource.DefaultButtonImageResourceFactory)1 EnclosureHandler (org.apache.wicket.markup.parser.filter.EnclosureHandler)1 InlineEnclosureHandler (org.apache.wicket.markup.parser.filter.InlineEnclosureHandler)1 RelativePathPrefixHandler (org.apache.wicket.markup.parser.filter.RelativePathPrefixHandler)1 WicketLinkTagHandler (org.apache.wicket.markup.parser.filter.WicketLinkTagHandler)1 WicketMessageTagHandler (org.apache.wicket.markup.parser.filter.WicketMessageTagHandler)1 AutoLinkResolver (org.apache.wicket.markup.resolver.AutoLinkResolver)1 HtmlHeaderResolver (org.apache.wicket.markup.resolver.HtmlHeaderResolver)1 WicketContainerResolver (org.apache.wicket.markup.resolver.WicketContainerResolver)1