Example usage for org.springframework.web.context.support GenericWebApplicationContext getResources

List of usage examples for org.springframework.web.context.support GenericWebApplicationContext getResources

Introduction

In this page you can find the example usage for org.springframework.web.context.support GenericWebApplicationContext getResources.

Prototype

@Override
public Resource[] getResources(String locationPattern) throws IOException 

Source Link

Document

This implementation delegates to this context's ResourceLoader if it implements the ResourcePatternResolver interface, falling back to the default superclass behavior else.

Usage

From source file:org.jahia.test.framework.JahiaWebInitializer.java

@Override
public void initialize(GenericWebApplicationContext webAppContext) {
    try {//from  w  w w  . j a va 2  s  . c  o  m
        Resource[] resources = webAppContext
                .getResources("classpath*:org/jahia/config/jahiaunittest.properties");
        PropertiesFactoryBean propertiesFactory = new PropertiesFactoryBean();
        propertiesFactory.setLocations(resources);
        propertiesFactory.afterPropertiesSet();
        Properties properties = propertiesFactory.getObject();

        String jackrabbitHome = (String) properties.get("jahia.jackrabbit.home");
        if (jackrabbitHome != null) {
            jackrabbitHome = webAppContext.getResource(jackrabbitHome).getURL().getPath();
            File repoHome = new File(jackrabbitHome);
            if (!repoHome.exists()) {
                repoHome.mkdirs();
            }

            if (resources[0] != null && ResourceUtils.isJarURL(resources[0].getURL())) {
                URL jarUrl = ResourceUtils.extractJarFileURL(resources[0].getURL());
                try {
                    new JahiaArchiveFileHandler(jarUrl.getPath()).unzip("./target/test-repo", new PathFilter() {

                        @Override
                        public boolean accept(String path) {
                            // TODO Auto-generated method stub
                            return path.startsWith("WEB-INF");
                        }
                    });
                } catch (JahiaException e) {
                    logger.error("Unable to extract JAR");
                }
            } else if (resources[0] != null) {
                FileUtils.copyDirectory(
                        new File(StringUtils.substringBefore(resources[0].getURI().getPath(), "org"),
                                "WEB-INF"),
                        new File("./target/test-repo", "WEB-INF"));
            }
        }
    } catch (IOException e) {

    }
}