Search in sources :

Example 1 with ServletContextResource

use of org.springframework.web.context.support.ServletContextResource in project grails-core by grails.

the class GrailsWebApplicationContext method prepareBeanFactory.

@Override
protected void prepareBeanFactory(ConfigurableListableBeanFactory beanFactory) {
    if (configLocations.length > 0) {
        for (String configLocation : configLocations) {
            BeanBuilder beanBuilder = new BeanBuilder(getParent(), getClassLoader());
            final ServletContextResource resource = new ServletContextResource(getServletContext(), configLocation);
            beanBuilder.loadBeans(resource);
            beanBuilder.registerBeans(this);
        }
    }
    super.prepareBeanFactory(beanFactory);
}
Also used : BeanBuilder(grails.spring.BeanBuilder) ServletContextResource(org.springframework.web.context.support.ServletContextResource)

Example 2 with ServletContextResource

use of org.springframework.web.context.support.ServletContextResource in project spring-framework by spring-projects.

the class PathResourceResolverTests method checkServletContextResource.

// SPR-12432
@Test
public void checkServletContextResource() throws Exception {
    Resource classpathLocation = new ClassPathResource("test/", PathResourceResolver.class);
    MockServletContext context = new MockServletContext();
    ServletContextResource servletContextLocation = new ServletContextResource(context, "/webjars/");
    ServletContextResource resource = new ServletContextResource(context, "/webjars/webjar-foo/1.0/foo.js");
    assertFalse(this.resolver.checkResource(resource, classpathLocation));
    assertTrue(this.resolver.checkResource(resource, servletContextLocation));
}
Also used : ServletContextResource(org.springframework.web.context.support.ServletContextResource) UrlResource(org.springframework.core.io.UrlResource) ClassPathResource(org.springframework.core.io.ClassPathResource) ServletContextResource(org.springframework.web.context.support.ServletContextResource) Resource(org.springframework.core.io.Resource) ClassPathResource(org.springframework.core.io.ClassPathResource) MockServletContext(org.springframework.mock.web.test.MockServletContext) Test(org.junit.Test)

Example 3 with ServletContextResource

use of org.springframework.web.context.support.ServletContextResource in project OpenClinica by OpenClinica.

the class SpringServletAccess method getPropertiesDir.

public static String getPropertiesDir(ServletContext servletContext) {
    String resource = "properties/placeholder.properties";
    ServletContextResource scr = (ServletContextResource) getApplicationContext(servletContext).getResource(resource);
    String absolutePath = null;
    try {
        absolutePath = scr.getFile().getAbsolutePath();
    } catch (IOException e) {
        throw new OpenClinicaSystemException(e.getMessage(), e.fillInStackTrace());
    }
    absolutePath = absolutePath.replaceAll("placeholder.properties", "");
    return absolutePath;
}
Also used : ServletContextResource(org.springframework.web.context.support.ServletContextResource) IOException(java.io.IOException) OpenClinicaSystemException(org.akaza.openclinica.exception.OpenClinicaSystemException)

Example 4 with ServletContextResource

use of org.springframework.web.context.support.ServletContextResource in project OpenClinica by OpenClinica.

the class SpringServletAccess method getPropertiesDir.

public static String getPropertiesDir(ServletContext servletContext) {
    String resource = "properties/placeholder.properties";
    ServletContextResource scr = (ServletContextResource) getApplicationContext(servletContext).getResource(resource);
    String absolutePath = null;
    try {
        absolutePath = scr.getFile().getAbsolutePath();
    } catch (IOException e) {
        throw new OpenClinicaSystemException(e.getMessage(), e.fillInStackTrace());
    }
    absolutePath = absolutePath.replaceAll("placeholder.properties", "");
    return absolutePath;
}
Also used : ServletContextResource(org.springframework.web.context.support.ServletContextResource) IOException(java.io.IOException) OpenClinicaSystemException(org.akaza.openclinica.exception.OpenClinicaSystemException)

Aggregations

ServletContextResource (org.springframework.web.context.support.ServletContextResource)4 IOException (java.io.IOException)2 OpenClinicaSystemException (org.akaza.openclinica.exception.OpenClinicaSystemException)2 BeanBuilder (grails.spring.BeanBuilder)1 Test (org.junit.Test)1 ClassPathResource (org.springframework.core.io.ClassPathResource)1 Resource (org.springframework.core.io.Resource)1 UrlResource (org.springframework.core.io.UrlResource)1 MockServletContext (org.springframework.mock.web.test.MockServletContext)1