Search in sources :

Example 6 with ModuleClassLoader

use of org.openmrs.module.ModuleClassLoader in project openmrs-core by openmrs.

the class MutableResourceBundleMessageSource method findPropertiesFiles.

/**
 * Searches the filesystem for message properties files. ABKTODO: consider caching this, rather
 * than searching every time
 *
 * @return an array of property file names
 */
private Resource[] findPropertiesFiles() {
    Set<Resource> resourceSet = new HashSet<>();
    try {
        String pattern = "classpath*:messages*.properties";
        ResourcePatternResolver resourceResolver = new PathMatchingResourcePatternResolver(OpenmrsClassLoader.getInstance());
        Resource[] propertiesFiles = resourceResolver.getResources(pattern);
        Collections.addAll(resourceSet, propertiesFiles);
        for (ModuleClassLoader moduleClassLoader : ModuleFactory.getModuleClassLoaders()) {
            resourceResolver = new PathMatchingResourcePatternResolver(moduleClassLoader);
            propertiesFiles = resourceResolver.getResources(pattern);
            Collections.addAll(resourceSet, propertiesFiles);
        }
    } catch (IOException e) {
        log.error("Error generated", e);
    }
    if (log.isWarnEnabled() && (resourceSet.isEmpty())) {
        log.warn("No properties files found.");
    }
    return resourceSet.toArray(new Resource[resourceSet.size()]);
}
Also used : PathMatchingResourcePatternResolver(org.springframework.core.io.support.PathMatchingResourcePatternResolver) ResourcePatternResolver(org.springframework.core.io.support.ResourcePatternResolver) ModuleClassLoader(org.openmrs.module.ModuleClassLoader) Resource(org.springframework.core.io.Resource) IOException(java.io.IOException) PathMatchingResourcePatternResolver(org.springframework.core.io.support.PathMatchingResourcePatternResolver) HashSet(java.util.HashSet)

Aggregations

ModuleClassLoader (org.openmrs.module.ModuleClassLoader)6 URL (java.net.URL)3 HashSet (java.util.HashSet)3 URI (java.net.URI)2 URISyntaxException (java.net.URISyntaxException)2 ArrayList (java.util.ArrayList)2 IOException (java.io.IOException)1 Resource (org.springframework.core.io.Resource)1 PathMatchingResourcePatternResolver (org.springframework.core.io.support.PathMatchingResourcePatternResolver)1 ResourcePatternResolver (org.springframework.core.io.support.ResourcePatternResolver)1