001/*002 * Copyright 2002-2016 the original author or authors.003 *004 * Licensed under the Apache License, Version 2.0 (the "License");005 * you may not use this file except in compliance with the License.006 * You may obtain a copy of the License at007 *008 * https://www.apache.org/licenses/LICENSE-2.0009 *010 * Unless required by applicable law or agreed to in writing, software011 * distributed under the License is distributed on an "AS IS" BASIS,012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.013 * See the License for the specific language governing permissions and014 * limitations under the License.015 */016017package org.springframework.core.io;018019import java.net.MalformedURLException;020import java.net.URL;021import java.util.Collection;022import java.util.LinkedHashSet;023import java.util.Set;024025import org.springframework.util.Assert;026import org.springframework.util.ClassUtils;027import org.springframework.util.StringUtils;028029/**030 * Default implementation of the {@link ResourceLoader} interface.031 * Used by {@link ResourceEditor}, and serves as base class for032 * {@link org.springframework.context.support.AbstractApplicationContext}.033 * Can also be used standalone.034 *035 * <p>Will return a {@link UrlResource} if the location value is a URL,036 * and a {@link ClassPathResource} if it is a non-URL path or a037 * "classpath:" pseudo-URL.038 *039 * @author Juergen Hoeller040 * @since 10.03.2004041 * @see FileSystemResourceLoader042 * @see org.springframework.context.support.ClassPathXmlApplicationContext043 */044public class DefaultResourceLoader implements ResourceLoader {045046 private ClassLoader classLoader;047048 private final Set<ProtocolResolver> protocolResolvers = new LinkedHashSet<ProtocolResolver>(4);049050051 /**052 * Create a new DefaultResourceLoader.053 * <p>ClassLoader access will happen using the thread context class loader054 * at the time of this ResourceLoader's initialization.055 * @see java.lang.Thread#getContextClassLoader()056 */057 public DefaultResourceLoader() {058 this.classLoader = ClassUtils.getDefaultClassLoader();059 }060061 /**062 * Create a new DefaultResourceLoader.063 * @param classLoader the ClassLoader to load class path resources with, or {@code null}064 * for using the thread context class loader at the time of actual resource access065 */066 public DefaultResourceLoader(ClassLoader classLoader) {067 this.classLoader = classLoader;068 }069070071 /**072 * Specify the ClassLoader to load class path resources with, or {@code null}073 * for using the thread context class loader at the time of actual resource access.074 * <p>The default is that ClassLoader access will happen using the thread context075 * class loader at the time of this ResourceLoader's initialization.