diff --git a/org.springframework.core/src/main/java/org/springframework/core/io/AbstractResource.java b/org.springframework.core/src/main/java/org/springframework/core/io/AbstractResource.java index a6b06ab7bb..2f6c8e7d7d 100644 --- a/org.springframework.core/src/main/java/org/springframework/core/io/AbstractResource.java +++ b/org.springframework.core/src/main/java/org/springframework/core/io/AbstractResource.java @@ -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 null, + * 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; } diff --git a/org.springframework.core/src/main/java/org/springframework/core/io/Resource.java b/org.springframework.core/src/main/java/org/springframework/core/io/Resource.java index aafb1a9dab..f90b13c7ed 100644 --- a/org.springframework.core/src/main/java/org/springframework/core/io/Resource.java +++ b/org.springframework.core/src/main/java/org/springframework/core/io/Resource.java @@ -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". + *

Returns null if this type of resource does not + * have a filename. */ String getFilename(); diff --git a/org.springframework.core/src/main/java/org/springframework/core/io/support/PropertiesLoaderSupport.java b/org.springframework.core/src/main/java/org/springframework/core/io/support/PropertiesLoaderSupport.java index e4b4147a40..1b427611c4 100644 --- a/org.springframework.core/src/main/java/org/springframework/core/io/support/PropertiesLoaderSupport.java +++ b/org.springframework.core/src/main/java/org/springframework/core/io/support/PropertiesLoaderSupport.java @@ -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); } diff --git a/org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/view/jasperreports/AbstractJasperReportsView.java b/org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/view/jasperreports/AbstractJasperReportsView.java index 28b73bb5a2..865b9f3855 100644 --- a/org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/view/jasperreports/AbstractJasperReportsView.java +++ b/org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/view/jasperreports/AbstractJasperReportsView.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2010 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. @@ -485,38 +485,38 @@ public abstract class AbstractJasperReportsView extends AbstractUrlBasedView { */ protected final JasperReport loadReport(Resource resource) { try { - String fileName = resource.getFilename(); - if (fileName.endsWith(".jasper")) { - // Load pre-compiled report. - if (logger.isInfoEnabled()) { - logger.info("Loading pre-compiled Jasper Report from " + resource); + String filename = resource.getFilename(); + if (filename != null) { + if (filename.endsWith(".jasper")) { + // Load pre-compiled report. + if (logger.isInfoEnabled()) { + logger.info("Loading pre-compiled Jasper Report from " + resource); + } + InputStream is = resource.getInputStream(); + try { + return (JasperReport) JRLoader.loadObject(is); + } + finally { + is.close(); + } } - InputStream is = resource.getInputStream(); - try { - return (JasperReport) JRLoader.loadObject(is); - } - finally { - is.close(); + else if (filename.endsWith(".jrxml")) { + // Compile report on-the-fly. + if (logger.isInfoEnabled()) { + logger.info("Compiling Jasper Report loaded from " + resource); + } + InputStream is = resource.getInputStream(); + try { + JasperDesign design = JRXmlLoader.load(is); + return JasperCompileManager.compileReport(design); + } + finally { + is.close(); + } } } - else if (fileName.endsWith(".jrxml")) { - // Compile report on-the-fly. - if (logger.isInfoEnabled()) { - logger.info("Compiling Jasper Report loaded from " + resource); - } - InputStream is = resource.getInputStream(); - try { - JasperDesign design = JRXmlLoader.load(is); - return JasperCompileManager.compileReport(design); - } - finally { - is.close(); - } - } - else { - throw new IllegalArgumentException( - "Report filename [" + fileName + "] must end in either .jasper or .jrxml"); - } + throw new IllegalArgumentException( + "Report filename [" + filename + "] must end in either .jasper or .jrxml"); } catch (IOException ex) { throw new ApplicationContextException(