clarified Resource's "getFilename" method to consistently return null if resource type does not have a filename (SPR-9043)

This commit is contained in:
Juergen Hoeller
2012-02-09 17:58:35 +01:00
parent 1e1f8c912b
commit 57851de88e
4 changed files with 41 additions and 41 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2011 the original author or authors.
* Copyright 2002-2012 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.
@@ -150,11 +150,11 @@ public abstract class AbstractResource implements Resource {
}
/**
* This implementation always throws IllegalStateException,
* assuming that the resource does not have a filename.
* This implementation always returns <code>null</code>,
* assuming that this resource type does not have a filename.
*/
public String getFilename() throws IllegalStateException {
throw new IllegalStateException(getDescription() + " does not have a filename");
return null;
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2011 the original author or authors.
* Copyright 2002-2012 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.
@@ -116,8 +116,10 @@ public interface Resource extends InputStreamSource {
Resource createRelative(String relativePath) throws IOException;
/**
* Return a filename for this resource, i.e. typically the last
* Determine a filename for this resource, i.e. typically the last
* part of the path: for example, "myfile.txt".
* <p>Returns <code>null</code> if this type of resource does not
* have a filename.
*/
String getFilename();

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2008 the original author or authors.
* Copyright 2002-2012 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.
@@ -23,7 +23,7 @@ import java.util.Properties;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.core.io.AbstractFileResolvingResource;
import org.springframework.core.io.Resource;
import org.springframework.util.CollectionUtils;
import org.springframework.util.DefaultPropertiesPersister;
@@ -179,9 +179,7 @@ public abstract class PropertiesLoaderSupport {
InputStream is = null;
try {
is = location.getInputStream();
String filename = (location instanceof AbstractFileResolvingResource) ?
location.getFilename() : null;
String filename = location.getFilename();
if (filename != null && filename.endsWith(XML_FILE_EXTENSION)) {
this.propertiesPersister.loadFromXml(props, is);
}