Improved fix for detecting non-file based Resources in PropertiesLoaderSupport (SPR-7547, SPR-7552)

Use instanceof check against AbstractFileResolvingResource instead of
try/catch around resource.getFilename() call.
This commit is contained in:
Chris Beams
2010-12-15 17:09:31 +00:00
parent c08a2764d0
commit 1a7aebb0dd

View File

@@ -23,6 +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,15 +180,11 @@ public abstract class PropertiesLoaderSupport {
try {
is = location.getInputStream();
String filename = null;
try {
filename = location.getFilename();
} catch (IllegalStateException ex) {
// resource is not file-based. See SPR-7552.
}
if (filename != null && filename.endsWith(XML_FILE_EXTENSION)) {
this.propertiesPersister.loadFromXml(props, is);
if (location instanceof AbstractFileResolvingResource) {
String filename = location.getFilename();
if (filename != null && filename.endsWith(XML_FILE_EXTENSION)) {
this.propertiesPersister.loadFromXml(props, is);
}
}
else {
if (this.fileEncoding != null) {