use of org.grails.core.io.StaticResourceLoader in project grails-core by grails.
the class StaticResourceLoaderTests method testGetResource.
public void testGetResource() throws Exception {
StaticResourceLoader srl = new StaticResourceLoader();
srl.setBaseResource(new UrlResource("http://grails.org"));
Resource r = srl.getResource("/Home");
assertEquals("http://grails.org/Home", r.getURL().toString());
}
use of org.grails.core.io.StaticResourceLoader in project grails-core by grails.
the class StaticResourceLoaderTests method testIllegalState.
public void testIllegalState() {
StaticResourceLoader srl = new StaticResourceLoader();
try {
srl.getResource("/foo");
fail("Should have thrown IllegalStateException");
} catch (IllegalStateException ise) {
// expected
}
}
use of org.grails.core.io.StaticResourceLoader in project grails-core by grails.
the class BinaryGrailsPlugin method getProperties.
/**
* Obtains all properties for this binary plugin for the given locale.
*
* Note this method does not cache so clients should in general cache the results of this method.
*
* @param locale The locale
* @return The properties or null if non exist
*/
public Properties getProperties(final Locale locale) {
Resource url = this.baseResourcesResource;
Properties properties = null;
if (url != null) {
StaticResourceLoader resourceLoader = new StaticResourceLoader();
resourceLoader.setBaseResource(url);
ResourcePatternResolver resolver = new PathMatchingResourcePatternResolver(resourceLoader);
try {
// first load all properties
Resource[] resources = resolver.getResources('*' + PROPERTIES_EXTENSION);
resources = resources.length > 0 ? filterResources(resources, locale) : resources;
if (resources.length > 0) {
properties = new Properties();
// message bundles are locale specific. The more underscores the locale has the more specific the locale
// so we order by the number of underscores present so that the most specific appears
Arrays.sort(resources, new Comparator<Resource>() {
@Override
public int compare(Resource o1, Resource o2) {
String f1 = o1.getFilename();
String f2 = o2.getFilename();
int firstUnderscoreCount = StringUtils.countOccurrencesOf(f1, "_");
int secondUnderscoreCount = StringUtils.countOccurrencesOf(f2, "_");
if (firstUnderscoreCount == secondUnderscoreCount) {
return 0;
} else {
return firstUnderscoreCount > secondUnderscoreCount ? 1 : -1;
}
}
});
loadFromResources(properties, resources);
}
} catch (IOException e) {
return null;
}
}
return properties;
}
Aggregations