use of org.apache.wicket.core.util.resource.locator.IResourceStreamLocator in project wiquery by WiQuery.
the class DatePickerLanguageResourceReferenceTestCase method testGetDatePickerLanguages.
@Test
public void testGetDatePickerLanguages() {
Locale nonavailableLocale = new Locale("wiquery");
Locale availableLocale = DatePickerLanguages.ARMENIAN.getLocale();
assertNull(DatePickerLanguages.getDatePickerLanguages(nonavailableLocale));
assertNull(DatePickerLanguageResourceReference.get(nonavailableLocale));
assertNotNull(DatePickerLanguages.getDatePickerLanguages(availableLocale));
assertNotNull(DatePickerLanguageResourceReference.get(availableLocale));
for (DatePickerLanguages language : DatePickerLanguages.values()) {
// assert if the language getter is implemented correctly to return
// the exact variant.
assertEquals(language, DatePickerLanguages.getDatePickerLanguages(language.getLocale()));
// assert if the reference getter is implemented correctly to return
// a reference to the exact variant.
DatePickerLanguageResourceReference ref = DatePickerLanguageResourceReference.get(language.getLocale());
assertNotNull(ref);
// assert if the file is actually there.
IResourceStreamLocator locator = Application.get().getResourceSettings().getResourceStreamLocator();
String absolutePath = Packages.absolutePath(DatePickerLanguageResourceReference.class, DatePickerLanguages.getJsFileName(language));
assertNotNull("Resource " + DatePickerLanguages.getJsFileName(language) + " for locale " + language.getLocale() + " does not exist!", locator.locate(DatePickerLanguageResourceReference.class, absolutePath));
}
}
use of org.apache.wicket.core.util.resource.locator.IResourceStreamLocator in project wicket by apache.
the class BorderBehavior method findMarkupStream.
/**
* @param owner
* @return markup stream
*/
private MarkupStream findMarkupStream(final Component owner) {
final MarkupType markupType = getMarkupType(owner);
if (markupType == null) {
return null;
}
// TODO we need to expose this functionality for any class not just for
// markupcontainers in markupcache so we don't have to replicate this
// logic here
// Get locator to search for the resource
final IResourceStreamLocator locator = Application.get().getResourceSettings().getResourceStreamLocator();
final String style = owner.getStyle();
final String variation = owner.getVariation();
final Locale locale = owner.getLocale();
MarkupResourceStream markupResourceStream = null;
Class<?> containerClass = getClass();
while (!(containerClass.equals(BorderBehavior.class))) {
String path = containerClass.getName().replace('.', '/');
IResourceStream resourceStream = locator.locate(containerClass, path, style, variation, locale, markupType.getExtension(), false);
// Did we find it already?
if (resourceStream != null) {
ContainerInfo ci = new ContainerInfo(containerClass, locale, style, variation, markupType);
markupResourceStream = new MarkupResourceStream(resourceStream, ci, containerClass);
break;
}
// Walk up the class hierarchy one level, if markup has not
// yet been found
containerClass = containerClass.getSuperclass();
}
if (markupResourceStream == null) {
throw new WicketRuntimeException("Could not find markup for component border `" + getClass().getName() + "`");
}
try {
IMarkupFragment markup = MarkupFactory.get().newMarkupParser(markupResourceStream).parse();
return new MarkupStream(markup);
} catch (Exception e) {
throw new WicketRuntimeException("Could not parse markup from markup resource stream: " + markupResourceStream.toString(), e);
} finally {
try {
markupResourceStream.close();
} catch (IOException e) {
throw new WicketRuntimeException("Cannot close markup resource stream: " + markupResourceStream, e);
}
}
}
use of org.apache.wicket.core.util.resource.locator.IResourceStreamLocator 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;
}
use of org.apache.wicket.core.util.resource.locator.IResourceStreamLocator 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";
}
use of org.apache.wicket.core.util.resource.locator.IResourceStreamLocator 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())));
}
Aggregations