
leap.lang.resource.FileResourceLoader Maven / Gradle / Ivy
/*
* Copyright 2002-2007 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package leap.lang.resource;
/**
* {@link ResourceLoader} implementation that resolves plain paths as file system resources rather than as class path
* resources (the latter is {@link DefaultResourceLoader}'s default strategy).
*
*
* NOTE: Plain paths will always be interpreted as relative to the current VM working directory, even if they
* start with a slash. (This is consistent with the semantics in a Servlet container.) Use an explicit "file:" prefix
* to enforce an absolute file path.
*
* @author Juergen Hoeller
* @since 1.1.3
* @see DefaultResourceLoader
*/
class FileResourceLoader extends DefaultResourceLoader {
@Override
protected Resource getResourceByPath(String path) {
if (path != null && path.startsWith("/")) {
path = path.substring(1);
}
return new FileSystemContextResource(path);
}
private static class FileSystemContextResource extends SimpleFileResource implements ContextResource {
public FileSystemContextResource(String path) {
super(path);
}
public String getPathWithinContext() {
return getPath();
}
}
}