use of org.apache.wicket.core.util.resource.locator.IResourceStreamLocator in project wicket by apache.
the class CachingResourceStreamLocatorTest method notExistingResource.
/**
* Tests NullResourceStreamReference
*/
@Test
public void notExistingResource() {
IResourceStreamLocator resourceStreamLocator = mock(IResourceStreamLocator.class);
CachingResourceStreamLocator cachingLocator = new CachingResourceStreamLocator(resourceStreamLocator);
cachingLocator.locate(String.class, "path");
cachingLocator.locate(String.class, "path");
// there is no resource with that Key so a "miss" will be cached and expect 1 call to the
// delegate
verify(resourceStreamLocator, times(1)).locate(String.class, "path");
}
use of org.apache.wicket.core.util.resource.locator.IResourceStreamLocator in project wicket by apache.
the class CachingResourceStreamLocatorTest method fileResourceDifferentExtensions.
/**
* Tests two FileResourceStreamReferences with different extensions
*/
@Test
public void fileResourceDifferentExtensions() {
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);
cachingLocator.locate(String.class, "path", "style", "variation", null, "extension2", 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);
verify(resourceStreamLocator, times(1)).locate(String.class, "path", "style", "variation", null, "extension2", true);
}
use of org.apache.wicket.core.util.resource.locator.IResourceStreamLocator 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())));
}
use of org.apache.wicket.core.util.resource.locator.IResourceStreamLocator in project wicket by apache.
the class MarkupParserTest method fileDocument.
/**
* @throws ParseException
* @throws ResourceStreamNotFoundException
* @throws IOException
*/
@Test
public void fileDocument() throws ParseException, ResourceStreamNotFoundException, IOException {
IResourceStreamLocator locator = new ResourceStreamLocator();
MarkupResourceStream resource = newMarkupResourceStream(locator, getClass(), "1", null, null, "html");
MarkupParser parser = new MarkupParser(resource);
parser.setWicketNamespace("wcn");
IMarkupFragment tokens = parser.parse();
log.info("tok(0)=" + tokens.get(0));
// Assert.assertEquals(docText, tokens.get(0).toString());
resource = newMarkupResourceStream(locator, getClass(), "2", null, null, "html");
parser = new MarkupParser(resource);
parser.setWicketNamespace("wcn");
tokens = parser.parse();
log.info("tok(0)=" + tokens.get(0));
// Assert.assertEquals(docText, tokens.get(0).toString());
resource = newMarkupResourceStream(locator, getClass(), "3", null, null, "html");
parser = new MarkupParser(resource);
parser.setWicketNamespace("wcn");
tokens = parser.parse();
log.info("tok(0)=" + tokens.get(0));
// Assert.assertEquals(docText, tokens.get(0).toString());
resource = newMarkupResourceStream(locator, getClass(), "4", null, null, "html");
parser = new MarkupParser(resource);
parser.setWicketNamespace("wcn");
tokens = parser.parse();
log.info("tok(0)=" + tokens.get(0));
// Assert.assertEquals(docText, tokens.get(0).toString());
// File from jar (URL resource)
resource = newMarkupResourceStream(locator, PageExpiredErrorPage.class, null, null, null, "html");
parser = new MarkupParser(resource);
parser.setWicketNamespace("wcn");
tokens = parser.parse();
log.info("tok(0)=" + tokens.get(0));
// Assert.assertEquals(docText, tokens.get(0).toString());
resource = newMarkupResourceStream(locator, getClass(), "5", null, null, "html");
parser = new MarkupParser(resource);
parser.setWicketNamespace("wcn");
tokens = parser.parse();
log.info("tok(0)=" + tokens.get(0));
// Assert.assertEquals(docText, tokens.get(0).toString());
resource = newMarkupResourceStream(locator, getClass(), "6", null, null, "html");
parser = new MarkupParser(resource);
parser.setWicketNamespace("wcn");
tokens = parser.parse();
log.info("tok(0)=" + tokens.get(0));
// Assert.assertEquals(docText, tokens.get(0).toString());
resource = newMarkupResourceStream(locator, getClass(), "7", null, null, "html");
parser = new MarkupParser(resource);
parser.setWicketNamespace("wcn");
tokens = parser.parse();
log.info("tok(0)=" + tokens.get(0));
// Assert.assertEquals(docText, tokens.get(0).toString());
resource = newMarkupResourceStream(locator, getClass(), "8", null, null, "html");
parser = new MarkupParser(resource);
parser.setWicketNamespace("wcn");
tokens = parser.parse();
log.info("tok(0)=" + tokens.get(0));
// Assert.assertEquals(docText, tokens.get(0).toString());
resource = newMarkupResourceStream(locator, getClass(), "9", null, null, "html");
parser = new MarkupParser(resource);
parser.setWicketNamespace("wcn");
tokens = parser.parse();
log.info("tok(0)=" + tokens.get(0));
// Assert.assertEquals(docText, tokens.get(0).toString());
}
use of org.apache.wicket.core.util.resource.locator.IResourceStreamLocator in project wicket by apache.
the class DefaultMarkupResourceStreamProvider method getMarkupResourceStream.
/**
* Create a new markup resource stream for the container.
* <p>
* Note: it will only called once, the IResourceStream will be cached by MarkupCache.
* <p>
* Note: IResourceStreamLocators should be used in case the strategy to find a markup resource
* should be extended for ALL components of your application.
*
* @see org.apache.wicket.core.util.resource.locator.IResourceStreamLocator
* @see org.apache.wicket.markup.DefaultMarkupResourceStreamProvider
*
* @param container
* @param containerClass
* The container the markup should be associated with
* @return A IResourceStream if the resource was found
*/
@Override
public IResourceStream getMarkupResourceStream(final MarkupContainer container, Class<?> containerClass) {
// Get locator to search for the resource
final IResourceStreamLocator locator = Application.get().getResourceSettings().getResourceStreamLocator();
String style = container.getStyle();
String variation = container.getVariation();
Locale locale = container.getLocale();
MarkupType markupType = container.getMarkupType();
String ext = (markupType != null ? markupType.getExtension() : null);
// resource.
while (containerClass != MarkupContainer.class) {
String path = containerClass.getName().replace('.', '/');
IResourceStream resourceStream = locator.locate(containerClass, path, style, variation, locale, ext, false);
// Did we find it already?
if (resourceStream != null) {
return new MarkupResourceStream(resourceStream, new ContainerInfo(containerClass, container), containerClass);
}
// Walk up the class hierarchy one level, if markup has not
// yet been found
containerClass = containerClass.getSuperclass();
}
return null;
}
Aggregations