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 at 007 * 008 * https://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * 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 and 014 * limitations under the License. 015 */ 016 017package org.springframework.core.io; 018 019import org.springframework.util.ResourceUtils; 020 021/** 022 * Strategy interface for loading resources (e.. class path or file system 023 * resources). An {@link org.springframework.context.ApplicationContext} 024 * is required to provide this functionality, plus extended 025 * {@link org.springframework.core.io.support.ResourcePatternResolver} support. 026 * 027 * <p>{@link DefaultResourceLoader} is a standalone implementation that is 028 * usable outside an ApplicationContext, also used by {@link ResourceEditor}. 029 * 030 * <p>Bean properties of type Resource and Resource array can be populated 031 * from Strings when running in an ApplicationContext, using the particular 032 * context's resource loading strategy. 033 * 034 * @author Juergen Hoeller 035 * @since 10.03.2004 036 * @see Resource 037 * @see org.springframework.core.io.support.ResourcePatternResolver 038 * @see org.springframework.context.ApplicationContext 039 * @see org.springframework.context.ResourceLoaderAware 040 */ 041public interface ResourceLoader { 042 043 /** Pseudo URL prefix for loading from the class path: "classpath:" */ 044 String CLASSPATH_URL_PREFIX = ResourceUtils.CLASSPATH_URL_PREFIX; 045 046 047 /** 048 * Return a Resource handle for the specified resource location. 049 * <p>The handle should always be a reusable resource descriptor, 050 * allowing for multiple {@link Resource#getInputStream()} calls. 051 * <p><ul> 052 * <li>Must support fully qualified URLs, e.g. "file:C:/test.dat". 053 * <li>Must support classpath pseudo-URLs, e.g. "classpath:test.dat". 054 * <li>Should support relative file paths, e.g. "WEB-INF/test.dat". 055 * (This will be implementation-specific, typically provided by an 056 * ApplicationContext implementation.) 057 * </ul> 058 * <p>Note that a Resource handle does not imply an existing resource; 059 * you need to invoke {@link Resource#exists} to check for existence. 060 * @param location the resource location 061 * @return a corresponding Resource handle (never {@code null}) 062 * @see #CLASSPATH_URL_PREFIX 063 * @see Resource#exists() 064 * @see Resource#getInputStream() 065 */ 066 Resource getResource(String location); 067 068 /** 069 * Expose the ClassLoader used by this ResourceLoader. 070 * <p>Clients which need to access the ClassLoader directly can do so 071 * in a uniform manner with the ResourceLoader, rather than relying 072 * on the thread context ClassLoader. 073 * @return the ClassLoader (only {@code null} if even the system 074 * ClassLoader isn't accessible) 075 * @see org.springframework.util.ClassUtils#getDefaultClassLoader() 076 */ 077 ClassLoader getClassLoader(); 078 079}