Example usage for org.springframework.web.context WebApplicationContext getResources

List of usage examples for org.springframework.web.context WebApplicationContext getResources

Introduction

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

Prototype

Resource[] getResources(String locationPattern) throws IOException;

Source Link

Document

Resolve the given location pattern into Resource objects.

Usage

From source file:com.freebox.engeneering.application.web.common.ApplicationContextListener.java

/**
 * Initializes the application context by web flow xml configs.
 * @param servletContextEvent the servlet context event.
 *///www  .  j  ava 2s.  c  o m
public void contextInitialized(ServletContextEvent servletContextEvent) {
    final ServletContext servletContext = servletContextEvent.getServletContext();
    final WebApplicationContext context = WebApplicationContextUtils
            .getRequiredWebApplicationContext(servletContext);

    String initParameter = servletContext.getInitParameter(CONFIG_LOCATION_PARAM);
    final String[] configLocations = getConfigLocations(context, initParameter);

    final Set<URL> xmlConfigs = new HashSet<URL>();
    for (String configLocation : configLocations) {
        try {
            final Resource[] locationResources = context.getResources(configLocation);
            for (Resource locationResource : locationResources) {
                xmlConfigs.add(locationResource.getURL());
            }
        } catch (IOException e) {
            if (LOGGER.isErrorEnabled()) {
                LOGGER.error("Could not find state chart configuration", e);
            }
        }
    }
    Assert.notEmpty(xmlConfigs, "Cannot find state chart configuration.");

    ApplicationContextLocator.setWebFlowConfiguration(xmlConfigs);
    ApplicationContextLocator.setApplicationContext(context);

    final FlowConfigurationLoader flowConfigurationLoader = (FlowConfigurationLoader) context
            .getBean("flowConfigurationLoader");
    flowConfigurationLoader.init(xmlConfigs);
}

From source file:org.sakaiproject.component.impl.ContextLoader.java

/**
 * Initialize the local ApplicationContext, link it to the shared context, and load shared definitions into the shared context.
 * /*from w  w w  .  ja  v a  2  s.  c o  m*/
 * @param servletContext
 *        current servlet context
 * @return the new WebApplicationContext
 * @throws BeansException
 *         if the context couldn't be initialized
 */
public WebApplicationContext initWebApplicationContext(ServletContext servletContext) throws BeansException {
    WebApplicationContext rv = super.initWebApplicationContext(servletContext);

    // if we have a parent and any shared bean definitions, load them into the parent
    ConfigurableApplicationContext parent = (ConfigurableApplicationContext) rv.getParent();
    if (parent != null) {
        String sharedConfig = servletContext.getInitParameter(SHARED_LOCATION_PARAM);
        if (sharedConfig != null) {
            String[] locations = StringUtils.tokenizeToStringArray(sharedConfig,
                    ConfigurableWebApplicationContext.CONFIG_LOCATION_DELIMITERS);
            if (locations != null) {
                XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(
                        (BeanDefinitionRegistry) parent.getBeanFactory());

                for (int i = 0; i < locations.length; i++) {
                    try {
                        reader.loadBeanDefinitions(rv.getResources(locations[i]));
                    } catch (IOException e) {
                        M_log.warn("exception loading into parent: " + e);
                    }
                }
            }
        }
    }

    return rv;
}