Skip to content

Commit

Permalink
clarified Resource's "getFilename" method to consistently return null…
Browse files Browse the repository at this point in the history
… if resource type does not have a filename (SPR-9043)
  • Loading branch information
jhoeller committed Feb 11, 2012
1 parent 1e1f8c9 commit 57851de
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 41 deletions.
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -150,11 +150,11 @@ public Resource createRelative(String relativePath) throws IOException {
}

/**
* 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;
}


Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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();

Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -23,7 +23,7 @@

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;
Expand Down Expand Up @@ -179,9 +179,7 @@ protected void loadProperties(Properties props) throws IOException {
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);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -485,38 +485,38 @@ protected JasperReport loadReport() {
*/
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);
}
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);
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();
}
}
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(
Expand Down

0 comments on commit 57851de

Please sign in to comment.