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

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

Introduction

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

Prototype

@Override
public Resource getResource(String location) 

Source Link

Document

This implementation delegates to this context's ResourceLoader if set, 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 {/*  ww w  .  jav  a 2  s  .  c  om*/
        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) {

    }
}