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;
}
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());
}
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);
}
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);
}
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");
}
Aggregations