Package org.springframework.core.io

Examples of org.springframework.core.io.ResourceLoader


  public void shouldFindJpaMappingFilesFromNestedJarLocationsOnClasspath() {

    String nestedModule3Path = "org/springframework/data/jpa/support/module3/module3-orm.xml";
    final String fileInJarUrl = "jar:file:/foo/bar/lib/somelib.jar!/" + nestedModule3Path;

    ResourceLoader resolver = new PathMatchingResourcePatternResolver(new DefaultResourceLoader()) {

      public Resource[] getResources(String locationPattern) throws IOException {

        Resource[] resources = super.getResources(locationPattern);
        resources = Arrays.copyOf(resources, resources.length + 1);
View Full Code Here


    }

    @Test
    public void testLoadFromServlet() throws Throwable {
        final File rootFile = getFile("/test-http-request-factory-application-context.xml").getParentFile();
        configFileLoader.setServletContext(new MockServletContext(new ResourceLoader() {
            @Override
            public Resource getResource(String location) {
                final File file = new File(rootFile, location);
                if (file.exists()) {
                    return new FileSystemResource(file);
View Full Code Here

*/
public class WebContextLoader extends AbstractContextLoader {
  protected final MockServletContext servletContext;

  public WebContextLoader() {
    ResourceLoader resourceLoader = new FileSystemResourceLoader();
    this.servletContext = initServletContext("src/main/webapp", resourceLoader);
  }
View Full Code Here

    ResourceLoader resourceLoader = new FileSystemResourceLoader();
    this.servletContext = initServletContext("src/main/webapp", resourceLoader);
  }

  public WebContextLoader(String warRootDir, boolean isClasspathRelative) {
    ResourceLoader resourceLoader = isClasspathRelative ? new DefaultResourceLoader()
        : new FileSystemResourceLoader();
    this.servletContext = initServletContext(warRootDir, resourceLoader);
  }
View Full Code Here

    // Set bean properties from init parameters.
    try {
      PropertyValues pvs = new FilterConfigPropertyValues(filterConfig, this.requiredProperties);
      BeanWrapper bw = PropertyAccessorFactory.forBeanPropertyAccess(this);
      ResourceLoader resourceLoader = new ServletContextResourceLoader(filterConfig.getServletContext());
      bw.registerCustomEditor(Resource.class, new ResourceEditor(resourceLoader, this.environment));
      initBeanWrapper(bw);
      bw.setPropertyValues(pvs, true);
    }
    catch (BeansException ex) {
View Full Code Here

    // Set bean properties from init parameters.
    try {
      PropertyValues pvs = new ServletConfigPropertyValues(getServletConfig(), this.requiredProperties);
      BeanWrapper bw = PropertyAccessorFactory.forBeanPropertyAccess(this);
      ResourceLoader resourceLoader = new ServletContextResourceLoader(getServletContext());
      bw.registerCustomEditor(Resource.class, new ResourceEditor(resourceLoader, getEnvironment()));
      initBeanWrapper(bw);
      bw.setPropertyValues(pvs, true);
    }
    catch (BeansException ex) {
View Full Code Here

    // Set bean properties from init parameters.
    try {
      PropertyValues pvs = new PortletConfigPropertyValues(getPortletConfig(), this.requiredProperties);
      BeanWrapper bw = PropertyAccessorFactory.forBeanPropertyAccess(this);
      ResourceLoader resourceLoader = new PortletContextResourceLoader(getPortletContext());
      bw.registerCustomEditor(Resource.class, new ResourceEditor(resourceLoader, getEnvironment()));
      initBeanWrapper(bw);
      bw.setPropertyValues(pvs, true);
    }
    catch (BeansException ex) {
View Full Code Here

   * @see #getResourceLoader()
   * @see #loadBeanDefinitions(org.springframework.core.io.Resource)
   * @see #loadBeanDefinitions(org.springframework.core.io.Resource[])
   */
  public int loadBeanDefinitions(String location, Set<Resource> actualResources) throws BeanDefinitionStoreException {
    ResourceLoader resourceLoader = getResourceLoader();
    if (resourceLoader == null) {
      throw new BeanDefinitionStoreException(
          "Cannot import bean definitions from location [" + location + "]: no ResourceLoader available");
    }

    if (resourceLoader instanceof ResourcePatternResolver) {
      // Resource pattern matching available.
      try {
        Resource[] resources = ((ResourcePatternResolver) resourceLoader).getResources(location);
        int loadCount = loadBeanDefinitions(resources);
        if (actualResources != null) {
          for (Resource resource : resources) {
            actualResources.add(resource);
          }
        }
        if (logger.isDebugEnabled()) {
          logger.debug("Loaded " + loadCount + " bean definitions from location pattern [" + location + "]");
        }
        return loadCount;
      }
      catch (IOException ex) {
        throw new BeanDefinitionStoreException(
            "Could not resolve bean definition resource pattern [" + location + "]", ex);
      }
    }
    else {
      // Can only load single resources by absolute URL.
      Resource resource = resourceLoader.getResource(location);
      int loadCount = loadBeanDefinitions(resource);
      if (actualResources != null) {
        actualResources.add(resource);
      }
      if (logger.isDebugEnabled()) {
View Full Code Here

   * if none specified.
   */
  protected EntityResolver getEntityResolver() {
    if (this.entityResolver == null) {
      // Determine default EntityResolver to use.
      ResourceLoader resourceLoader = getResourceLoader();
      if (resourceLoader != null) {
        this.entityResolver = new ResourceEntityResolver(resourceLoader);
      }
      else {
        this.entityResolver = new DelegatingEntityResolver(getBeanClassLoader());
View Full Code Here

  }

  public void testVelocityEngineFactoryBeanWithNonFileResourceLoaderPath() throws Exception {
    VelocityEngineFactoryBean vefb = new VelocityEngineFactoryBean();
    vefb.setResourceLoaderPath("file:/mydir");
    vefb.setResourceLoader(new ResourceLoader() {
      @Override
      public Resource getResource(String location) {
        if (location.equals("file:/mydir") || location.equals("file:/mydir/test")) {
          return new ByteArrayResource("test".getBytes(), "test");
        }
View Full Code Here

TOP

Related Classes of org.springframework.core.io.ResourceLoader

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.