Search in sources :

Example 1 with IResourceStreamLocator

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

the class PackageResource method internalGetResourceStream.

private IResourceStream internalGetResourceStream(final String style, final Locale locale) {
    IResourceStreamLocator resourceStreamLocator = Application.get().getResourceSettings().getResourceStreamLocator();
    IResourceStream resourceStream = resourceStreamLocator.locate(getScope(), absolutePath, style, variation, locale, null, false);
    String realPath = absolutePath;
    if (resourceStream instanceof IFixedLocationResourceStream) {
        realPath = ((IFixedLocationResourceStream) resourceStream).locationAsString();
        if (realPath != null) {
            int index = realPath.indexOf(absolutePath);
            if (index != -1) {
                realPath = realPath.substring(index);
            }
        } else {
            realPath = absolutePath;
        }
    }
    if (accept(realPath) == false) {
        throw new PackageResourceBlockedException("Access denied to (static) package resource " + absolutePath + ". See IPackageResourceGuard");
    }
    if (resourceStream != null) {
        resourceStream = new ProcessingResourceStream(resourceStream);
    }
    return resourceStream;
}
Also used : IResourceStream(org.apache.wicket.util.resource.IResourceStream) IResourceStreamLocator(org.apache.wicket.core.util.resource.locator.IResourceStreamLocator) IFixedLocationResourceStream(org.apache.wicket.util.resource.IFixedLocationResourceStream)

Example 2 with IResourceStreamLocator

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

the class PackageResourceReference method getUrlAttributes.

private ResourceReference.UrlAttributes getUrlAttributes(Locale locale, String style, String variation) {
    IResourceStreamLocator locator = Application.get().getResourceSettings().getResourceStreamLocator();
    String absolutePath = Packages.absolutePath(getScope(), getName());
    IResourceStream stream = locator.locate(getScope(), absolutePath, style, variation, locale, null, false);
    if (stream == null)
        return new ResourceReference.UrlAttributes(null, null, null);
    return new ResourceReference.UrlAttributes(stream.getLocale(), stream.getStyle(), stream.getVariation());
}
Also used : IResourceStream(org.apache.wicket.util.resource.IResourceStream) IResourceStreamLocator(org.apache.wicket.core.util.resource.locator.IResourceStreamLocator)

Example 3 with IResourceStreamLocator

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

the class ResourceStreamLocatorTest method createAndTestResource.

/**
 * @param sourcePath
 * @param style
 * @param variation
 * @param locale
 * @param extension
 */
public void createAndTestResource(IResourceFinder sourcePath, String style, String variation, Locale locale, String extension) {
    IResourceStreamLocator locator = new ResourceStreamLocator(sourcePath);
    IResourceStream resource = locator.locate(this.getClass(), this.getClass().getName().replace('.', '/'), style, variation, locale, "txt", false);
    compareFilename(resource, extension);
}
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)

Example 4 with IResourceStreamLocator

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

the class CachingResourceStreamLocatorTest method fileResource.

/**
 * Tests FileResourceStreamReference
 */
@Test
public void fileResource() {
    IResourceStreamLocator resourceStreamLocator = mock(IResourceStreamLocator.class);
    FileResourceStream frs = new FileResourceStream(new File("."));
    when(resourceStreamLocator.locate(String.class, "path", "style", "variation", null, "extension", true)).thenReturn(frs);
    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);
    // there is a file resource with that Key so expect just one call to the delegate
    verify(resourceStreamLocator, times(1)).locate(String.class, "path", "style", "variation", null, "extension", true);
}
Also used : FileResourceStream(org.apache.wicket.util.resource.FileResourceStream) CachingResourceStreamLocator(org.apache.wicket.core.util.resource.locator.caching.CachingResourceStreamLocator) IResourceStreamLocator(org.apache.wicket.core.util.resource.locator.IResourceStreamLocator) File(java.io.File) Test(org.junit.Test)

Example 5 with IResourceStreamLocator

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

the class CachingResourceStreamLocatorTest method urlResource.

/**
 * Tests UrlResourceStreamReference
 *
 * @throws Exception
 */
@Test
public void urlResource() throws Exception {
    IResourceStreamLocator resourceStreamLocator = mock(IResourceStreamLocator.class);
    UrlResourceStream urs = new UrlResourceStream(new URL("file:///"));
    when(resourceStreamLocator.locate(String.class, "path")).thenReturn(urs);
    CachingResourceStreamLocator cachingLocator = new CachingResourceStreamLocator(resourceStreamLocator);
    cachingLocator.locate(String.class, "path");
    cachingLocator.locate(String.class, "path");
    // there is a url resource with that Key so expect just one call to the delegate
    verify(resourceStreamLocator, times(1)).locate(String.class, "path");
}
Also used : UrlResourceStream(org.apache.wicket.core.util.resource.UrlResourceStream) CachingResourceStreamLocator(org.apache.wicket.core.util.resource.locator.caching.CachingResourceStreamLocator) IResourceStreamLocator(org.apache.wicket.core.util.resource.locator.IResourceStreamLocator) URL(java.net.URL) Test(org.junit.Test)

Aggregations

IResourceStreamLocator (org.apache.wicket.core.util.resource.locator.IResourceStreamLocator)18 Test (org.junit.Test)11 CachingResourceStreamLocator (org.apache.wicket.core.util.resource.locator.caching.CachingResourceStreamLocator)10 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 MidPointApplicationConfiguration (com.evolveum.midpoint.gui.api.util.MidPointApplicationConfiguration)1 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)1 PageMounter (com.evolveum.midpoint.web.application.PageMounter)1 MidPointResourceStreamLocator (com.evolveum.midpoint.web.util.MidPointResourceStreamLocator)1 MidPointStringResourceLoader (com.evolveum.midpoint.web.util.MidPointStringResourceLoader)1 SystemConfigurationType (com.evolveum.midpoint.xml.ns._public.common.common_3.SystemConfigurationType)1 IOException (java.io.IOException)1 URL (java.net.URL)1 ServletContext (javax.servlet.ServletContext)1 WicketRuntimeException (org.apache.wicket.WicketRuntimeException)1 AbstractDefaultAjaxBehavior (org.apache.wicket.ajax.AbstractDefaultAjaxBehavior)1