Search in sources :

Example 1 with GrailsApplicationClass

use of grails.core.GrailsApplicationClass 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.isDevelopmentMode()) {
        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()]));
}
Also used : PathMatchingResourcePatternResolver(org.springframework.core.io.support.PathMatchingResourcePatternResolver) CachingPathMatchingResourcePatternResolver(org.grails.core.io.CachingPathMatchingResourcePatternResolver) ResourcePatternResolver(org.springframework.core.io.support.ResourcePatternResolver) ClassRelativeResourcePatternResolver(org.grails.core.support.internal.tools.ClassRelativeResourcePatternResolver) GrailsApplicationClass(grails.core.GrailsApplicationClass) Resource(org.springframework.core.io.Resource) FileSystemResource(org.springframework.core.io.FileSystemResource) ArrayList(java.util.ArrayList) FileSystemResource(org.springframework.core.io.FileSystemResource) DefaultGrailsApplication(grails.core.DefaultGrailsApplication) FilenameFilter(java.io.FilenameFilter) ClassRelativeResourcePatternResolver(org.grails.core.support.internal.tools.ClassRelativeResourcePatternResolver) File(java.io.File)

Aggregations

DefaultGrailsApplication (grails.core.DefaultGrailsApplication)1 GrailsApplicationClass (grails.core.GrailsApplicationClass)1 File (java.io.File)1 FilenameFilter (java.io.FilenameFilter)1 ArrayList (java.util.ArrayList)1 CachingPathMatchingResourcePatternResolver (org.grails.core.io.CachingPathMatchingResourcePatternResolver)1 ClassRelativeResourcePatternResolver (org.grails.core.support.internal.tools.ClassRelativeResourcePatternResolver)1 FileSystemResource (org.springframework.core.io.FileSystemResource)1 Resource (org.springframework.core.io.Resource)1 PathMatchingResourcePatternResolver (org.springframework.core.io.support.PathMatchingResourcePatternResolver)1 ResourcePatternResolver (org.springframework.core.io.support.ResourcePatternResolver)1