use of org.grails.core.support.internal.tools.ClassRelativeResourcePatternResolver in project grails-core by grails.
the class PluginAwareResourceBundleMessageSource method afterPropertiesSet.
public void afterPropertiesSet() throws Exception {
if (pluginCacheMillis == Long.MIN_VALUE) {
pluginCacheMillis = cacheMillis;
}
if (localResourceLoader == null) {
return;
}
Resource[] resources;
if (Environment.isDevelopmentEnvironmentAvailable()) {
File[] propertiesFiles = new File(BuildSettings.BASE_DIR, GRAILS_APP_I18N_PATH_COMPONENT).listFiles(new FilenameFilter() {
@Override
public boolean accept(File dir, String name) {
return name.endsWith(".properties");
}
});
if (propertiesFiles != null && propertiesFiles.length > 0) {
List<Resource> resourceList = new ArrayList<Resource>(propertiesFiles.length);
for (File propertiesFile : propertiesFiles) {
resourceList.add(new FileSystemResource(propertiesFile));
}
resources = resourceList.toArray(new Resource[resourceList.size()]);
} else {
resources = new Resource[0];
}
} else {
if (searchClasspath) {
resources = resourceResolver.getResources(messageBundleLocationPattern);
} else {
DefaultGrailsApplication defaultGrailsApplication = (DefaultGrailsApplication) application;
if (defaultGrailsApplication != null) {
GrailsApplicationClass applicationClass = defaultGrailsApplication.getApplicationClass();
if (applicationClass != null) {
ResourcePatternResolver resourcePatternResolver = new ClassRelativeResourcePatternResolver(applicationClass.getClass());
resources = resourcePatternResolver.getResources(messageBundleLocationPattern);
} else {
resources = resourceResolver.getResources(messageBundleLocationPattern);
}
} else {
resources = resourceResolver.getResources(messageBundleLocationPattern);
}
}
}
List<String> basenames = new ArrayList<String>();
for (Resource resource : resources) {
String filename = resource.getFilename();
String baseName = GrailsStringUtils.getFileBasename(filename);
int i = baseName.indexOf('_');
if (i > -1) {
baseName = baseName.substring(0, i);
}
if (!basenames.contains(baseName) && !baseName.equals(""))
basenames.add(baseName);
}
setBasenames(basenames.toArray(new String[basenames.size()]));
}
Aggregations